1 //==-- llvm/CodeGen/TargetLoweringObjectFileImpl.h - Object Info -*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements classes used to handle lowerings specific to common
11 // object file formats.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
16 #define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/MC/SectionKind.h"
20 #include "llvm/Target/TargetLoweringObjectFile.h"
23 class MachineModuleInfo;
35 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
36 mutable void *UniquingMap;
38 /// TLSDataSection - Section directive for Thread Local data.
40 const MCSection *TLSDataSection; // Defaults to ".tdata".
42 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
43 /// Null if this target doesn't support a BSS section.
45 const MCSection *TLSBSSSection; // Defaults to ".tbss".
47 const MCSection *DataRelSection;
48 const MCSection *DataRelLocalSection;
49 const MCSection *DataRelROSection;
50 const MCSection *DataRelROLocalSection;
52 const MCSection *MergeableConst4Section;
53 const MCSection *MergeableConst8Section;
54 const MCSection *MergeableConst16Section;
57 const MCSection *getELFSection(StringRef Section, unsigned Type,
58 unsigned Flags, SectionKind Kind,
59 bool IsExplicit = false) const;
61 TargetLoweringObjectFileELF() : UniquingMap(0) {}
62 ~TargetLoweringObjectFileELF();
64 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
66 const MCSection *getDataRelSection() const { return DataRelSection; }
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;
73 virtual const MCSection *
74 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
75 Mangler *Mang, const TargetMachine &TM) const;
77 virtual const MCSection *
78 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
79 Mangler *Mang, const TargetMachine &TM) const;
81 /// getExprForDwarfGlobalReference - Return an MCExpr to use for a reference
82 /// to the specified global variable from exception handling information.
84 virtual const MCExpr *
85 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
86 MachineModuleInfo *MMI, unsigned Encoding,
87 MCStreamer &Streamer) const;
92 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
93 mutable void *UniquingMap;
95 const MCSection *CStringSection;
96 const MCSection *UStringSection;
97 const MCSection *TextCoalSection;
98 const MCSection *ConstTextCoalSection;
99 const MCSection *ConstDataCoalSection;
100 const MCSection *ConstDataSection;
101 const MCSection *DataCoalSection;
102 const MCSection *DataCommonSection;
103 const MCSection *DataBSSSection;
104 const MCSection *FourByteConstantSection;
105 const MCSection *EightByteConstantSection;
106 const MCSection *SixteenByteConstantSection;
108 const MCSection *LazySymbolPointerSection;
109 const MCSection *NonLazySymbolPointerSection;
111 TargetLoweringObjectFileMachO() : UniquingMap(0) {}
112 ~TargetLoweringObjectFileMachO();
114 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
116 virtual const MCSection *
117 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
118 Mangler *Mang, const TargetMachine &TM) const;
120 virtual const MCSection *
121 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
122 Mangler *Mang, const TargetMachine &TM) const;
124 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
126 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
127 /// decide not to emit the UsedDirective for some symbols in llvm.used.
128 /// FIXME: REMOVE this (rdar://7071300)
129 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
132 /// getMachOSection - Return the MCSection for the specified mach-o section.
133 /// This requires the operands to be valid.
134 const MCSectionMachO *getMachOSection(StringRef Segment,
136 unsigned TypeAndAttributes,
137 SectionKind K) const {
138 return getMachOSection(Segment, Section, TypeAndAttributes, 0, K);
140 const MCSectionMachO *getMachOSection(StringRef Segment,
142 unsigned TypeAndAttributes,
144 SectionKind K) const;
146 /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
147 /// text symbols into.
148 const MCSection *getTextCoalSection() const {
149 return TextCoalSection;
152 /// getConstTextCoalSection - Return the "__TEXT,__const_coal" section
153 /// we put weak read-only symbols into.
154 const MCSection *getConstTextCoalSection() const {
155 return ConstTextCoalSection;
158 /// getLazySymbolPointerSection - Return the section corresponding to
159 /// the .lazy_symbol_pointer directive.
160 const MCSection *getLazySymbolPointerSection() const {
161 return LazySymbolPointerSection;
164 /// getNonLazySymbolPointerSection - Return the section corresponding to
165 /// the .non_lazy_symbol_pointer directive.
166 const MCSection *getNonLazySymbolPointerSection() const {
167 return NonLazySymbolPointerSection;
170 /// getExprForDwarfGlobalReference - The mach-o version of this method
171 /// defaults to returning a stub reference.
172 virtual const MCExpr *
173 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
174 MachineModuleInfo *MMI, unsigned Encoding,
175 MCStreamer &Streamer) const;
177 virtual unsigned getPersonalityEncoding() const;
178 virtual unsigned getLSDAEncoding() const;
179 virtual unsigned getFDEEncoding() const;
180 virtual unsigned getTTypeEncoding() const;
185 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
186 mutable void *UniquingMap;
188 TargetLoweringObjectFileCOFF() : UniquingMap(0) {}
189 ~TargetLoweringObjectFileCOFF();
191 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
193 virtual const MCSection *
194 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
195 Mangler *Mang, const TargetMachine &TM) const;
197 virtual const MCSection *
198 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
199 Mangler *Mang, const TargetMachine &TM) const;
201 /// getCOFFSection - Return the MCSection for the specified COFF section.
202 /// FIXME: Switch this to a semantic view eventually.
203 const MCSection *getCOFFSection(StringRef Name, bool isDirective,
204 SectionKind K) const;
207 } // end namespace llvm