TargetLoweringObjectFileImpl.h revision 3192d14076dbe5724ce85b9d48644bb3c081f0e5
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  /// getExprForDwarfGlobalReference - Return an MCExpr to use for a reference
82  /// to the specified global variable from exception handling information.
83  ///
84  virtual const MCExpr *
85  getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
86                                 MachineModuleInfo *MMI, unsigned Encoding,
87                                 MCStreamer &Streamer) const;
88};
89
90
91
92class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
93  mutable void *UniquingMap;
94
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;
107
108  const MCSection *LazySymbolPointerSection;
109  const MCSection *NonLazySymbolPointerSection;
110public:
111  TargetLoweringObjectFileMachO() : UniquingMap(0) {}
112  ~TargetLoweringObjectFileMachO();
113
114  virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
115
116  virtual const MCSection *
117  SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
118                         Mangler *Mang, const TargetMachine &TM) const;
119
120  virtual const MCSection *
121  getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
122                           Mangler *Mang, const TargetMachine &TM) const;
123
124  virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
125
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,
130                                          Mangler *) const;
131
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,
135                                        StringRef Section,
136                                        unsigned TypeAndAttributes,
137                                        SectionKind K) const {
138    return getMachOSection(Segment, Section, TypeAndAttributes, 0, K);
139  }
140  const MCSectionMachO *getMachOSection(StringRef Segment,
141                                        StringRef Section,
142                                        unsigned TypeAndAttributes,
143                                        unsigned Reserved2,
144                                        SectionKind K) const;
145
146  /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
147  /// text symbols into.
148  const MCSection *getTextCoalSection() const {
149    return TextCoalSection;
150  }
151
152  /// getConstTextCoalSection - Return the "__TEXT,__const_coal" section
153  /// we put weak read-only symbols into.
154  const MCSection *getConstTextCoalSection() const {
155    return ConstTextCoalSection;
156  }
157
158  /// getLazySymbolPointerSection - Return the section corresponding to
159  /// the .lazy_symbol_pointer directive.
160  const MCSection *getLazySymbolPointerSection() const {
161    return LazySymbolPointerSection;
162  }
163
164  /// getNonLazySymbolPointerSection - Return the section corresponding to
165  /// the .non_lazy_symbol_pointer directive.
166  const MCSection *getNonLazySymbolPointerSection() const {
167    return NonLazySymbolPointerSection;
168  }
169
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;
176
177  virtual unsigned getPersonalityEncoding() const;
178  virtual unsigned getLSDAEncoding() const;
179  virtual unsigned getFDEEncoding() const;
180  virtual unsigned getTTypeEncoding() const;
181};
182
183
184
185class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
186  mutable void *UniquingMap;
187public:
188  TargetLoweringObjectFileCOFF() : UniquingMap(0) {}
189  ~TargetLoweringObjectFileCOFF();
190
191  virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
192
193  virtual const MCSection *
194  getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
195                           Mangler *Mang, const TargetMachine &TM) const;
196
197  virtual const MCSection *
198  SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
199                         Mangler *Mang, const TargetMachine &TM) const;
200
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;
205};
206
207} // end namespace llvm
208
209#endif
210