blob: 6654eab7f01e1159e768319c53bea78a1fb14fb1 [file] [log] [blame]
Chris Lattner5e693ed2009-07-28 03:13:23 +00001//===-- llvm/Target/TargetLoweringObjectFile.cpp - Object File Info -------===//
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
David Blaikieb3bde2e2017-11-17 01:07:10 +000015#include "llvm/CodeGen/TargetLoweringObjectFile.h"
Zachary Turner264b5d92017-06-07 03:48:56 +000016#include "llvm/BinaryFormat/Dwarf.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000017#include "llvm/CodeGen/TargetLowering.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000018#include "llvm/IR/Constants.h"
19#include "llvm/IR/DataLayout.h"
20#include "llvm/IR/DerivedTypes.h"
21#include "llvm/IR/Function.h"
22#include "llvm/IR/GlobalVariable.h"
Rafael Espindola894843c2014-01-07 21:19:40 +000023#include "llvm/IR/Mangler.h"
Chris Lattner4d2c0f92009-07-31 18:48:30 +000024#include "llvm/MC/MCContext.h"
Chris Lattnerb8666022009-09-16 01:46:41 +000025#include "llvm/MC/MCExpr.h"
Chris Lattner03627cb2010-03-11 21:55:20 +000026#include "llvm/MC/MCStreamer.h"
Chris Lattnerccbeed22010-01-13 21:29:21 +000027#include "llvm/MC/MCSymbol.h"
Chris Lattnerd82510e2009-11-07 09:20:54 +000028#include "llvm/Support/ErrorHandling.h"
Chris Lattnerccbeed22010-01-13 21:29:21 +000029#include "llvm/Support/raw_ostream.h"
Chandler Carruth442f7842014-03-04 10:07:28 +000030#include "llvm/Target/TargetMachine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000031#include "llvm/Target/TargetOptions.h"
Chris Lattner5e693ed2009-07-28 03:13:23 +000032using namespace llvm;
33
34//===----------------------------------------------------------------------===//
35// Generic Code
36//===----------------------------------------------------------------------===//
37
Evan Cheng76792992011-07-20 05:58:47 +000038/// Initialize - this method must be called before any actual lowering is
39/// done. This specifies the current context for codegen, and gives the
40/// lowering implementations a chance to set up their default sections.
41void TargetLoweringObjectFile::Initialize(MCContext &ctx,
42 const TargetMachine &TM) {
43 Ctx = &ctx;
Eric Liud07ad512016-09-16 11:50:57 +000044 // `Initialize` can be called more than once.
Gabor Horvath43b72d52017-05-01 16:18:42 +000045 delete Mang;
Eric Christopher4367c7f2016-09-16 07:33:15 +000046 Mang = new Mangler();
Rafael Espindola9f929952017-08-02 20:32:26 +000047 InitMCObjectFileInfo(TM.getTargetTriple(), TM.isPositionIndependent(), *Ctx,
48 TM.getCodeModel() == CodeModel::Large);
Chris Lattner5e693ed2009-07-28 03:13:23 +000049}
Saleem Abdulrasool0d3d6c42014-04-16 04:15:25 +000050
Chris Lattner5e693ed2009-07-28 03:13:23 +000051TargetLoweringObjectFile::~TargetLoweringObjectFile() {
Eric Christopher4367c7f2016-09-16 07:33:15 +000052 delete Mang;
Chris Lattner5e693ed2009-07-28 03:13:23 +000053}
54
Eli Friedmancd07a3e2018-02-06 23:22:14 +000055static bool isNullOrUndef(const Constant *C) {
56 // Check that the constant isn't all zeros or undefs.
57 if (C->isNullValue() || isa<UndefValue>(C))
58 return true;
59 if (!isa<ConstantAggregate>(C))
60 return false;
61 for (auto Operand : C->operand_values()) {
62 if (!isNullOrUndef(cast<Constant>(Operand)))
63 return false;
64 }
65 return true;
66}
67
Nick Lewycky50f02cb2011-12-02 22:16:29 +000068static bool isSuitableForBSS(const GlobalVariable *GV, bool NoZerosInBSS) {
Jay Foad60020682011-06-19 18:37:11 +000069 const Constant *C = GV->getInitializer();
Anton Korobeynikov1df58862009-09-09 08:41:20 +000070
Chris Lattner5e693ed2009-07-28 03:13:23 +000071 // Must have zero initializer.
Eli Friedmancd07a3e2018-02-06 23:22:14 +000072 if (!isNullOrUndef(C))
Chris Lattner5e693ed2009-07-28 03:13:23 +000073 return false;
Anton Korobeynikov1df58862009-09-09 08:41:20 +000074
Chris Lattner5e693ed2009-07-28 03:13:23 +000075 // Leave constant zeros in readonly constant sections, so they can be shared.
76 if (GV->isConstant())
77 return false;
Anton Korobeynikov1df58862009-09-09 08:41:20 +000078
Chris Lattner5e693ed2009-07-28 03:13:23 +000079 // If the global has an explicit section specified, don't put it in BSS.
David Majnemer483e4e02014-05-17 05:18:40 +000080 if (GV->hasSection())
Chris Lattner5e693ed2009-07-28 03:13:23 +000081 return false;
Anton Korobeynikov1df58862009-09-09 08:41:20 +000082
Chris Lattner5e693ed2009-07-28 03:13:23 +000083 // If -nozero-initialized-in-bss is specified, don't ever use BSS.
84 if (NoZerosInBSS)
85 return false;
Anton Korobeynikov1df58862009-09-09 08:41:20 +000086
Chris Lattner5e693ed2009-07-28 03:13:23 +000087 // Otherwise, put it in BSS!
88 return true;
89}
90
Chris Lattner81bbf442009-08-04 16:13:09 +000091/// IsNullTerminatedString - Return true if the specified constant (which is
92/// known to have a type that is an array of 1/2/4 byte elements) ends with a
Chris Lattner139822f2012-01-24 14:17:05 +000093/// nul value and contains no other nuls in it. Note that this is more general
94/// than ConstantDataSequential::isString because we allow 2 & 4 byte strings.
Chris Lattner81bbf442009-08-04 16:13:09 +000095static bool IsNullTerminatedString(const Constant *C) {
Chris Lattner139822f2012-01-24 14:17:05 +000096 // First check: is we have constant array terminated with zero
Chris Lattner139822f2012-01-24 14:17:05 +000097 if (const ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(C)) {
98 unsigned NumElts = CDS->getNumElements();
99 assert(NumElts != 0 && "Can't have an empty CDS");
100
101 if (CDS->getElementAsInteger(NumElts-1) != 0)
102 return false; // Not null terminated.
103
104 // Verify that the null doesn't occur anywhere else in the string.
105 for (unsigned i = 0; i != NumElts-1; ++i)
106 if (CDS->getElementAsInteger(i) == 0)
107 return false;
108 return true;
109 }
Chris Lattner5e693ed2009-07-28 03:13:23 +0000110
111 // Another possibility: [1 x i8] zeroinitializer
112 if (isa<ConstantAggregateZero>(C))
Chris Lattner139822f2012-01-24 14:17:05 +0000113 return cast<ArrayType>(C->getType())->getNumElements() == 1;
Chris Lattner5e693ed2009-07-28 03:13:23 +0000114
115 return false;
116}
117
Rafael Espindolaf4e6b292013-12-02 16:25:47 +0000118MCSymbol *TargetLoweringObjectFile::getSymbolWithGlobalValueBase(
Eric Christopher4367c7f2016-09-16 07:33:15 +0000119 const GlobalValue *GV, StringRef Suffix, const TargetMachine &TM) const {
Rafael Espindola117b20c2013-12-05 05:53:12 +0000120 assert(!Suffix.empty());
Rafael Espindola117b20c2013-12-05 05:53:12 +0000121
Rafael Espindolaf4e6b292013-12-02 16:25:47 +0000122 SmallString<60> NameStr;
Mehdi Amini5c0fa582015-07-16 06:04:17 +0000123 NameStr += GV->getParent()->getDataLayout().getPrivateGlobalPrefix();
Eric Christopher4367c7f2016-09-16 07:33:15 +0000124 TM.getNameWithPrefix(NameStr, GV, *Mang);
Rafael Espindolaf4e6b292013-12-02 16:25:47 +0000125 NameStr.append(Suffix.begin(), Suffix.end());
Jim Grosbach6f482002015-05-18 18:43:14 +0000126 return Ctx->getOrCreateSymbol(NameStr);
Rafael Espindolaf4e6b292013-12-02 16:25:47 +0000127}
Rafael Espindolae133ed82013-10-29 17:28:26 +0000128
Rafael Espindoladaeafb42014-02-19 17:23:20 +0000129MCSymbol *TargetLoweringObjectFile::getCFIPersonalitySymbol(
Eric Christopher4367c7f2016-09-16 07:33:15 +0000130 const GlobalValue *GV, const TargetMachine &TM,
Rafael Espindoladaeafb42014-02-19 17:23:20 +0000131 MachineModuleInfo *MMI) const {
Tim Northoverb64fb452016-11-22 16:17:20 +0000132 return TM.getSymbol(GV);
Rafael Espindolaa83b1772011-04-16 03:51:21 +0000133}
134
135void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
Mehdi Amini5c0fa582015-07-16 06:04:17 +0000136 const DataLayout &,
Rafael Espindolaa83b1772011-04-16 03:51:21 +0000137 const MCSymbol *Sym) const {
Rafael Espindolaa83b1772011-04-16 03:51:21 +0000138}
139
140
Chris Lattnercbc7b262009-08-05 04:25:40 +0000141/// getKindForGlobal - This is a top-level target-independent classifier for
Chris Lattnerc9c277b2009-08-01 21:11:14 +0000142/// a global variable. Given an global variable and information from TM, it
143/// classifies the global in a variety of ways that make various target
144/// implementations simpler. The target implementation is free to ignore this
145/// extra info of course.
Peter Collingbourne67335642016-10-24 19:23:39 +0000146SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalObject *GO,
Chris Lattnercbc7b262009-08-05 04:25:40 +0000147 const TargetMachine &TM){
Peter Collingbourne67335642016-10-24 19:23:39 +0000148 assert(!GO->isDeclaration() && !GO->hasAvailableExternallyLinkage() &&
Chris Lattnercbc7b262009-08-05 04:25:40 +0000149 "Can only be used for global definitions");
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000150
Chris Lattner5e693ed2009-07-28 03:13:23 +0000151 Reloc::Model ReloModel = TM.getRelocationModel();
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000152
Chris Lattner5e693ed2009-07-28 03:13:23 +0000153 // Early exit - functions should be always in text sections.
Peter Collingbourne67335642016-10-24 19:23:39 +0000154 const auto *GVar = dyn_cast<GlobalVariable>(GO);
Craig Topper062a2ba2014-04-25 05:30:21 +0000155 if (!GVar)
Chris Lattnerf8d97102009-08-01 23:57:16 +0000156 return SectionKind::getText();
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000157
Chris Lattner5e693ed2009-07-28 03:13:23 +0000158 // Handle thread-local data first.
159 if (GVar->isThreadLocal()) {
Nick Lewycky50f02cb2011-12-02 22:16:29 +0000160 if (isSuitableForBSS(GVar, TM.Options.NoZerosInBSS))
Chris Lattnerf8d97102009-08-01 23:57:16 +0000161 return SectionKind::getThreadBSS();
162 return SectionKind::getThreadData();
Chris Lattner5e693ed2009-07-28 03:13:23 +0000163 }
164
Chris Lattner5b585f82010-01-19 02:48:26 +0000165 // Variables with common linkage always get classified as common.
166 if (GVar->hasCommonLinkage())
167 return SectionKind::getCommon();
168
Chris Lattner5e693ed2009-07-28 03:13:23 +0000169 // Variable can be easily put to BSS section.
Nick Lewycky50f02cb2011-12-02 22:16:29 +0000170 if (isSuitableForBSS(GVar, TM.Options.NoZerosInBSS)) {
Chris Lattnerb2534212010-01-19 04:15:51 +0000171 if (GVar->hasLocalLinkage())
172 return SectionKind::getBSSLocal();
173 else if (GVar->hasExternalLinkage())
174 return SectionKind::getBSSExtern();
Chris Lattnerf8d97102009-08-01 23:57:16 +0000175 return SectionKind::getBSS();
Chris Lattnerb2534212010-01-19 04:15:51 +0000176 }
Chris Lattner5e693ed2009-07-28 03:13:23 +0000177
Jay Foad60020682011-06-19 18:37:11 +0000178 const Constant *C = GVar->getInitializer();
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000179
Chris Lattner5e693ed2009-07-28 03:13:23 +0000180 // If the global is marked constant, we can put it into a mergable section,
181 // a mergable string section, or general .data if it contains relocations.
Chris Lattnerea4e9832011-01-18 01:23:44 +0000182 if (GVar->isConstant()) {
Chris Lattner5e693ed2009-07-28 03:13:23 +0000183 // If the initializer for the global contains something that requires a
Eric Christopherde9e92e2012-05-05 01:16:06 +0000184 // relocation, then we may have to drop this into a writable data section
Chris Lattner5e693ed2009-07-28 03:13:23 +0000185 // even though it is marked const.
Rafael Espindola65e49022015-11-17 00:51:23 +0000186 if (!C->needsRelocation()) {
Chris Lattnerea4e9832011-01-18 01:23:44 +0000187 // If the global is required to have a unique address, it can't be put
188 // into a mergable section: just drop it into the general read-only
189 // section instead.
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000190 if (!GVar->hasGlobalUnnamedAddr())
Chris Lattnerea4e9832011-01-18 01:23:44 +0000191 return SectionKind::getReadOnly();
Rafael Espindola65e49022015-11-17 00:51:23 +0000192
Chris Lattner5e693ed2009-07-28 03:13:23 +0000193 // If initializer is a null-terminated string, put it in a "cstring"
Chris Lattner81bbf442009-08-04 16:13:09 +0000194 // section of the right width.
Chris Lattner229907c2011-07-18 04:54:35 +0000195 if (ArrayType *ATy = dyn_cast<ArrayType>(C->getType())) {
196 if (IntegerType *ITy =
Chris Lattner81bbf442009-08-04 16:13:09 +0000197 dyn_cast<IntegerType>(ATy->getElementType())) {
198 if ((ITy->getBitWidth() == 8 || ITy->getBitWidth() == 16 ||
199 ITy->getBitWidth() == 32) &&
200 IsNullTerminatedString(C)) {
201 if (ITy->getBitWidth() == 8)
202 return SectionKind::getMergeable1ByteCString();
203 if (ITy->getBitWidth() == 16)
204 return SectionKind::getMergeable2ByteCString();
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000205
Chris Lattner81bbf442009-08-04 16:13:09 +0000206 assert(ITy->getBitWidth() == 32 && "Unknown width");
207 return SectionKind::getMergeable4ByteCString();
208 }
209 }
210 }
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000211
Chris Lattner5e693ed2009-07-28 03:13:23 +0000212 // Otherwise, just drop it into a mergable constant section. If we have
213 // a section for this size, use it, otherwise use the arbitrary sized
214 // mergable section.
Peter Collingbourne67335642016-10-24 19:23:39 +0000215 switch (
216 GVar->getParent()->getDataLayout().getTypeAllocSize(C->getType())) {
Chris Lattnerf8d97102009-08-01 23:57:16 +0000217 case 4: return SectionKind::getMergeableConst4();
218 case 8: return SectionKind::getMergeableConst8();
219 case 16: return SectionKind::getMergeableConst16();
David Majnemer964b70d2016-02-22 22:23:11 +0000220 case 32: return SectionKind::getMergeableConst32();
Rafael Espindola33804ca2015-01-29 14:12:41 +0000221 default:
222 return SectionKind::getReadOnly();
Chris Lattner5e693ed2009-07-28 03:13:23 +0000223 }
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000224
Rafael Espindola65e49022015-11-17 00:51:23 +0000225 } else {
Oliver Stannard8331aae2016-08-08 15:28:31 +0000226 // In static, ROPI and RWPI relocation models, the linker will resolve
227 // all addresses, so the relocation entries will actually be constants by
228 // the time the app starts up. However, we can't put this into a
229 // mergable section, because the linker doesn't take relocations into
230 // consideration when it tries to merge entries in the section.
231 if (ReloModel == Reloc::Static || ReloModel == Reloc::ROPI ||
232 ReloModel == Reloc::RWPI || ReloModel == Reloc::ROPI_RWPI)
Chris Lattnerf8d97102009-08-01 23:57:16 +0000233 return SectionKind::getReadOnly();
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000234
Chris Lattner5e693ed2009-07-28 03:13:23 +0000235 // Otherwise, the dynamic linker needs to fix it up, put it in the
236 // writable data.rel section.
Chris Lattnerf8d97102009-08-01 23:57:16 +0000237 return SectionKind::getReadOnlyWithRel();
Chris Lattner5e693ed2009-07-28 03:13:23 +0000238 }
239 }
240
Rafael Espindolaa686f122016-06-24 22:19:54 +0000241 // Okay, this isn't a constant.
Rafael Espindola449711c2015-11-18 06:02:15 +0000242 return SectionKind::getData();
Chris Lattner5e693ed2009-07-28 03:13:23 +0000243}
244
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000245/// This method computes the appropriate section to emit the specified global
246/// variable or function definition. This should not be passed external (or
247/// available externally) globals.
Eric Christopher4367c7f2016-09-16 07:33:15 +0000248MCSection *TargetLoweringObjectFile::SectionForGlobal(
Peter Collingbourne67335642016-10-24 19:23:39 +0000249 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
Chris Lattner5e693ed2009-07-28 03:13:23 +0000250 // Select section name.
Peter Collingbourne67335642016-10-24 19:23:39 +0000251 if (GO->hasSection())
252 return getExplicitSectionGlobal(GO, Kind, TM);
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000253
Javed Absarb16d1462017-06-05 10:09:13 +0000254 if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {
255 auto Attrs = GVar->getAttributes();
256 if ((Attrs.hasAttribute("bss-section") && Kind.isBSS()) ||
257 (Attrs.hasAttribute("data-section") && Kind.isData()) ||
258 (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly())) {
259 return getExplicitSectionGlobal(GO, Kind, TM);
260 }
261 }
262
263 if (auto *F = dyn_cast<Function>(GO)) {
264 if (F->hasFnAttribute("implicit-section-name"))
265 return getExplicitSectionGlobal(GO, Kind, TM);
266 }
267
Chris Lattner5e693ed2009-07-28 03:13:23 +0000268 // Use default section depending on the 'type' of global
Peter Collingbourne67335642016-10-24 19:23:39 +0000269 return SelectSectionForGlobal(GO, Kind, TM);
Chris Lattner5e693ed2009-07-28 03:13:23 +0000270}
271
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000272MCSection *TargetLoweringObjectFile::getSectionForJumpTable(
Eric Christopher4367c7f2016-09-16 07:33:15 +0000273 const Function &F, const TargetMachine &TM) const {
David Majnemera3ea4072016-02-21 01:30:30 +0000274 unsigned Align = 0;
Mehdi Amini5c0fa582015-07-16 06:04:17 +0000275 return getSectionForConstant(F.getParent()->getDataLayout(),
David Majnemera3ea4072016-02-21 01:30:30 +0000276 SectionKind::getReadOnly(), /*C=*/nullptr,
277 Align);
Rafael Espindola29786d42015-02-12 17:16:46 +0000278}
279
Rafael Espindoladf195192015-02-17 23:34:51 +0000280bool TargetLoweringObjectFile::shouldPutJumpTableInFunctionSection(
281 bool UsesLabelDifference, const Function &F) const {
282 // In PIC mode, we need to emit the jump table to the same section as the
283 // function body itself, otherwise the label differences won't make sense.
284 // FIXME: Need a better predicate for this: what about custom entries?
285 if (UsesLabelDifference)
286 return true;
287
288 // We should also do if the section name is NULL or function is declared
289 // in discardable section
290 // FIXME: this isn't the right predicate, should be based on the MCSection
291 // for the function.
Davide Italiano76de68e2017-01-14 20:09:29 +0000292 return F.isWeakForLinker();
Rafael Espindoladf195192015-02-17 23:34:51 +0000293}
294
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000295/// Given a mergable constant with the specified size and relocation
296/// information, return a section that it should be placed in.
Mehdi Amini5c0fa582015-07-16 06:04:17 +0000297MCSection *TargetLoweringObjectFile::getSectionForConstant(
David Majnemera3ea4072016-02-21 01:30:30 +0000298 const DataLayout &DL, SectionKind Kind, const Constant *C,
299 unsigned &Align) const {
Craig Topper062a2ba2014-04-25 05:30:21 +0000300 if (Kind.isReadOnly() && ReadOnlySection != nullptr)
Chris Lattner5e693ed2009-07-28 03:13:23 +0000301 return ReadOnlySection;
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000302
Chris Lattner5e693ed2009-07-28 03:13:23 +0000303 return DataSection;
304}
305
Anton Korobeynikove42af362012-11-14 01:47:00 +0000306/// getTTypeGlobalReference - Return an MCExpr to use for a
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +0000307/// reference to the specified global variable from exception
308/// handling information.
Rafael Espindola15b26692014-02-09 14:50:44 +0000309const MCExpr *TargetLoweringObjectFile::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +0000310 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
311 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
Anton Korobeynikove42af362012-11-14 01:47:00 +0000312 const MCSymbolRefExpr *Ref =
Tim Northoverb64fb452016-11-22 16:17:20 +0000313 MCSymbolRefExpr::create(TM.getSymbol(GV), getContext());
Anton Korobeynikove42af362012-11-14 01:47:00 +0000314
315 return getTTypeReference(Ref, Encoding, Streamer);
Chris Lattnerb8666022009-09-16 01:46:41 +0000316}
Chris Lattner5e693ed2009-07-28 03:13:23 +0000317
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +0000318const MCExpr *TargetLoweringObjectFile::
Anton Korobeynikove42af362012-11-14 01:47:00 +0000319getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
320 MCStreamer &Streamer) const {
Rafael Espindolaa01cdb02011-04-15 15:11:06 +0000321 switch (Encoding & 0x70) {
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +0000322 default:
Chris Lattner2104b8d2010-04-07 22:58:41 +0000323 report_fatal_error("We do not support this DWARF encoding yet!");
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +0000324 case dwarf::DW_EH_PE_absptr:
325 // Do nothing special
Anton Korobeynikove42af362012-11-14 01:47:00 +0000326 return Sym;
Chris Lattner03627cb2010-03-11 21:55:20 +0000327 case dwarf::DW_EH_PE_pcrel: {
328 // Emit a label to the streamer for the current position. This gives us
329 // .-foo addressing.
Jim Grosbach6f482002015-05-18 18:43:14 +0000330 MCSymbol *PCSym = getContext().createTempSymbol();
Chris Lattner03627cb2010-03-11 21:55:20 +0000331 Streamer.EmitLabel(PCSym);
Jim Grosbach13760bd2015-05-30 01:25:56 +0000332 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
333 return MCBinaryExpr::createSub(Sym, PC, getContext());
Chris Lattner03627cb2010-03-11 21:55:20 +0000334 }
335 }
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +0000336}
David Blaikief2694972013-06-28 20:05:11 +0000337
Ulrich Weigand2b6fc8d2013-07-02 18:47:09 +0000338const MCExpr *TargetLoweringObjectFile::getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
David Blaikief2694972013-06-28 20:05:11 +0000339 // FIXME: It's not clear what, if any, default this should have - perhaps a
340 // null return could mean 'no location' & we should just do that here.
Jim Grosbach13760bd2015-05-30 01:25:56 +0000341 return MCSymbolRefExpr::create(Sym, *Ctx);
David Blaikief2694972013-06-28 20:05:11 +0000342}
David Majnemer7db449a2015-03-17 23:54:51 +0000343
344void TargetLoweringObjectFile::getNameWithPrefix(
Eric Christopher4367c7f2016-09-16 07:33:15 +0000345 SmallVectorImpl<char> &OutName, const GlobalValue *GV,
Peter Collingbourne94d77862015-11-03 23:40:03 +0000346 const TargetMachine &TM) const {
Eric Christopher4367c7f2016-09-16 07:33:15 +0000347 Mang->getNameWithPrefix(OutName, GV, /*CannotUsePrivateLabel=*/false);
David Majnemer7db449a2015-03-17 23:54:51 +0000348}