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 const MCSection *CStringSection;
94 const MCSection *UStringSection;
95 const MCSection *TextCoalSection;
96 const MCSection *ConstTextCoalSection;
97 const MCSection *ConstDataCoalSection;
98 const MCSection *ConstDataSection;
99 const MCSection *DataCoalSection;
100 const MCSection *DataCommonSection;
101 const MCSection *DataBSSSection;
102 const MCSection *FourByteConstantSection;
103 const MCSection *EightByteConstantSection;
104 const MCSection *SixteenByteConstantSection;
106 const MCSection *LazySymbolPointerSection;
107 const MCSection *NonLazySymbolPointerSection;
109 TargetLoweringObjectFileMachO() {}
110 ~TargetLoweringObjectFileMachO() {}
112 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
114 virtual const MCSection *
115 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
116 Mangler *Mang, const TargetMachine &TM) const;
118 virtual const MCSection *
119 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
120 Mangler *Mang, const TargetMachine &TM) const;
122 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
124 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
125 /// decide not to emit the UsedDirective for some symbols in llvm.used.
126 /// FIXME: REMOVE this (rdar://7071300)
127 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
130 /// getMachOSection - Return the MCSection for the specified mach-o section.
131 /// This requires the operands to be valid.
132 const MCSectionMachO *getMachOSection(StringRef Segment,
134 unsigned TypeAndAttributes,
135 SectionKind K) const {
136 return getMachOSection(Segment, Section, TypeAndAttributes, 0, K);
138 const MCSectionMachO *getMachOSection(StringRef Segment,
140 unsigned TypeAndAttributes,
142 SectionKind K) const;
144 /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
145 /// text symbols into.
146 const MCSection *getTextCoalSection() const {
147 return TextCoalSection;
150 /// getConstTextCoalSection - Return the "__TEXT,__const_coal" section
151 /// we put weak read-only symbols into.
152 const MCSection *getConstTextCoalSection() const {
153 return ConstTextCoalSection;
156 /// getLazySymbolPointerSection - Return the section corresponding to
157 /// the .lazy_symbol_pointer directive.
158 const MCSection *getLazySymbolPointerSection() const {
159 return LazySymbolPointerSection;
162 /// getNonLazySymbolPointerSection - Return the section corresponding to
163 /// the .non_lazy_symbol_pointer directive.
164 const MCSection *getNonLazySymbolPointerSection() const {
165 return NonLazySymbolPointerSection;
168 /// getExprForDwarfGlobalReference - The mach-o version of this method
169 /// defaults to returning a stub reference.
170 virtual const MCExpr *
171 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
172 MachineModuleInfo *MMI, unsigned Encoding,
173 MCStreamer &Streamer) const;
175 virtual unsigned getPersonalityEncoding() const;
176 virtual unsigned getLSDAEncoding() const;
177 virtual unsigned getFDEEncoding() const;
178 virtual unsigned getTTypeEncoding() const;
183 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
184 mutable void *UniquingMap;
186 TargetLoweringObjectFileCOFF() : UniquingMap(0) {}
187 ~TargetLoweringObjectFileCOFF();
189 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
191 virtual const MCSection *
192 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
193 Mangler *Mang, const TargetMachine &TM) const;
195 virtual const MCSection *
196 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
197 Mangler *Mang, const TargetMachine &TM) const;
199 /// getCOFFSection - Return the MCSection for the specified COFF section.
200 /// FIXME: Switch this to a semantic view eventually.
201 const MCSection *getCOFFSection(StringRef Name, bool isDirective,
202 SectionKind K) const;
205 } // end namespace llvm