TargetLoweringObjectFileImpl.h revision 362dd0bef5437f85586c046bc53287b6fbe9c099
1//==-- llvm/CodeGen/TargetLoweringObjectFileImpl.h - Object Info -*- C++ -*-==//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements classes used to handle lowerings specific to common
11// object file formats.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
16#define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
17
18#include "llvm/ADT/StringRef.h"
19#include "llvm/MC/SectionKind.h"
20#include "llvm/Target/TargetLoweringObjectFile.h"
21
22namespace llvm {
23  class MachineModuleInfo;
24  class Mangler;
25  class MCAsmInfo;
26  class MCExpr;
27  class MCSection;
28  class MCSectionMachO;
29  class MCSymbol;
30  class MCContext;
31  class GlobalValue;
32  class TargetMachine;
33
34
35class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
36  mutable void *UniquingMap;
37protected:
38  /// TLSDataSection - Section directive for Thread Local data.
39  ///
40  const MCSection *TLSDataSection;        // Defaults to ".tdata".
41
42  /// TLSBSSSection - Section directive for Thread Local uninitialized data.
43  /// Null if this target doesn't support a BSS section.
44  ///
45  const MCSection *TLSBSSSection;         // Defaults to ".tbss".
46
47  const MCSection *DataRelSection;
48  const MCSection *DataRelLocalSection;
49  const MCSection *DataRelROSection;
50  const MCSection *DataRelROLocalSection;
51
52  const MCSection *MergeableConst4Section;
53  const MCSection *MergeableConst8Section;
54  const MCSection *MergeableConst16Section;
55
56protected:
57  const MCSection *getELFSection(StringRef Section, unsigned Type,
58                                 unsigned Flags, SectionKind Kind,
59                                 bool IsExplicit = false) const;
60public:
61  TargetLoweringObjectFileELF() : UniquingMap(0) {}
62  ~TargetLoweringObjectFileELF();
63
64  virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
65
66  const MCSection *getDataRelSection() const { return DataRelSection; }
67
68  /// getSectionForConstant - Given a constant with the SectionKind, return a
69  /// section that it should be placed in.
70  virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
71
72
73  virtual const MCSection *
74  getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
75                           Mangler *Mang, const TargetMachine &TM) const;
76
77  virtual const MCSection *
78  SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
79                         Mangler *Mang, const TargetMachine &TM) const;
80
81  /// getSymbolForDwarfGlobalReference - Return an MCExpr to use for a reference
82  /// to the specified global variable from exception handling information.
83  ///
84  virtual const MCExpr *
85  getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
86                              MachineModuleInfo *MMI, unsigned Encoding) const;
87};
88
89
90
91class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
92  mutable void *UniquingMap;
93
94  const MCSection *CStringSection;
95  const MCSection *UStringSection;
96  const MCSection *TextCoalSection;
97  const MCSection *ConstTextCoalSection;
98  const MCSection *ConstDataCoalSection;
99  const MCSection *ConstDataSection;
100  const MCSection *DataCoalSection;
101  const MCSection *DataCommonSection;
102  const MCSection *DataBSSSection;
103  const MCSection *FourByteConstantSection;
104  const MCSection *EightByteConstantSection;
105  const MCSection *SixteenByteConstantSection;
106
107  const MCSection *LazySymbolPointerSection;
108  const MCSection *NonLazySymbolPointerSection;
109public:
110  TargetLoweringObjectFileMachO() : UniquingMap(0) {}
111  ~TargetLoweringObjectFileMachO();
112
113  virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
114
115  virtual const MCSection *
116  SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
117                         Mangler *Mang, const TargetMachine &TM) const;
118
119  virtual const MCSection *
120  getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
121                           Mangler *Mang, const TargetMachine &TM) const;
122
123  virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
124
125  /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
126  /// decide not to emit the UsedDirective for some symbols in llvm.used.
127  /// FIXME: REMOVE this (rdar://7071300)
128  virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
129                                          Mangler *) const;
130
131  /// getMachOSection - Return the MCSection for the specified mach-o section.
132  /// This requires the operands to be valid.
133  const MCSectionMachO *getMachOSection(StringRef Segment,
134                                        StringRef Section,
135                                        unsigned TypeAndAttributes,
136                                        SectionKind K) const {
137    return getMachOSection(Segment, Section, TypeAndAttributes, 0, K);
138  }
139  const MCSectionMachO *getMachOSection(StringRef Segment,
140                                        StringRef Section,
141                                        unsigned TypeAndAttributes,
142                                        unsigned Reserved2,
143                                        SectionKind K) const;
144
145  /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
146  /// text symbols into.
147  const MCSection *getTextCoalSection() const {
148    return TextCoalSection;
149  }
150
151  /// getConstTextCoalSection - Return the "__TEXT,__const_coal" section
152  /// we put weak read-only symbols into.
153  const MCSection *getConstTextCoalSection() const {
154    return ConstTextCoalSection;
155  }
156
157  /// getLazySymbolPointerSection - Return the section corresponding to
158  /// the .lazy_symbol_pointer directive.
159  const MCSection *getLazySymbolPointerSection() const {
160    return LazySymbolPointerSection;
161  }
162
163  /// getNonLazySymbolPointerSection - Return the section corresponding to
164  /// the .non_lazy_symbol_pointer directive.
165  const MCSection *getNonLazySymbolPointerSection() const {
166    return NonLazySymbolPointerSection;
167  }
168
169  /// getSymbolForDwarfGlobalReference - The mach-o version of this method
170  /// defaults to returning a stub reference.
171  virtual const MCExpr *
172  getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
173                              MachineModuleInfo *MMI, unsigned Encoding) const;
174};
175
176
177
178class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
179  mutable void *UniquingMap;
180public:
181  TargetLoweringObjectFileCOFF() : UniquingMap(0) {}
182  ~TargetLoweringObjectFileCOFF();
183
184  virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
185
186  virtual const MCSection *
187  getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
188                           Mangler *Mang, const TargetMachine &TM) const;
189
190  virtual const MCSection *
191  SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
192                         Mangler *Mang, const TargetMachine &TM) const;
193
194  /// getCOFFSection - Return the MCSection for the specified COFF section.
195  /// FIXME: Switch this to a semantic view eventually.
196  const MCSection *getCOFFSection(StringRef Name, bool isDirective,
197                                  SectionKind K) const;
198};
199
200} // end namespace llvm
201
202#endif
203