xref: /aosp_15_r20/external/llvm/lib/Target/TargetLoweringObjectFile.cpp (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===-- llvm/Target/TargetLoweringObjectFile.cpp - Object File Info -------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file implements classes used to handle lowerings specific to common
11*9880d681SAndroid Build Coastguard Worker // object file formats.
12*9880d681SAndroid Build Coastguard Worker //
13*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
14*9880d681SAndroid Build Coastguard Worker 
15*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/TargetLoweringObjectFile.h"
16*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Constants.h"
17*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/DataLayout.h"
18*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/DerivedTypes.h"
19*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Function.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/GlobalVariable.h"
21*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Mangler.h"
22*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCAsmInfo.h"
23*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCContext.h"
24*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCExpr.h"
25*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCStreamer.h"
26*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCSymbol.h"
27*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Dwarf.h"
28*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/ErrorHandling.h"
29*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/raw_ostream.h"
30*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/TargetLowering.h"
31*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/TargetMachine.h"
32*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/TargetOptions.h"
33*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/TargetSubtargetInfo.h"
34*9880d681SAndroid Build Coastguard Worker using namespace llvm;
35*9880d681SAndroid Build Coastguard Worker 
36*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
37*9880d681SAndroid Build Coastguard Worker //                              Generic Code
38*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
39*9880d681SAndroid Build Coastguard Worker 
40*9880d681SAndroid Build Coastguard Worker /// Initialize - this method must be called before any actual lowering is
41*9880d681SAndroid Build Coastguard Worker /// done.  This specifies the current context for codegen, and gives the
42*9880d681SAndroid Build Coastguard Worker /// lowering implementations a chance to set up their default sections.
Initialize(MCContext & ctx,const TargetMachine & TM)43*9880d681SAndroid Build Coastguard Worker void TargetLoweringObjectFile::Initialize(MCContext &ctx,
44*9880d681SAndroid Build Coastguard Worker                                           const TargetMachine &TM) {
45*9880d681SAndroid Build Coastguard Worker   Ctx = &ctx;
46*9880d681SAndroid Build Coastguard Worker   InitMCObjectFileInfo(TM.getTargetTriple(), TM.isPositionIndependent(),
47*9880d681SAndroid Build Coastguard Worker                        TM.getCodeModel(), *Ctx);
48*9880d681SAndroid Build Coastguard Worker }
49*9880d681SAndroid Build Coastguard Worker 
~TargetLoweringObjectFile()50*9880d681SAndroid Build Coastguard Worker TargetLoweringObjectFile::~TargetLoweringObjectFile() {
51*9880d681SAndroid Build Coastguard Worker }
52*9880d681SAndroid Build Coastguard Worker 
isSuitableForBSS(const GlobalVariable * GV,bool NoZerosInBSS)53*9880d681SAndroid Build Coastguard Worker static bool isSuitableForBSS(const GlobalVariable *GV, bool NoZerosInBSS) {
54*9880d681SAndroid Build Coastguard Worker   const Constant *C = GV->getInitializer();
55*9880d681SAndroid Build Coastguard Worker 
56*9880d681SAndroid Build Coastguard Worker   // Must have zero initializer.
57*9880d681SAndroid Build Coastguard Worker   if (!C->isNullValue())
58*9880d681SAndroid Build Coastguard Worker     return false;
59*9880d681SAndroid Build Coastguard Worker 
60*9880d681SAndroid Build Coastguard Worker   // Leave constant zeros in readonly constant sections, so they can be shared.
61*9880d681SAndroid Build Coastguard Worker   if (GV->isConstant())
62*9880d681SAndroid Build Coastguard Worker     return false;
63*9880d681SAndroid Build Coastguard Worker 
64*9880d681SAndroid Build Coastguard Worker   // If the global has an explicit section specified, don't put it in BSS.
65*9880d681SAndroid Build Coastguard Worker   if (GV->hasSection())
66*9880d681SAndroid Build Coastguard Worker     return false;
67*9880d681SAndroid Build Coastguard Worker 
68*9880d681SAndroid Build Coastguard Worker   // If -nozero-initialized-in-bss is specified, don't ever use BSS.
69*9880d681SAndroid Build Coastguard Worker   if (NoZerosInBSS)
70*9880d681SAndroid Build Coastguard Worker     return false;
71*9880d681SAndroid Build Coastguard Worker 
72*9880d681SAndroid Build Coastguard Worker   // Otherwise, put it in BSS!
73*9880d681SAndroid Build Coastguard Worker   return true;
74*9880d681SAndroid Build Coastguard Worker }
75*9880d681SAndroid Build Coastguard Worker 
76*9880d681SAndroid Build Coastguard Worker /// IsNullTerminatedString - Return true if the specified constant (which is
77*9880d681SAndroid Build Coastguard Worker /// known to have a type that is an array of 1/2/4 byte elements) ends with a
78*9880d681SAndroid Build Coastguard Worker /// nul value and contains no other nuls in it.  Note that this is more general
79*9880d681SAndroid Build Coastguard Worker /// than ConstantDataSequential::isString because we allow 2 & 4 byte strings.
IsNullTerminatedString(const Constant * C)80*9880d681SAndroid Build Coastguard Worker static bool IsNullTerminatedString(const Constant *C) {
81*9880d681SAndroid Build Coastguard Worker   // First check: is we have constant array terminated with zero
82*9880d681SAndroid Build Coastguard Worker   if (const ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(C)) {
83*9880d681SAndroid Build Coastguard Worker     unsigned NumElts = CDS->getNumElements();
84*9880d681SAndroid Build Coastguard Worker     assert(NumElts != 0 && "Can't have an empty CDS");
85*9880d681SAndroid Build Coastguard Worker 
86*9880d681SAndroid Build Coastguard Worker     if (CDS->getElementAsInteger(NumElts-1) != 0)
87*9880d681SAndroid Build Coastguard Worker       return false; // Not null terminated.
88*9880d681SAndroid Build Coastguard Worker 
89*9880d681SAndroid Build Coastguard Worker     // Verify that the null doesn't occur anywhere else in the string.
90*9880d681SAndroid Build Coastguard Worker     for (unsigned i = 0; i != NumElts-1; ++i)
91*9880d681SAndroid Build Coastguard Worker       if (CDS->getElementAsInteger(i) == 0)
92*9880d681SAndroid Build Coastguard Worker         return false;
93*9880d681SAndroid Build Coastguard Worker     return true;
94*9880d681SAndroid Build Coastguard Worker   }
95*9880d681SAndroid Build Coastguard Worker 
96*9880d681SAndroid Build Coastguard Worker   // Another possibility: [1 x i8] zeroinitializer
97*9880d681SAndroid Build Coastguard Worker   if (isa<ConstantAggregateZero>(C))
98*9880d681SAndroid Build Coastguard Worker     return cast<ArrayType>(C->getType())->getNumElements() == 1;
99*9880d681SAndroid Build Coastguard Worker 
100*9880d681SAndroid Build Coastguard Worker   return false;
101*9880d681SAndroid Build Coastguard Worker }
102*9880d681SAndroid Build Coastguard Worker 
getSymbolWithGlobalValueBase(const GlobalValue * GV,StringRef Suffix,Mangler & Mang,const TargetMachine & TM) const103*9880d681SAndroid Build Coastguard Worker MCSymbol *TargetLoweringObjectFile::getSymbolWithGlobalValueBase(
104*9880d681SAndroid Build Coastguard Worker     const GlobalValue *GV, StringRef Suffix, Mangler &Mang,
105*9880d681SAndroid Build Coastguard Worker     const TargetMachine &TM) const {
106*9880d681SAndroid Build Coastguard Worker   assert(!Suffix.empty());
107*9880d681SAndroid Build Coastguard Worker 
108*9880d681SAndroid Build Coastguard Worker   SmallString<60> NameStr;
109*9880d681SAndroid Build Coastguard Worker   NameStr += GV->getParent()->getDataLayout().getPrivateGlobalPrefix();
110*9880d681SAndroid Build Coastguard Worker   TM.getNameWithPrefix(NameStr, GV, Mang);
111*9880d681SAndroid Build Coastguard Worker   NameStr.append(Suffix.begin(), Suffix.end());
112*9880d681SAndroid Build Coastguard Worker   return Ctx->getOrCreateSymbol(NameStr);
113*9880d681SAndroid Build Coastguard Worker }
114*9880d681SAndroid Build Coastguard Worker 
getCFIPersonalitySymbol(const GlobalValue * GV,Mangler & Mang,const TargetMachine & TM,MachineModuleInfo * MMI) const115*9880d681SAndroid Build Coastguard Worker MCSymbol *TargetLoweringObjectFile::getCFIPersonalitySymbol(
116*9880d681SAndroid Build Coastguard Worker     const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
117*9880d681SAndroid Build Coastguard Worker     MachineModuleInfo *MMI) const {
118*9880d681SAndroid Build Coastguard Worker   return TM.getSymbol(GV, Mang);
119*9880d681SAndroid Build Coastguard Worker }
120*9880d681SAndroid Build Coastguard Worker 
emitPersonalityValue(MCStreamer & Streamer,const DataLayout &,const MCSymbol * Sym) const121*9880d681SAndroid Build Coastguard Worker void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
122*9880d681SAndroid Build Coastguard Worker                                                     const DataLayout &,
123*9880d681SAndroid Build Coastguard Worker                                                     const MCSymbol *Sym) const {
124*9880d681SAndroid Build Coastguard Worker }
125*9880d681SAndroid Build Coastguard Worker 
126*9880d681SAndroid Build Coastguard Worker 
127*9880d681SAndroid Build Coastguard Worker /// getKindForGlobal - This is a top-level target-independent classifier for
128*9880d681SAndroid Build Coastguard Worker /// a global variable.  Given an global variable and information from TM, it
129*9880d681SAndroid Build Coastguard Worker /// classifies the global in a variety of ways that make various target
130*9880d681SAndroid Build Coastguard Worker /// implementations simpler.  The target implementation is free to ignore this
131*9880d681SAndroid Build Coastguard Worker /// extra info of course.
getKindForGlobal(const GlobalValue * GV,const TargetMachine & TM)132*9880d681SAndroid Build Coastguard Worker SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalValue *GV,
133*9880d681SAndroid Build Coastguard Worker                                                        const TargetMachine &TM){
134*9880d681SAndroid Build Coastguard Worker   assert(!GV->isDeclaration() && !GV->hasAvailableExternallyLinkage() &&
135*9880d681SAndroid Build Coastguard Worker          "Can only be used for global definitions");
136*9880d681SAndroid Build Coastguard Worker 
137*9880d681SAndroid Build Coastguard Worker   Reloc::Model ReloModel = TM.getRelocationModel();
138*9880d681SAndroid Build Coastguard Worker 
139*9880d681SAndroid Build Coastguard Worker   // Early exit - functions should be always in text sections.
140*9880d681SAndroid Build Coastguard Worker   const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
141*9880d681SAndroid Build Coastguard Worker   if (!GVar)
142*9880d681SAndroid Build Coastguard Worker     return SectionKind::getText();
143*9880d681SAndroid Build Coastguard Worker 
144*9880d681SAndroid Build Coastguard Worker   // Handle thread-local data first.
145*9880d681SAndroid Build Coastguard Worker   if (GVar->isThreadLocal()) {
146*9880d681SAndroid Build Coastguard Worker     if (isSuitableForBSS(GVar, TM.Options.NoZerosInBSS))
147*9880d681SAndroid Build Coastguard Worker       return SectionKind::getThreadBSS();
148*9880d681SAndroid Build Coastguard Worker     return SectionKind::getThreadData();
149*9880d681SAndroid Build Coastguard Worker   }
150*9880d681SAndroid Build Coastguard Worker 
151*9880d681SAndroid Build Coastguard Worker   // Variables with common linkage always get classified as common.
152*9880d681SAndroid Build Coastguard Worker   if (GVar->hasCommonLinkage())
153*9880d681SAndroid Build Coastguard Worker     return SectionKind::getCommon();
154*9880d681SAndroid Build Coastguard Worker 
155*9880d681SAndroid Build Coastguard Worker   // Variable can be easily put to BSS section.
156*9880d681SAndroid Build Coastguard Worker   if (isSuitableForBSS(GVar, TM.Options.NoZerosInBSS)) {
157*9880d681SAndroid Build Coastguard Worker     if (GVar->hasLocalLinkage())
158*9880d681SAndroid Build Coastguard Worker       return SectionKind::getBSSLocal();
159*9880d681SAndroid Build Coastguard Worker     else if (GVar->hasExternalLinkage())
160*9880d681SAndroid Build Coastguard Worker       return SectionKind::getBSSExtern();
161*9880d681SAndroid Build Coastguard Worker     return SectionKind::getBSS();
162*9880d681SAndroid Build Coastguard Worker   }
163*9880d681SAndroid Build Coastguard Worker 
164*9880d681SAndroid Build Coastguard Worker   const Constant *C = GVar->getInitializer();
165*9880d681SAndroid Build Coastguard Worker 
166*9880d681SAndroid Build Coastguard Worker   // If the global is marked constant, we can put it into a mergable section,
167*9880d681SAndroid Build Coastguard Worker   // a mergable string section, or general .data if it contains relocations.
168*9880d681SAndroid Build Coastguard Worker   if (GVar->isConstant()) {
169*9880d681SAndroid Build Coastguard Worker     // If the initializer for the global contains something that requires a
170*9880d681SAndroid Build Coastguard Worker     // relocation, then we may have to drop this into a writable data section
171*9880d681SAndroid Build Coastguard Worker     // even though it is marked const.
172*9880d681SAndroid Build Coastguard Worker     if (!C->needsRelocation()) {
173*9880d681SAndroid Build Coastguard Worker       // If the global is required to have a unique address, it can't be put
174*9880d681SAndroid Build Coastguard Worker       // into a mergable section: just drop it into the general read-only
175*9880d681SAndroid Build Coastguard Worker       // section instead.
176*9880d681SAndroid Build Coastguard Worker       if (!GVar->hasGlobalUnnamedAddr())
177*9880d681SAndroid Build Coastguard Worker         return SectionKind::getReadOnly();
178*9880d681SAndroid Build Coastguard Worker 
179*9880d681SAndroid Build Coastguard Worker       // If initializer is a null-terminated string, put it in a "cstring"
180*9880d681SAndroid Build Coastguard Worker       // section of the right width.
181*9880d681SAndroid Build Coastguard Worker       if (ArrayType *ATy = dyn_cast<ArrayType>(C->getType())) {
182*9880d681SAndroid Build Coastguard Worker         if (IntegerType *ITy =
183*9880d681SAndroid Build Coastguard Worker               dyn_cast<IntegerType>(ATy->getElementType())) {
184*9880d681SAndroid Build Coastguard Worker           if ((ITy->getBitWidth() == 8 || ITy->getBitWidth() == 16 ||
185*9880d681SAndroid Build Coastguard Worker                ITy->getBitWidth() == 32) &&
186*9880d681SAndroid Build Coastguard Worker               IsNullTerminatedString(C)) {
187*9880d681SAndroid Build Coastguard Worker             if (ITy->getBitWidth() == 8)
188*9880d681SAndroid Build Coastguard Worker               return SectionKind::getMergeable1ByteCString();
189*9880d681SAndroid Build Coastguard Worker             if (ITy->getBitWidth() == 16)
190*9880d681SAndroid Build Coastguard Worker               return SectionKind::getMergeable2ByteCString();
191*9880d681SAndroid Build Coastguard Worker 
192*9880d681SAndroid Build Coastguard Worker             assert(ITy->getBitWidth() == 32 && "Unknown width");
193*9880d681SAndroid Build Coastguard Worker             return SectionKind::getMergeable4ByteCString();
194*9880d681SAndroid Build Coastguard Worker           }
195*9880d681SAndroid Build Coastguard Worker         }
196*9880d681SAndroid Build Coastguard Worker       }
197*9880d681SAndroid Build Coastguard Worker 
198*9880d681SAndroid Build Coastguard Worker       // Otherwise, just drop it into a mergable constant section.  If we have
199*9880d681SAndroid Build Coastguard Worker       // a section for this size, use it, otherwise use the arbitrary sized
200*9880d681SAndroid Build Coastguard Worker       // mergable section.
201*9880d681SAndroid Build Coastguard Worker       switch (GV->getParent()->getDataLayout().getTypeAllocSize(C->getType())) {
202*9880d681SAndroid Build Coastguard Worker       case 4:  return SectionKind::getMergeableConst4();
203*9880d681SAndroid Build Coastguard Worker       case 8:  return SectionKind::getMergeableConst8();
204*9880d681SAndroid Build Coastguard Worker       case 16: return SectionKind::getMergeableConst16();
205*9880d681SAndroid Build Coastguard Worker       case 32: return SectionKind::getMergeableConst32();
206*9880d681SAndroid Build Coastguard Worker       default:
207*9880d681SAndroid Build Coastguard Worker         return SectionKind::getReadOnly();
208*9880d681SAndroid Build Coastguard Worker       }
209*9880d681SAndroid Build Coastguard Worker 
210*9880d681SAndroid Build Coastguard Worker     } else {
211*9880d681SAndroid Build Coastguard Worker       // In static relocation model, the linker will resolve all addresses, so
212*9880d681SAndroid Build Coastguard Worker       // the relocation entries will actually be constants by the time the app
213*9880d681SAndroid Build Coastguard Worker       // starts up.  However, we can't put this into a mergable section, because
214*9880d681SAndroid Build Coastguard Worker       // the linker doesn't take relocations into consideration when it tries to
215*9880d681SAndroid Build Coastguard Worker       // merge entries in the section.
216*9880d681SAndroid Build Coastguard Worker       if (ReloModel == Reloc::Static)
217*9880d681SAndroid Build Coastguard Worker         return SectionKind::getReadOnly();
218*9880d681SAndroid Build Coastguard Worker 
219*9880d681SAndroid Build Coastguard Worker       // Otherwise, the dynamic linker needs to fix it up, put it in the
220*9880d681SAndroid Build Coastguard Worker       // writable data.rel section.
221*9880d681SAndroid Build Coastguard Worker       return SectionKind::getReadOnlyWithRel();
222*9880d681SAndroid Build Coastguard Worker     }
223*9880d681SAndroid Build Coastguard Worker   }
224*9880d681SAndroid Build Coastguard Worker 
225*9880d681SAndroid Build Coastguard Worker   // Okay, this isn't a constant.
226*9880d681SAndroid Build Coastguard Worker   return SectionKind::getData();
227*9880d681SAndroid Build Coastguard Worker }
228*9880d681SAndroid Build Coastguard Worker 
229*9880d681SAndroid Build Coastguard Worker /// This method computes the appropriate section to emit the specified global
230*9880d681SAndroid Build Coastguard Worker /// variable or function definition.  This should not be passed external (or
231*9880d681SAndroid Build Coastguard Worker /// available externally) globals.
232*9880d681SAndroid Build Coastguard Worker MCSection *
SectionForGlobal(const GlobalValue * GV,SectionKind Kind,Mangler & Mang,const TargetMachine & TM) const233*9880d681SAndroid Build Coastguard Worker TargetLoweringObjectFile::SectionForGlobal(const GlobalValue *GV,
234*9880d681SAndroid Build Coastguard Worker                                            SectionKind Kind, Mangler &Mang,
235*9880d681SAndroid Build Coastguard Worker                                            const TargetMachine &TM) const {
236*9880d681SAndroid Build Coastguard Worker   // Select section name.
237*9880d681SAndroid Build Coastguard Worker   if (GV->hasSection())
238*9880d681SAndroid Build Coastguard Worker     return getExplicitSectionGlobal(GV, Kind, Mang, TM);
239*9880d681SAndroid Build Coastguard Worker 
240*9880d681SAndroid Build Coastguard Worker 
241*9880d681SAndroid Build Coastguard Worker   // Use default section depending on the 'type' of global
242*9880d681SAndroid Build Coastguard Worker   return SelectSectionForGlobal(GV, Kind, Mang, TM);
243*9880d681SAndroid Build Coastguard Worker }
244*9880d681SAndroid Build Coastguard Worker 
getSectionForJumpTable(const Function & F,Mangler & Mang,const TargetMachine & TM) const245*9880d681SAndroid Build Coastguard Worker MCSection *TargetLoweringObjectFile::getSectionForJumpTable(
246*9880d681SAndroid Build Coastguard Worker     const Function &F, Mangler &Mang, const TargetMachine &TM) const {
247*9880d681SAndroid Build Coastguard Worker   unsigned Align = 0;
248*9880d681SAndroid Build Coastguard Worker   return getSectionForConstant(F.getParent()->getDataLayout(),
249*9880d681SAndroid Build Coastguard Worker                                SectionKind::getReadOnly(), /*C=*/nullptr,
250*9880d681SAndroid Build Coastguard Worker                                Align);
251*9880d681SAndroid Build Coastguard Worker }
252*9880d681SAndroid Build Coastguard Worker 
shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,const Function & F) const253*9880d681SAndroid Build Coastguard Worker bool TargetLoweringObjectFile::shouldPutJumpTableInFunctionSection(
254*9880d681SAndroid Build Coastguard Worker     bool UsesLabelDifference, const Function &F) const {
255*9880d681SAndroid Build Coastguard Worker   // In PIC mode, we need to emit the jump table to the same section as the
256*9880d681SAndroid Build Coastguard Worker   // function body itself, otherwise the label differences won't make sense.
257*9880d681SAndroid Build Coastguard Worker   // FIXME: Need a better predicate for this: what about custom entries?
258*9880d681SAndroid Build Coastguard Worker   if (UsesLabelDifference)
259*9880d681SAndroid Build Coastguard Worker     return true;
260*9880d681SAndroid Build Coastguard Worker 
261*9880d681SAndroid Build Coastguard Worker   // We should also do if the section name is NULL or function is declared
262*9880d681SAndroid Build Coastguard Worker   // in discardable section
263*9880d681SAndroid Build Coastguard Worker   // FIXME: this isn't the right predicate, should be based on the MCSection
264*9880d681SAndroid Build Coastguard Worker   // for the function.
265*9880d681SAndroid Build Coastguard Worker   if (F.isWeakForLinker())
266*9880d681SAndroid Build Coastguard Worker     return true;
267*9880d681SAndroid Build Coastguard Worker 
268*9880d681SAndroid Build Coastguard Worker   return false;
269*9880d681SAndroid Build Coastguard Worker }
270*9880d681SAndroid Build Coastguard Worker 
271*9880d681SAndroid Build Coastguard Worker /// Given a mergable constant with the specified size and relocation
272*9880d681SAndroid Build Coastguard Worker /// information, return a section that it should be placed in.
getSectionForConstant(const DataLayout & DL,SectionKind Kind,const Constant * C,unsigned & Align) const273*9880d681SAndroid Build Coastguard Worker MCSection *TargetLoweringObjectFile::getSectionForConstant(
274*9880d681SAndroid Build Coastguard Worker     const DataLayout &DL, SectionKind Kind, const Constant *C,
275*9880d681SAndroid Build Coastguard Worker     unsigned &Align) const {
276*9880d681SAndroid Build Coastguard Worker   if (Kind.isReadOnly() && ReadOnlySection != nullptr)
277*9880d681SAndroid Build Coastguard Worker     return ReadOnlySection;
278*9880d681SAndroid Build Coastguard Worker 
279*9880d681SAndroid Build Coastguard Worker   return DataSection;
280*9880d681SAndroid Build Coastguard Worker }
281*9880d681SAndroid Build Coastguard Worker 
282*9880d681SAndroid Build Coastguard Worker /// getTTypeGlobalReference - Return an MCExpr to use for a
283*9880d681SAndroid Build Coastguard Worker /// reference to the specified global variable from exception
284*9880d681SAndroid Build Coastguard Worker /// handling information.
getTTypeGlobalReference(const GlobalValue * GV,unsigned Encoding,Mangler & Mang,const TargetMachine & TM,MachineModuleInfo * MMI,MCStreamer & Streamer) const285*9880d681SAndroid Build Coastguard Worker const MCExpr *TargetLoweringObjectFile::getTTypeGlobalReference(
286*9880d681SAndroid Build Coastguard Worker     const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
287*9880d681SAndroid Build Coastguard Worker     const TargetMachine &TM, MachineModuleInfo *MMI,
288*9880d681SAndroid Build Coastguard Worker     MCStreamer &Streamer) const {
289*9880d681SAndroid Build Coastguard Worker   const MCSymbolRefExpr *Ref =
290*9880d681SAndroid Build Coastguard Worker       MCSymbolRefExpr::create(TM.getSymbol(GV, Mang), getContext());
291*9880d681SAndroid Build Coastguard Worker 
292*9880d681SAndroid Build Coastguard Worker   return getTTypeReference(Ref, Encoding, Streamer);
293*9880d681SAndroid Build Coastguard Worker }
294*9880d681SAndroid Build Coastguard Worker 
295*9880d681SAndroid Build Coastguard Worker const MCExpr *TargetLoweringObjectFile::
getTTypeReference(const MCSymbolRefExpr * Sym,unsigned Encoding,MCStreamer & Streamer) const296*9880d681SAndroid Build Coastguard Worker getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
297*9880d681SAndroid Build Coastguard Worker                   MCStreamer &Streamer) const {
298*9880d681SAndroid Build Coastguard Worker   switch (Encoding & 0x70) {
299*9880d681SAndroid Build Coastguard Worker   default:
300*9880d681SAndroid Build Coastguard Worker     report_fatal_error("We do not support this DWARF encoding yet!");
301*9880d681SAndroid Build Coastguard Worker   case dwarf::DW_EH_PE_absptr:
302*9880d681SAndroid Build Coastguard Worker     // Do nothing special
303*9880d681SAndroid Build Coastguard Worker     return Sym;
304*9880d681SAndroid Build Coastguard Worker   case dwarf::DW_EH_PE_pcrel: {
305*9880d681SAndroid Build Coastguard Worker     // Emit a label to the streamer for the current position.  This gives us
306*9880d681SAndroid Build Coastguard Worker     // .-foo addressing.
307*9880d681SAndroid Build Coastguard Worker     MCSymbol *PCSym = getContext().createTempSymbol();
308*9880d681SAndroid Build Coastguard Worker     Streamer.EmitLabel(PCSym);
309*9880d681SAndroid Build Coastguard Worker     const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
310*9880d681SAndroid Build Coastguard Worker     return MCBinaryExpr::createSub(Sym, PC, getContext());
311*9880d681SAndroid Build Coastguard Worker   }
312*9880d681SAndroid Build Coastguard Worker   }
313*9880d681SAndroid Build Coastguard Worker }
314*9880d681SAndroid Build Coastguard Worker 
getDebugThreadLocalSymbol(const MCSymbol * Sym) const315*9880d681SAndroid Build Coastguard Worker const MCExpr *TargetLoweringObjectFile::getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
316*9880d681SAndroid Build Coastguard Worker   // FIXME: It's not clear what, if any, default this should have - perhaps a
317*9880d681SAndroid Build Coastguard Worker   // null return could mean 'no location' & we should just do that here.
318*9880d681SAndroid Build Coastguard Worker   return MCSymbolRefExpr::create(Sym, *Ctx);
319*9880d681SAndroid Build Coastguard Worker }
320*9880d681SAndroid Build Coastguard Worker 
getNameWithPrefix(SmallVectorImpl<char> & OutName,const GlobalValue * GV,Mangler & Mang,const TargetMachine & TM) const321*9880d681SAndroid Build Coastguard Worker void TargetLoweringObjectFile::getNameWithPrefix(
322*9880d681SAndroid Build Coastguard Worker     SmallVectorImpl<char> &OutName, const GlobalValue *GV, Mangler &Mang,
323*9880d681SAndroid Build Coastguard Worker     const TargetMachine &TM) const {
324*9880d681SAndroid Build Coastguard Worker   Mang.getNameWithPrefix(OutName, GV, /*CannotUsePrivateLabel=*/false);
325*9880d681SAndroid Build Coastguard Worker }
326