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
154ba319b5SDimitry Andric #include "llvm/Target/TargetLoweringObjectFile.h"
16db17bf38SDimitry Andric #include "llvm/BinaryFormat/Dwarf.h"
17139f7f9bSDimitry Andric #include "llvm/IR/Constants.h"
18139f7f9bSDimitry Andric #include "llvm/IR/DataLayout.h"
19139f7f9bSDimitry Andric #include "llvm/IR/DerivedTypes.h"
20139f7f9bSDimitry Andric #include "llvm/IR/Function.h"
21139f7f9bSDimitry Andric #include "llvm/IR/GlobalVariable.h"
2291bc56edSDimitry Andric #include "llvm/IR/Mangler.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/ErrorHandling.h"
28f22ef01cSRoman Divacky #include "llvm/Support/raw_ostream.h"
29139f7f9bSDimitry Andric #include "llvm/Target/TargetMachine.h"
30139f7f9bSDimitry Andric #include "llvm/Target/TargetOptions.h"
31f22ef01cSRoman Divacky using namespace llvm;
32f22ef01cSRoman Divacky
33f22ef01cSRoman Divacky //===----------------------------------------------------------------------===//
34f22ef01cSRoman Divacky // Generic Code
35f22ef01cSRoman Divacky //===----------------------------------------------------------------------===//
36f22ef01cSRoman Divacky
376122f3e6SDimitry Andric /// Initialize - this method must be called before any actual lowering is
386122f3e6SDimitry Andric /// done. This specifies the current context for codegen, and gives the
396122f3e6SDimitry Andric /// lowering implementations a chance to set up their default sections.
Initialize(MCContext & ctx,const TargetMachine & TM)406122f3e6SDimitry Andric void TargetLoweringObjectFile::Initialize(MCContext &ctx,
416122f3e6SDimitry Andric const TargetMachine &TM) {
426122f3e6SDimitry Andric Ctx = &ctx;
43d88c1a5aSDimitry Andric // `Initialize` can be called more than once.
44f37b6182SDimitry Andric delete Mang;
45d88c1a5aSDimitry Andric Mang = new Mangler();
462cab237bSDimitry Andric InitMCObjectFileInfo(TM.getTargetTriple(), TM.isPositionIndependent(), *Ctx,
472cab237bSDimitry Andric TM.getCodeModel() == CodeModel::Large);
48*b5893f02SDimitry Andric
49*b5893f02SDimitry Andric // Reset various EH DWARF encodings.
50*b5893f02SDimitry Andric PersonalityEncoding = LSDAEncoding = TTypeEncoding = dwarf::DW_EH_PE_absptr;
51f22ef01cSRoman Divacky }
52f22ef01cSRoman Divacky
~TargetLoweringObjectFile()53f22ef01cSRoman Divacky TargetLoweringObjectFile::~TargetLoweringObjectFile() {
54d88c1a5aSDimitry Andric delete Mang;
55f22ef01cSRoman Divacky }
56f22ef01cSRoman Divacky
isNullOrUndef(const Constant * C)574ba319b5SDimitry Andric static bool isNullOrUndef(const Constant *C) {
584ba319b5SDimitry Andric // Check that the constant isn't all zeros or undefs.
594ba319b5SDimitry Andric if (C->isNullValue() || isa<UndefValue>(C))
604ba319b5SDimitry Andric return true;
614ba319b5SDimitry Andric if (!isa<ConstantAggregate>(C))
624ba319b5SDimitry Andric return false;
634ba319b5SDimitry Andric for (auto Operand : C->operand_values()) {
644ba319b5SDimitry Andric if (!isNullOrUndef(cast<Constant>(Operand)))
654ba319b5SDimitry Andric return false;
664ba319b5SDimitry Andric }
674ba319b5SDimitry Andric return true;
684ba319b5SDimitry Andric }
694ba319b5SDimitry Andric
isSuitableForBSS(const GlobalVariable * GV)704ba319b5SDimitry Andric static bool isSuitableForBSS(const GlobalVariable *GV) {
7117a519f9SDimitry Andric const Constant *C = GV->getInitializer();
72f22ef01cSRoman Divacky
73f22ef01cSRoman Divacky // Must have zero initializer.
744ba319b5SDimitry Andric if (!isNullOrUndef(C))
75f22ef01cSRoman Divacky return false;
76f22ef01cSRoman Divacky
77f22ef01cSRoman Divacky // Leave constant zeros in readonly constant sections, so they can be shared.
78f22ef01cSRoman Divacky if (GV->isConstant())
79f22ef01cSRoman Divacky return false;
80f22ef01cSRoman Divacky
81f22ef01cSRoman Divacky // If the global has an explicit section specified, don't put it in BSS.
8291bc56edSDimitry Andric if (GV->hasSection())
83f22ef01cSRoman Divacky return false;
84f22ef01cSRoman Divacky
85f22ef01cSRoman Divacky // Otherwise, put it in BSS!
86f22ef01cSRoman Divacky return true;
87f22ef01cSRoman Divacky }
88f22ef01cSRoman Divacky
89f22ef01cSRoman Divacky /// IsNullTerminatedString - Return true if the specified constant (which is
90f22ef01cSRoman Divacky /// known to have a type that is an array of 1/2/4 byte elements) ends with a
91dff0c46cSDimitry Andric /// nul value and contains no other nuls in it. Note that this is more general
92dff0c46cSDimitry Andric /// than ConstantDataSequential::isString because we allow 2 & 4 byte strings.
IsNullTerminatedString(const Constant * C)93f22ef01cSRoman Divacky static bool IsNullTerminatedString(const Constant *C) {
94dff0c46cSDimitry Andric // First check: is we have constant array terminated with zero
95dff0c46cSDimitry Andric if (const ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(C)) {
96dff0c46cSDimitry Andric unsigned NumElts = CDS->getNumElements();
97dff0c46cSDimitry Andric assert(NumElts != 0 && "Can't have an empty CDS");
98f22ef01cSRoman Divacky
99dff0c46cSDimitry Andric if (CDS->getElementAsInteger(NumElts-1) != 0)
100f22ef01cSRoman Divacky return false; // Not null terminated.
101f22ef01cSRoman Divacky
102f22ef01cSRoman Divacky // Verify that the null doesn't occur anywhere else in the string.
103dff0c46cSDimitry Andric for (unsigned i = 0; i != NumElts-1; ++i)
104dff0c46cSDimitry Andric if (CDS->getElementAsInteger(i) == 0)
105f22ef01cSRoman Divacky return false;
106f22ef01cSRoman Divacky return true;
107f22ef01cSRoman Divacky }
108f22ef01cSRoman Divacky
109f22ef01cSRoman Divacky // Another possibility: [1 x i8] zeroinitializer
110f22ef01cSRoman Divacky if (isa<ConstantAggregateZero>(C))
111dff0c46cSDimitry Andric return cast<ArrayType>(C->getType())->getNumElements() == 1;
112f22ef01cSRoman Divacky
113f22ef01cSRoman Divacky return false;
114f22ef01cSRoman Divacky }
115f22ef01cSRoman Divacky
getSymbolWithGlobalValueBase(const GlobalValue * GV,StringRef Suffix,const TargetMachine & TM) const11691bc56edSDimitry Andric MCSymbol *TargetLoweringObjectFile::getSymbolWithGlobalValueBase(
117d88c1a5aSDimitry Andric const GlobalValue *GV, StringRef Suffix, const TargetMachine &TM) const {
11891bc56edSDimitry Andric assert(!Suffix.empty());
11991bc56edSDimitry Andric
120f785676fSDimitry Andric SmallString<60> NameStr;
1217d523365SDimitry Andric NameStr += GV->getParent()->getDataLayout().getPrivateGlobalPrefix();
122d88c1a5aSDimitry Andric TM.getNameWithPrefix(NameStr, GV, *Mang);
12391bc56edSDimitry Andric NameStr.append(Suffix.begin(), Suffix.end());
124ff0cc061SDimitry Andric return Ctx->getOrCreateSymbol(NameStr);
125f785676fSDimitry Andric }
126f785676fSDimitry Andric
getCFIPersonalitySymbol(const GlobalValue * GV,const TargetMachine & TM,MachineModuleInfo * MMI) const12791bc56edSDimitry Andric MCSymbol *TargetLoweringObjectFile::getCFIPersonalitySymbol(
128d88c1a5aSDimitry Andric const GlobalValue *GV, const TargetMachine &TM,
1293b0f4066SDimitry Andric MachineModuleInfo *MMI) const {
130d88c1a5aSDimitry Andric return TM.getSymbol(GV);
1313b0f4066SDimitry Andric }
1323b0f4066SDimitry Andric
emitPersonalityValue(MCStreamer & Streamer,const DataLayout &,const MCSymbol * Sym) const1333b0f4066SDimitry Andric void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
1347d523365SDimitry Andric const DataLayout &,
1353b0f4066SDimitry Andric const MCSymbol *Sym) const {
1363b0f4066SDimitry Andric }
1373b0f4066SDimitry Andric
1383b0f4066SDimitry Andric
139f22ef01cSRoman Divacky /// getKindForGlobal - This is a top-level target-independent classifier for
1404ba319b5SDimitry Andric /// a global object. Given a global variable and information from the TM, this
1414ba319b5SDimitry Andric /// function classifies the global in a target independent manner. This function
1424ba319b5SDimitry Andric /// may be overridden by the target implementation.
getKindForGlobal(const GlobalObject * GO,const TargetMachine & TM)143d88c1a5aSDimitry Andric SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalObject *GO,
144f22ef01cSRoman Divacky const TargetMachine &TM){
145d88c1a5aSDimitry Andric assert(!GO->isDeclaration() && !GO->hasAvailableExternallyLinkage() &&
146f22ef01cSRoman Divacky "Can only be used for global definitions");
147f22ef01cSRoman Divacky
1484ba319b5SDimitry Andric // Functions are classified as text sections.
1494ba319b5SDimitry Andric if (isa<Function>(GO))
150f22ef01cSRoman Divacky return SectionKind::getText();
151f22ef01cSRoman Divacky
1524ba319b5SDimitry Andric // Global variables require more detailed analysis.
1534ba319b5SDimitry Andric const auto *GVar = cast<GlobalVariable>(GO);
1544ba319b5SDimitry Andric
155f22ef01cSRoman Divacky // Handle thread-local data first.
156f22ef01cSRoman Divacky if (GVar->isThreadLocal()) {
1574ba319b5SDimitry Andric if (isSuitableForBSS(GVar) && !TM.Options.NoZerosInBSS)
158f22ef01cSRoman Divacky return SectionKind::getThreadBSS();
159f22ef01cSRoman Divacky return SectionKind::getThreadData();
160f22ef01cSRoman Divacky }
161f22ef01cSRoman Divacky
162f22ef01cSRoman Divacky // Variables with common linkage always get classified as common.
163f22ef01cSRoman Divacky if (GVar->hasCommonLinkage())
164f22ef01cSRoman Divacky return SectionKind::getCommon();
165f22ef01cSRoman Divacky
1664ba319b5SDimitry Andric // Most non-mergeable zero data can be put in the BSS section unless otherwise
1674ba319b5SDimitry Andric // specified.
1684ba319b5SDimitry Andric if (isSuitableForBSS(GVar) && !TM.Options.NoZerosInBSS) {
169f22ef01cSRoman Divacky if (GVar->hasLocalLinkage())
170f22ef01cSRoman Divacky return SectionKind::getBSSLocal();
171f22ef01cSRoman Divacky else if (GVar->hasExternalLinkage())
172f22ef01cSRoman Divacky return SectionKind::getBSSExtern();
173f22ef01cSRoman Divacky return SectionKind::getBSS();
174f22ef01cSRoman Divacky }
175f22ef01cSRoman Divacky
176f22ef01cSRoman Divacky // If the global is marked constant, we can put it into a mergable section,
177f22ef01cSRoman Divacky // a mergable string section, or general .data if it contains relocations.
178f22ef01cSRoman Divacky if (GVar->isConstant()) {
179f22ef01cSRoman Divacky // If the initializer for the global contains something that requires a
1807ae0e2c9SDimitry Andric // relocation, then we may have to drop this into a writable data section
181f22ef01cSRoman Divacky // even though it is marked const.
1824ba319b5SDimitry Andric const Constant *C = GVar->getInitializer();
1837d523365SDimitry Andric if (!C->needsRelocation()) {
1842754fe60SDimitry Andric // If the global is required to have a unique address, it can't be put
1852754fe60SDimitry Andric // into a mergable section: just drop it into the general read-only
1862754fe60SDimitry Andric // section instead.
1873ca95b02SDimitry Andric if (!GVar->hasGlobalUnnamedAddr())
1882754fe60SDimitry Andric return SectionKind::getReadOnly();
1892754fe60SDimitry Andric
190f22ef01cSRoman Divacky // If initializer is a null-terminated string, put it in a "cstring"
191f22ef01cSRoman Divacky // section of the right width.
1926122f3e6SDimitry Andric if (ArrayType *ATy = dyn_cast<ArrayType>(C->getType())) {
1936122f3e6SDimitry Andric if (IntegerType *ITy =
194f22ef01cSRoman Divacky dyn_cast<IntegerType>(ATy->getElementType())) {
195f22ef01cSRoman Divacky if ((ITy->getBitWidth() == 8 || ITy->getBitWidth() == 16 ||
196f22ef01cSRoman Divacky ITy->getBitWidth() == 32) &&
197f22ef01cSRoman Divacky IsNullTerminatedString(C)) {
198f22ef01cSRoman Divacky if (ITy->getBitWidth() == 8)
199f22ef01cSRoman Divacky return SectionKind::getMergeable1ByteCString();
200f22ef01cSRoman Divacky if (ITy->getBitWidth() == 16)
201f22ef01cSRoman Divacky return SectionKind::getMergeable2ByteCString();
202f22ef01cSRoman Divacky
203f22ef01cSRoman Divacky assert(ITy->getBitWidth() == 32 && "Unknown width");
204f22ef01cSRoman Divacky return SectionKind::getMergeable4ByteCString();
205f22ef01cSRoman Divacky }
206f22ef01cSRoman Divacky }
207f22ef01cSRoman Divacky }
208f22ef01cSRoman Divacky
209f22ef01cSRoman Divacky // Otherwise, just drop it into a mergable constant section. If we have
210f22ef01cSRoman Divacky // a section for this size, use it, otherwise use the arbitrary sized
211f22ef01cSRoman Divacky // mergable section.
212d88c1a5aSDimitry Andric switch (
213d88c1a5aSDimitry Andric GVar->getParent()->getDataLayout().getTypeAllocSize(C->getType())) {
214f22ef01cSRoman Divacky case 4: return SectionKind::getMergeableConst4();
215f22ef01cSRoman Divacky case 8: return SectionKind::getMergeableConst8();
216f22ef01cSRoman Divacky case 16: return SectionKind::getMergeableConst16();
2173ca95b02SDimitry Andric case 32: return SectionKind::getMergeableConst32();
218ff0cc061SDimitry Andric default:
219ff0cc061SDimitry Andric return SectionKind::getReadOnly();
220f22ef01cSRoman Divacky }
221f22ef01cSRoman Divacky
2227d523365SDimitry Andric } else {
223d88c1a5aSDimitry Andric // In static, ROPI and RWPI relocation models, the linker will resolve
224d88c1a5aSDimitry Andric // all addresses, so the relocation entries will actually be constants by
225d88c1a5aSDimitry Andric // the time the app starts up. However, we can't put this into a
226d88c1a5aSDimitry Andric // mergable section, because the linker doesn't take relocations into
227d88c1a5aSDimitry Andric // consideration when it tries to merge entries in the section.
2284ba319b5SDimitry Andric Reloc::Model ReloModel = TM.getRelocationModel();
229d88c1a5aSDimitry Andric if (ReloModel == Reloc::Static || ReloModel == Reloc::ROPI ||
230d88c1a5aSDimitry Andric ReloModel == Reloc::RWPI || ReloModel == Reloc::ROPI_RWPI)
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
2393ca95b02SDimitry Andric // Okay, this isn't a constant.
2407d523365SDimitry Andric return SectionKind::getData();
241f22ef01cSRoman Divacky }
242f22ef01cSRoman Divacky
243ff0cc061SDimitry Andric /// This method computes the appropriate section to emit the specified global
244ff0cc061SDimitry Andric /// variable or function definition. This should not be passed external (or
245ff0cc061SDimitry Andric /// available externally) globals.
SectionForGlobal(const GlobalObject * GO,SectionKind Kind,const TargetMachine & TM) const246d88c1a5aSDimitry Andric MCSection *TargetLoweringObjectFile::SectionForGlobal(
247d88c1a5aSDimitry Andric const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
248f22ef01cSRoman Divacky // Select section name.
249d88c1a5aSDimitry Andric if (GO->hasSection())
250d88c1a5aSDimitry Andric return getExplicitSectionGlobal(GO, Kind, TM);
251f22ef01cSRoman Divacky
252db17bf38SDimitry Andric if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {
253db17bf38SDimitry Andric auto Attrs = GVar->getAttributes();
254db17bf38SDimitry Andric if ((Attrs.hasAttribute("bss-section") && Kind.isBSS()) ||
255db17bf38SDimitry Andric (Attrs.hasAttribute("data-section") && Kind.isData()) ||
256db17bf38SDimitry Andric (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly())) {
257db17bf38SDimitry Andric return getExplicitSectionGlobal(GO, Kind, TM);
258db17bf38SDimitry Andric }
259db17bf38SDimitry Andric }
260db17bf38SDimitry Andric
261db17bf38SDimitry Andric if (auto *F = dyn_cast<Function>(GO)) {
262db17bf38SDimitry Andric if (F->hasFnAttribute("implicit-section-name"))
263db17bf38SDimitry Andric return getExplicitSectionGlobal(GO, Kind, TM);
264db17bf38SDimitry Andric }
265db17bf38SDimitry Andric
266f22ef01cSRoman Divacky // Use default section depending on the 'type' of global
267d88c1a5aSDimitry Andric return SelectSectionForGlobal(GO, Kind, TM);
268f22ef01cSRoman Divacky }
269f22ef01cSRoman Divacky
getSectionForJumpTable(const Function & F,const TargetMachine & TM) const270ff0cc061SDimitry Andric MCSection *TargetLoweringObjectFile::getSectionForJumpTable(
271d88c1a5aSDimitry Andric const Function &F, const TargetMachine &TM) const {
2723ca95b02SDimitry Andric unsigned Align = 0;
2737d523365SDimitry Andric return getSectionForConstant(F.getParent()->getDataLayout(),
2743ca95b02SDimitry Andric SectionKind::getReadOnly(), /*C=*/nullptr,
2753ca95b02SDimitry Andric Align);
276ff0cc061SDimitry Andric }
277ff0cc061SDimitry Andric
shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,const Function & F) const278ff0cc061SDimitry Andric bool TargetLoweringObjectFile::shouldPutJumpTableInFunctionSection(
279ff0cc061SDimitry Andric bool UsesLabelDifference, const Function &F) const {
280ff0cc061SDimitry Andric // In PIC mode, we need to emit the jump table to the same section as the
281ff0cc061SDimitry Andric // function body itself, otherwise the label differences won't make sense.
282ff0cc061SDimitry Andric // FIXME: Need a better predicate for this: what about custom entries?
283ff0cc061SDimitry Andric if (UsesLabelDifference)
284ff0cc061SDimitry Andric return true;
285ff0cc061SDimitry Andric
286ff0cc061SDimitry Andric // We should also do if the section name is NULL or function is declared
287ff0cc061SDimitry Andric // in discardable section
288ff0cc061SDimitry Andric // FIXME: this isn't the right predicate, should be based on the MCSection
289ff0cc061SDimitry Andric // for the function.
2907a7e6055SDimitry Andric return F.isWeakForLinker();
291ff0cc061SDimitry Andric }
292ff0cc061SDimitry Andric
293ff0cc061SDimitry Andric /// Given a mergable constant with the specified size and relocation
294ff0cc061SDimitry Andric /// information, return a section that it should be placed in.
getSectionForConstant(const DataLayout & DL,SectionKind Kind,const Constant * C,unsigned & Align) const2957d523365SDimitry Andric MCSection *TargetLoweringObjectFile::getSectionForConstant(
2963ca95b02SDimitry Andric const DataLayout &DL, SectionKind Kind, const Constant *C,
2973ca95b02SDimitry Andric unsigned &Align) const {
29891bc56edSDimitry Andric if (Kind.isReadOnly() && ReadOnlySection != nullptr)
299f22ef01cSRoman Divacky return ReadOnlySection;
300f22ef01cSRoman Divacky
301f22ef01cSRoman Divacky return DataSection;
302f22ef01cSRoman Divacky }
303f22ef01cSRoman Divacky
304139f7f9bSDimitry Andric /// getTTypeGlobalReference - Return an MCExpr to use for a
305f22ef01cSRoman Divacky /// reference to the specified global variable from exception
306f22ef01cSRoman Divacky /// handling information.
getTTypeGlobalReference(const GlobalValue * GV,unsigned Encoding,const TargetMachine & TM,MachineModuleInfo * MMI,MCStreamer & Streamer) const30791bc56edSDimitry Andric const MCExpr *TargetLoweringObjectFile::getTTypeGlobalReference(
308d88c1a5aSDimitry Andric const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
309d88c1a5aSDimitry Andric MachineModuleInfo *MMI, MCStreamer &Streamer) const {
310139f7f9bSDimitry Andric const MCSymbolRefExpr *Ref =
311d88c1a5aSDimitry Andric MCSymbolRefExpr::create(TM.getSymbol(GV), getContext());
312139f7f9bSDimitry Andric
313139f7f9bSDimitry Andric return getTTypeReference(Ref, Encoding, Streamer);
314f22ef01cSRoman Divacky }
315f22ef01cSRoman Divacky
316f22ef01cSRoman Divacky const MCExpr *TargetLoweringObjectFile::
getTTypeReference(const MCSymbolRefExpr * Sym,unsigned Encoding,MCStreamer & Streamer) const317139f7f9bSDimitry Andric getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
318f22ef01cSRoman Divacky MCStreamer &Streamer) const {
3193b0f4066SDimitry Andric switch (Encoding & 0x70) {
320f22ef01cSRoman Divacky default:
321f22ef01cSRoman Divacky report_fatal_error("We do not support this DWARF encoding yet!");
322f22ef01cSRoman Divacky case dwarf::DW_EH_PE_absptr:
323f22ef01cSRoman Divacky // Do nothing special
324139f7f9bSDimitry Andric return Sym;
325f22ef01cSRoman Divacky case dwarf::DW_EH_PE_pcrel: {
326f22ef01cSRoman Divacky // Emit a label to the streamer for the current position. This gives us
327f22ef01cSRoman Divacky // .-foo addressing.
328ff0cc061SDimitry Andric MCSymbol *PCSym = getContext().createTempSymbol();
329f22ef01cSRoman Divacky Streamer.EmitLabel(PCSym);
33097bc6c73SDimitry Andric const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
33197bc6c73SDimitry Andric return MCBinaryExpr::createSub(Sym, PC, getContext());
332f22ef01cSRoman Divacky }
333f22ef01cSRoman Divacky }
334f22ef01cSRoman Divacky }
335f785676fSDimitry Andric
getDebugThreadLocalSymbol(const MCSymbol * Sym) const336f785676fSDimitry Andric const MCExpr *TargetLoweringObjectFile::getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
337f785676fSDimitry Andric // FIXME: It's not clear what, if any, default this should have - perhaps a
338f785676fSDimitry Andric // null return could mean 'no location' & we should just do that here.
33997bc6c73SDimitry Andric return MCSymbolRefExpr::create(Sym, *Ctx);
340f785676fSDimitry Andric }
341ff0cc061SDimitry Andric
getNameWithPrefix(SmallVectorImpl<char> & OutName,const GlobalValue * GV,const TargetMachine & TM) const342ff0cc061SDimitry Andric void TargetLoweringObjectFile::getNameWithPrefix(
343d88c1a5aSDimitry Andric SmallVectorImpl<char> &OutName, const GlobalValue *GV,
3447d523365SDimitry Andric const TargetMachine &TM) const {
345d88c1a5aSDimitry Andric Mang->getNameWithPrefix(OutName, GV, /*CannotUsePrivateLabel=*/false);
346ff0cc061SDimitry Andric }
347