1 //===-- llvm/Target/TargetLoweringObjectFile.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_TARGET_TARGETLOWERINGOBJECTFILE_H
16 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/MC/MCObjectFileInfo.h"
21 #include "llvm/MC/SectionKind.h"
24 class MachineModuleInfo;
30 class MCSymbolRefExpr;
36 class TargetLoweringObjectFile : public MCObjectFileInfo {
40 TargetLoweringObjectFile(
41 const TargetLoweringObjectFile&) = delete;
42 void operator=(const TargetLoweringObjectFile&) = delete;
45 bool SupportIndirectSymViaGOTPCRel;
46 bool SupportGOTPCRelWithOffset;
49 MCContext &getContext() const { return *Ctx; }
51 TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(nullptr), DL(nullptr),
52 SupportIndirectSymViaGOTPCRel(false),
53 SupportGOTPCRelWithOffset(true) {}
55 virtual ~TargetLoweringObjectFile();
57 /// This method must be called before any actual lowering is done. This
58 /// specifies the current context for codegen, and gives the lowering
59 /// implementations a chance to set up their default sections.
60 virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
62 virtual void emitPersonalityValue(MCStreamer &Streamer,
63 const TargetMachine &TM,
64 const MCSymbol *Sym) const;
66 /// Extract the dependent library name from a linker option string. Returns
67 /// StringRef() if the option does not specify a library.
68 virtual StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const {
72 /// Emit the module flags that the platform cares about.
73 virtual void emitModuleFlags(MCStreamer &Streamer,
74 ArrayRef<Module::ModuleFlagEntry> Flags,
75 Mangler &Mang, const TargetMachine &TM) const {}
77 /// Given a constant with the SectionKind, return a section that it should be
79 virtual const MCSection *getSectionForConstant(SectionKind Kind,
80 const Constant *C) const;
82 /// Classify the specified global variable into a set of target independent
83 /// categories embodied in SectionKind.
84 static SectionKind getKindForGlobal(const GlobalValue *GV,
85 const TargetMachine &TM);
87 /// This method computes the appropriate section to emit the specified global
88 /// variable or function definition. This should not be passed external (or
89 /// available externally) globals.
90 const MCSection *SectionForGlobal(const GlobalValue *GV,
91 SectionKind Kind, Mangler &Mang,
92 const TargetMachine &TM) const;
94 /// This method computes the appropriate section to emit the specified global
95 /// variable or function definition. This should not be passed external (or
96 /// available externally) globals.
97 const MCSection *SectionForGlobal(const GlobalValue *GV,
99 const TargetMachine &TM) const {
100 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
103 virtual const MCSection *
104 getSectionForJumpTable(const Function &F, Mangler &Mang,
105 const TargetMachine &TM) const;
107 virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
108 const Function &F) const;
110 /// Targets should implement this method to assign a section to globals with
111 /// an explicit section specfied. The implementation of this method can
112 /// assume that GV->hasSection() is true.
113 virtual const MCSection *
114 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
115 Mangler &Mang, const TargetMachine &TM) const = 0;
117 /// Allow the target to completely override section assignment of a global.
118 virtual const MCSection *getSpecialCasedSectionGlobals(const GlobalValue *GV,
120 Mangler &Mang) const {
124 /// Return an MCExpr to use for a reference to the specified global variable
125 /// from exception handling information.
126 virtual const MCExpr *
127 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
128 Mangler &Mang, const TargetMachine &TM,
129 MachineModuleInfo *MMI, MCStreamer &Streamer) const;
131 /// Return the MCSymbol for a private symbol with global value name as its
132 /// base, with the specified suffix.
133 MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
134 StringRef Suffix, Mangler &Mang,
135 const TargetMachine &TM) const;
137 // The symbol that gets passed to .cfi_personality.
138 virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
140 const TargetMachine &TM,
141 MachineModuleInfo *MMI) const;
144 getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
145 MCStreamer &Streamer) const;
147 virtual const MCSection *getStaticCtorSection(unsigned Priority,
148 const MCSymbol *KeySym) const {
149 return StaticCtorSection;
152 virtual const MCSection *getStaticDtorSection(unsigned Priority,
153 const MCSymbol *KeySym) const {
154 return StaticDtorSection;
157 /// \brief Create a symbol reference to describe the given TLS variable when
158 /// emitting the address in debug info.
159 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
161 virtual const MCExpr *
162 getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler &Mang,
163 const TargetMachine &TM) const {
167 /// \brief Target supports replacing a data "PC"-relative access to a symbol
168 /// through another symbol, by accessing the later via a GOT entry instead?
169 bool supportIndirectSymViaGOTPCRel() const {
170 return SupportIndirectSymViaGOTPCRel;
173 /// \brief Target GOT "PC"-relative relocation supports encoding an additional
174 /// binary expression with an offset?
175 bool supportGOTPCRelWithOffset() const {
176 return SupportGOTPCRelWithOffset;
179 /// \brief Get the target specific PC relative GOT entry relocation
180 virtual const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
182 MCStreamer &Streamer) const {
187 virtual const MCSection *
188 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
189 Mangler &Mang, const TargetMachine &TM) const = 0;
192 } // end namespace llvm