1f22ef01cSRoman Divacky //===-- llvm/Target/TargetLoweringObjectFile.cpp - Object File Info -------===//
2f22ef01cSRoman Divacky //
3f22ef01cSRoman Divacky //                     The LLVM Compiler Infrastructure
4f22ef01cSRoman Divacky //
5f22ef01cSRoman Divacky // This file is distributed under the University of Illinois Open Source
6f22ef01cSRoman Divacky // License. See LICENSE.TXT for details.
7f22ef01cSRoman Divacky //
8f22ef01cSRoman Divacky //===----------------------------------------------------------------------===//
9f22ef01cSRoman Divacky //
10f22ef01cSRoman Divacky // This file implements classes used to handle lowerings specific to common
11f22ef01cSRoman Divacky // object file formats.
12f22ef01cSRoman Divacky //
13f22ef01cSRoman Divacky //===----------------------------------------------------------------------===//
14f22ef01cSRoman Divacky 
15f22ef01cSRoman Divacky #include "llvm/Target/TargetLoweringObjectFile.h"
16139f7f9bSDimitry Andric #include "llvm/IR/Constants.h"
17139f7f9bSDimitry Andric #include "llvm/IR/DataLayout.h"
18139f7f9bSDimitry Andric #include "llvm/IR/DerivedTypes.h"
19139f7f9bSDimitry Andric #include "llvm/IR/Function.h"
20139f7f9bSDimitry Andric #include "llvm/IR/GlobalVariable.h"
2191bc56edSDimitry Andric #include "llvm/IR/Mangler.h"
2291bc56edSDimitry Andric #include "llvm/MC/MCAsmInfo.h"
23f22ef01cSRoman Divacky #include "llvm/MC/MCContext.h"
24f22ef01cSRoman Divacky #include "llvm/MC/MCExpr.h"
25f22ef01cSRoman Divacky #include "llvm/MC/MCStreamer.h"
26f22ef01cSRoman Divacky #include "llvm/MC/MCSymbol.h"
27f22ef01cSRoman Divacky #include "llvm/Support/Dwarf.h"
28f22ef01cSRoman Divacky #include "llvm/Support/ErrorHandling.h"
29f22ef01cSRoman Divacky #include "llvm/Support/raw_ostream.h"
3091bc56edSDimitry Andric #include "llvm/Target/TargetLowering.h"
31139f7f9bSDimitry Andric #include "llvm/Target/TargetMachine.h"
32139f7f9bSDimitry Andric #include "llvm/Target/TargetOptions.h"
3339d628a0SDimitry Andric #include "llvm/Target/TargetSubtargetInfo.h"
34f22ef01cSRoman Divacky using namespace llvm;
35f22ef01cSRoman Divacky 
36f22ef01cSRoman Divacky //===----------------------------------------------------------------------===//
37f22ef01cSRoman Divacky //                              Generic Code
38f22ef01cSRoman Divacky //===----------------------------------------------------------------------===//
39f22ef01cSRoman Divacky 
406122f3e6SDimitry Andric /// Initialize - this method must be called before any actual lowering is
416122f3e6SDimitry Andric /// done.  This specifies the current context for codegen, and gives the
426122f3e6SDimitry Andric /// lowering implementations a chance to set up their default sections.
436122f3e6SDimitry Andric void TargetLoweringObjectFile::Initialize(MCContext &ctx,
446122f3e6SDimitry Andric                                           const TargetMachine &TM) {
456122f3e6SDimitry Andric   Ctx = &ctx;
46ff0cc061SDimitry Andric   DL = TM.getDataLayout();
478f0fd8f6SDimitry Andric   InitMCObjectFileInfo(TM.getTargetTriple(), TM.getRelocationModel(),
488f0fd8f6SDimitry Andric                        TM.getCodeModel(), *Ctx);
49f22ef01cSRoman Divacky }
50f22ef01cSRoman Divacky 
51f22ef01cSRoman Divacky TargetLoweringObjectFile::~TargetLoweringObjectFile() {
52f22ef01cSRoman Divacky }
53f22ef01cSRoman Divacky 
54dff0c46cSDimitry Andric static bool isSuitableForBSS(const GlobalVariable *GV, bool NoZerosInBSS) {
5517a519f9SDimitry Andric   const Constant *C = GV->getInitializer();
56f22ef01cSRoman Divacky 
57f22ef01cSRoman Divacky   // Must have zero initializer.
58f22ef01cSRoman Divacky   if (!C->isNullValue())
59f22ef01cSRoman Divacky     return false;
60f22ef01cSRoman Divacky 
61f22ef01cSRoman Divacky   // Leave constant zeros in readonly constant sections, so they can be shared.
62f22ef01cSRoman Divacky   if (GV->isConstant())
63f22ef01cSRoman Divacky     return false;
64f22ef01cSRoman Divacky 
65f22ef01cSRoman Divacky   // If the global has an explicit section specified, don't put it in BSS.
6691bc56edSDimitry Andric   if (GV->hasSection())
67f22ef01cSRoman Divacky     return false;
68f22ef01cSRoman Divacky 
69f22ef01cSRoman Divacky   // If -nozero-initialized-in-bss is specified, don't ever use BSS.
70f22ef01cSRoman Divacky   if (NoZerosInBSS)
71f22ef01cSRoman Divacky     return false;
72f22ef01cSRoman Divacky 
73f22ef01cSRoman Divacky   // Otherwise, put it in BSS!
74f22ef01cSRoman Divacky   return true;
75f22ef01cSRoman Divacky }
76f22ef01cSRoman Divacky 
77f22ef01cSRoman Divacky /// IsNullTerminatedString - Return true if the specified constant (which is
78f22ef01cSRoman Divacky /// known to have a type that is an array of 1/2/4 byte elements) ends with a
79dff0c46cSDimitry Andric /// nul value and contains no other nuls in it.  Note that this is more general
80dff0c46cSDimitry Andric /// than ConstantDataSequential::isString because we allow 2 & 4 byte strings.
81f22ef01cSRoman Divacky static bool IsNullTerminatedString(const Constant *C) {
82dff0c46cSDimitry Andric   // First check: is we have constant array terminated with zero
83dff0c46cSDimitry Andric   if (const ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(C)) {
84dff0c46cSDimitry Andric     unsigned NumElts = CDS->getNumElements();
85dff0c46cSDimitry Andric     assert(NumElts != 0 && "Can't have an empty CDS");
86f22ef01cSRoman Divacky 
87dff0c46cSDimitry Andric     if (CDS->getElementAsInteger(NumElts-1) != 0)
88f22ef01cSRoman Divacky       return false; // Not null terminated.
89f22ef01cSRoman Divacky 
90f22ef01cSRoman Divacky     // Verify that the null doesn't occur anywhere else in the string.
91dff0c46cSDimitry Andric     for (unsigned i = 0; i != NumElts-1; ++i)
92dff0c46cSDimitry Andric       if (CDS->getElementAsInteger(i) == 0)
93f22ef01cSRoman Divacky         return false;
94f22ef01cSRoman Divacky     return true;
95f22ef01cSRoman Divacky   }
96f22ef01cSRoman Divacky 
97f22ef01cSRoman Divacky   // Another possibility: [1 x i8] zeroinitializer
98f22ef01cSRoman Divacky   if (isa<ConstantAggregateZero>(C))
99dff0c46cSDimitry Andric     return cast<ArrayType>(C->getType())->getNumElements() == 1;
100f22ef01cSRoman Divacky 
101f22ef01cSRoman Divacky   return false;
102f22ef01cSRoman Divacky }
103f22ef01cSRoman Divacky 
10491bc56edSDimitry Andric MCSymbol *TargetLoweringObjectFile::getSymbolWithGlobalValueBase(
10591bc56edSDimitry Andric     const GlobalValue *GV, StringRef Suffix, Mangler &Mang,
10691bc56edSDimitry Andric     const TargetMachine &TM) const {
10791bc56edSDimitry Andric   assert(!Suffix.empty());
10891bc56edSDimitry Andric 
109f785676fSDimitry Andric   SmallString<60> NameStr;
11091bc56edSDimitry Andric   NameStr += DL->getPrivateGlobalPrefix();
11191bc56edSDimitry Andric   TM.getNameWithPrefix(NameStr, GV, Mang);
11291bc56edSDimitry Andric   NameStr.append(Suffix.begin(), Suffix.end());
113ff0cc061SDimitry Andric   return Ctx->getOrCreateSymbol(NameStr);
114f785676fSDimitry Andric }
115f785676fSDimitry Andric 
11691bc56edSDimitry Andric MCSymbol *TargetLoweringObjectFile::getCFIPersonalitySymbol(
11791bc56edSDimitry Andric     const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
1183b0f4066SDimitry Andric     MachineModuleInfo *MMI) const {
11991bc56edSDimitry Andric   return TM.getSymbol(GV, Mang);
1203b0f4066SDimitry Andric }
1213b0f4066SDimitry Andric 
1223b0f4066SDimitry Andric void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
1233b0f4066SDimitry Andric                                                     const TargetMachine &TM,
1243b0f4066SDimitry Andric                                                     const MCSymbol *Sym) const {
1253b0f4066SDimitry Andric }
1263b0f4066SDimitry Andric 
1273b0f4066SDimitry Andric 
128f22ef01cSRoman Divacky /// getKindForGlobal - This is a top-level target-independent classifier for
129f22ef01cSRoman Divacky /// a global variable.  Given an global variable and information from TM, it
130f22ef01cSRoman Divacky /// classifies the global in a variety of ways that make various target
131f22ef01cSRoman Divacky /// implementations simpler.  The target implementation is free to ignore this
132f22ef01cSRoman Divacky /// extra info of course.
133f22ef01cSRoman Divacky SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalValue *GV,
134f22ef01cSRoman Divacky                                                        const TargetMachine &TM){
135f22ef01cSRoman Divacky   assert(!GV->isDeclaration() && !GV->hasAvailableExternallyLinkage() &&
136f22ef01cSRoman Divacky          "Can only be used for global definitions");
137f22ef01cSRoman Divacky 
138f22ef01cSRoman Divacky   Reloc::Model ReloModel = TM.getRelocationModel();
139f22ef01cSRoman Divacky 
140f22ef01cSRoman Divacky   // Early exit - functions should be always in text sections.
141f22ef01cSRoman Divacky   const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
14291bc56edSDimitry Andric   if (!GVar)
143f22ef01cSRoman Divacky     return SectionKind::getText();
144f22ef01cSRoman Divacky 
145f22ef01cSRoman Divacky   // Handle thread-local data first.
146f22ef01cSRoman Divacky   if (GVar->isThreadLocal()) {
147dff0c46cSDimitry Andric     if (isSuitableForBSS(GVar, TM.Options.NoZerosInBSS))
148f22ef01cSRoman Divacky       return SectionKind::getThreadBSS();
149f22ef01cSRoman Divacky     return SectionKind::getThreadData();
150f22ef01cSRoman Divacky   }
151f22ef01cSRoman Divacky 
152f22ef01cSRoman Divacky   // Variables with common linkage always get classified as common.
153f22ef01cSRoman Divacky   if (GVar->hasCommonLinkage())
154f22ef01cSRoman Divacky     return SectionKind::getCommon();
155f22ef01cSRoman Divacky 
156f22ef01cSRoman Divacky   // Variable can be easily put to BSS section.
157dff0c46cSDimitry Andric   if (isSuitableForBSS(GVar, TM.Options.NoZerosInBSS)) {
158f22ef01cSRoman Divacky     if (GVar->hasLocalLinkage())
159f22ef01cSRoman Divacky       return SectionKind::getBSSLocal();
160f22ef01cSRoman Divacky     else if (GVar->hasExternalLinkage())
161f22ef01cSRoman Divacky       return SectionKind::getBSSExtern();
162f22ef01cSRoman Divacky     return SectionKind::getBSS();
163f22ef01cSRoman Divacky   }
164f22ef01cSRoman Divacky 
16517a519f9SDimitry Andric   const Constant *C = GVar->getInitializer();
166f22ef01cSRoman Divacky 
167f22ef01cSRoman Divacky   // If the global is marked constant, we can put it into a mergable section,
168f22ef01cSRoman Divacky   // a mergable string section, or general .data if it contains relocations.
169f22ef01cSRoman Divacky   if (GVar->isConstant()) {
170f22ef01cSRoman Divacky     // If the initializer for the global contains something that requires a
1717ae0e2c9SDimitry Andric     // relocation, then we may have to drop this into a writable data section
172f22ef01cSRoman Divacky     // even though it is marked const.
173f22ef01cSRoman Divacky     switch (C->getRelocationInfo()) {
174f22ef01cSRoman Divacky     case Constant::NoRelocation:
1752754fe60SDimitry Andric       // If the global is required to have a unique address, it can't be put
1762754fe60SDimitry Andric       // into a mergable section: just drop it into the general read-only
1772754fe60SDimitry Andric       // section instead.
1782754fe60SDimitry Andric       if (!GVar->hasUnnamedAddr())
1792754fe60SDimitry Andric         return SectionKind::getReadOnly();
1802754fe60SDimitry Andric 
181f22ef01cSRoman Divacky       // If initializer is a null-terminated string, put it in a "cstring"
182f22ef01cSRoman Divacky       // section of the right width.
1836122f3e6SDimitry Andric       if (ArrayType *ATy = dyn_cast<ArrayType>(C->getType())) {
1846122f3e6SDimitry Andric         if (IntegerType *ITy =
185f22ef01cSRoman Divacky               dyn_cast<IntegerType>(ATy->getElementType())) {
186f22ef01cSRoman Divacky           if ((ITy->getBitWidth() == 8 || ITy->getBitWidth() == 16 ||
187f22ef01cSRoman Divacky                ITy->getBitWidth() == 32) &&
188f22ef01cSRoman Divacky               IsNullTerminatedString(C)) {
189f22ef01cSRoman Divacky             if (ITy->getBitWidth() == 8)
190f22ef01cSRoman Divacky               return SectionKind::getMergeable1ByteCString();
191f22ef01cSRoman Divacky             if (ITy->getBitWidth() == 16)
192f22ef01cSRoman Divacky               return SectionKind::getMergeable2ByteCString();
193f22ef01cSRoman Divacky 
194f22ef01cSRoman Divacky             assert(ITy->getBitWidth() == 32 && "Unknown width");
195f22ef01cSRoman Divacky             return SectionKind::getMergeable4ByteCString();
196f22ef01cSRoman Divacky           }
197f22ef01cSRoman Divacky         }
198f22ef01cSRoman Divacky       }
199f22ef01cSRoman Divacky 
200f22ef01cSRoman Divacky       // Otherwise, just drop it into a mergable constant section.  If we have
201f22ef01cSRoman Divacky       // a section for this size, use it, otherwise use the arbitrary sized
202f22ef01cSRoman Divacky       // mergable section.
203ff0cc061SDimitry Andric       switch (TM.getDataLayout()->getTypeAllocSize(C->getType())) {
204f22ef01cSRoman Divacky       case 4:  return SectionKind::getMergeableConst4();
205f22ef01cSRoman Divacky       case 8:  return SectionKind::getMergeableConst8();
206f22ef01cSRoman Divacky       case 16: return SectionKind::getMergeableConst16();
207ff0cc061SDimitry Andric       default:
208ff0cc061SDimitry Andric         return SectionKind::getReadOnly();
209f22ef01cSRoman Divacky       }
210f22ef01cSRoman Divacky 
211f22ef01cSRoman Divacky     case Constant::LocalRelocation:
212f22ef01cSRoman Divacky       // In static relocation model, the linker will resolve all addresses, so
213f22ef01cSRoman Divacky       // the relocation entries will actually be constants by the time the app
214f22ef01cSRoman Divacky       // starts up.  However, we can't put this into a mergable section, because
215f22ef01cSRoman Divacky       // the linker doesn't take relocations into consideration when it tries to
216f22ef01cSRoman Divacky       // merge entries in the section.
217f22ef01cSRoman Divacky       if (ReloModel == Reloc::Static)
218f22ef01cSRoman Divacky         return SectionKind::getReadOnly();
219f22ef01cSRoman Divacky 
220f22ef01cSRoman Divacky       // Otherwise, the dynamic linker needs to fix it up, put it in the
221f22ef01cSRoman Divacky       // writable data.rel.local section.
222f22ef01cSRoman Divacky       return SectionKind::getReadOnlyWithRelLocal();
223f22ef01cSRoman Divacky 
224f22ef01cSRoman Divacky     case Constant::GlobalRelocations:
225f22ef01cSRoman Divacky       // In static relocation model, the linker will resolve all addresses, so
226f22ef01cSRoman Divacky       // the relocation entries will actually be constants by the time the app
227f22ef01cSRoman Divacky       // starts up.  However, we can't put this into a mergable section, because
228f22ef01cSRoman Divacky       // the linker doesn't take relocations into consideration when it tries to
229f22ef01cSRoman Divacky       // merge entries in the section.
230f22ef01cSRoman Divacky       if (ReloModel == Reloc::Static)
231f22ef01cSRoman Divacky         return SectionKind::getReadOnly();
232f22ef01cSRoman Divacky 
233f22ef01cSRoman Divacky       // Otherwise, the dynamic linker needs to fix it up, put it in the
234f22ef01cSRoman Divacky       // writable data.rel section.
235f22ef01cSRoman Divacky       return SectionKind::getReadOnlyWithRel();
236f22ef01cSRoman Divacky     }
237f22ef01cSRoman Divacky   }
238f22ef01cSRoman Divacky 
239f22ef01cSRoman Divacky   // Okay, this isn't a constant.  If the initializer for the global is going
240f22ef01cSRoman Divacky   // to require a runtime relocation by the dynamic linker, put it into a more
241f22ef01cSRoman Divacky   // specific section to improve startup time of the app.  This coalesces these
242f22ef01cSRoman Divacky   // globals together onto fewer pages, improving the locality of the dynamic
243f22ef01cSRoman Divacky   // linker.
244f22ef01cSRoman Divacky   if (ReloModel == Reloc::Static)
245f22ef01cSRoman Divacky     return SectionKind::getDataNoRel();
246f22ef01cSRoman Divacky 
247f22ef01cSRoman Divacky   switch (C->getRelocationInfo()) {
248f22ef01cSRoman Divacky   case Constant::NoRelocation:
249f22ef01cSRoman Divacky     return SectionKind::getDataNoRel();
250f22ef01cSRoman Divacky   case Constant::LocalRelocation:
251f22ef01cSRoman Divacky     return SectionKind::getDataRelLocal();
252f22ef01cSRoman Divacky   case Constant::GlobalRelocations:
253f22ef01cSRoman Divacky     return SectionKind::getDataRel();
254f22ef01cSRoman Divacky   }
255dff0c46cSDimitry Andric   llvm_unreachable("Invalid relocation");
256f22ef01cSRoman Divacky }
257f22ef01cSRoman Divacky 
258ff0cc061SDimitry Andric /// This method computes the appropriate section to emit the specified global
259ff0cc061SDimitry Andric /// variable or function definition.  This should not be passed external (or
260ff0cc061SDimitry Andric /// available externally) globals.
261ff0cc061SDimitry Andric MCSection *
262ff0cc061SDimitry Andric TargetLoweringObjectFile::SectionForGlobal(const GlobalValue *GV,
263ff0cc061SDimitry Andric                                            SectionKind Kind, Mangler &Mang,
264f22ef01cSRoman Divacky                                            const TargetMachine &TM) const {
265f22ef01cSRoman Divacky   // Select section name.
266f22ef01cSRoman Divacky   if (GV->hasSection())
267f22ef01cSRoman Divacky     return getExplicitSectionGlobal(GV, Kind, Mang, TM);
268f22ef01cSRoman Divacky 
269f22ef01cSRoman Divacky 
270f22ef01cSRoman Divacky   // Use default section depending on the 'type' of global
271f22ef01cSRoman Divacky   return SelectSectionForGlobal(GV, Kind, Mang, TM);
272f22ef01cSRoman Divacky }
273f22ef01cSRoman Divacky 
274ff0cc061SDimitry Andric MCSection *TargetLoweringObjectFile::getSectionForJumpTable(
275ff0cc061SDimitry Andric     const Function &F, Mangler &Mang, const TargetMachine &TM) const {
276ff0cc061SDimitry Andric   return getSectionForConstant(SectionKind::getReadOnly(), /*C=*/nullptr);
277ff0cc061SDimitry Andric }
278ff0cc061SDimitry Andric 
279ff0cc061SDimitry Andric bool TargetLoweringObjectFile::shouldPutJumpTableInFunctionSection(
280ff0cc061SDimitry Andric     bool UsesLabelDifference, const Function &F) const {
281ff0cc061SDimitry Andric   // In PIC mode, we need to emit the jump table to the same section as the
282ff0cc061SDimitry Andric   // function body itself, otherwise the label differences won't make sense.
283ff0cc061SDimitry Andric   // FIXME: Need a better predicate for this: what about custom entries?
284ff0cc061SDimitry Andric   if (UsesLabelDifference)
285ff0cc061SDimitry Andric     return true;
286ff0cc061SDimitry Andric 
287ff0cc061SDimitry Andric   // We should also do if the section name is NULL or function is declared
288ff0cc061SDimitry Andric   // in discardable section
289ff0cc061SDimitry Andric   // FIXME: this isn't the right predicate, should be based on the MCSection
290ff0cc061SDimitry Andric   // for the function.
291ff0cc061SDimitry Andric   if (F.isWeakForLinker())
292ff0cc061SDimitry Andric     return true;
293ff0cc061SDimitry Andric 
294ff0cc061SDimitry Andric   return false;
295ff0cc061SDimitry Andric }
296ff0cc061SDimitry Andric 
297ff0cc061SDimitry Andric /// Given a mergable constant with the specified size and relocation
298ff0cc061SDimitry Andric /// information, return a section that it should be placed in.
299ff0cc061SDimitry Andric MCSection *
30091bc56edSDimitry Andric TargetLoweringObjectFile::getSectionForConstant(SectionKind Kind,
30191bc56edSDimitry Andric                                                 const Constant *C) const {
30291bc56edSDimitry Andric   if (Kind.isReadOnly() && ReadOnlySection != nullptr)
303f22ef01cSRoman Divacky     return ReadOnlySection;
304f22ef01cSRoman Divacky 
305f22ef01cSRoman Divacky   return DataSection;
306f22ef01cSRoman Divacky }
307f22ef01cSRoman Divacky 
308139f7f9bSDimitry Andric /// getTTypeGlobalReference - Return an MCExpr to use for a
309f22ef01cSRoman Divacky /// reference to the specified global variable from exception
310f22ef01cSRoman Divacky /// handling information.
31191bc56edSDimitry Andric const MCExpr *TargetLoweringObjectFile::getTTypeGlobalReference(
31291bc56edSDimitry Andric     const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
31391bc56edSDimitry Andric     const TargetMachine &TM, MachineModuleInfo *MMI,
314f22ef01cSRoman Divacky     MCStreamer &Streamer) const {
315139f7f9bSDimitry Andric   const MCSymbolRefExpr *Ref =
31697bc6c73SDimitry Andric       MCSymbolRefExpr::create(TM.getSymbol(GV, Mang), getContext());
317139f7f9bSDimitry Andric 
318139f7f9bSDimitry Andric   return getTTypeReference(Ref, Encoding, Streamer);
319f22ef01cSRoman Divacky }
320f22ef01cSRoman Divacky 
321f22ef01cSRoman Divacky const MCExpr *TargetLoweringObjectFile::
322139f7f9bSDimitry Andric getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
323f22ef01cSRoman Divacky                   MCStreamer &Streamer) const {
3243b0f4066SDimitry Andric   switch (Encoding & 0x70) {
325f22ef01cSRoman Divacky   default:
326f22ef01cSRoman Divacky     report_fatal_error("We do not support this DWARF encoding yet!");
327f22ef01cSRoman Divacky   case dwarf::DW_EH_PE_absptr:
328f22ef01cSRoman Divacky     // Do nothing special
329139f7f9bSDimitry Andric     return Sym;
330f22ef01cSRoman Divacky   case dwarf::DW_EH_PE_pcrel: {
331f22ef01cSRoman Divacky     // Emit a label to the streamer for the current position.  This gives us
332f22ef01cSRoman Divacky     // .-foo addressing.
333ff0cc061SDimitry Andric     MCSymbol *PCSym = getContext().createTempSymbol();
334f22ef01cSRoman Divacky     Streamer.EmitLabel(PCSym);
33597bc6c73SDimitry Andric     const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
33697bc6c73SDimitry Andric     return MCBinaryExpr::createSub(Sym, PC, getContext());
337f22ef01cSRoman Divacky   }
338f22ef01cSRoman Divacky   }
339f22ef01cSRoman Divacky }
340f785676fSDimitry Andric 
341f785676fSDimitry Andric const MCExpr *TargetLoweringObjectFile::getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
342f785676fSDimitry Andric   // FIXME: It's not clear what, if any, default this should have - perhaps a
343f785676fSDimitry Andric   // null return could mean 'no location' & we should just do that here.
34497bc6c73SDimitry Andric   return MCSymbolRefExpr::create(Sym, *Ctx);
345f785676fSDimitry Andric }
346ff0cc061SDimitry Andric 
347ff0cc061SDimitry Andric void TargetLoweringObjectFile::getNameWithPrefix(
348ff0cc061SDimitry Andric     SmallVectorImpl<char> &OutName, const GlobalValue *GV,
349ff0cc061SDimitry Andric     bool CannotUsePrivateLabel, Mangler &Mang, const TargetMachine &TM) const {
350ff0cc061SDimitry Andric   Mang.getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
351ff0cc061SDimitry Andric }
352