blob: ee32d01572461edcf32587845e90a43dae9cfd58 [file] [log] [blame]
Chris Lattner5e693ed2009-07-28 03:13:23 +00001//===-- llvm/Target/TargetLoweringObjectFile.cpp - Object File Info -------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Chris Lattner5e693ed2009-07-28 03:13:23 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file implements classes used to handle lowerings specific to common
10// object file formats.
11//
12//===----------------------------------------------------------------------===//
13
David Blaikie6054e652018-03-23 23:58:19 +000014#include "llvm/Target/TargetLoweringObjectFile.h"
Zachary Turner264b5d92017-06-07 03:48:56 +000015#include "llvm/BinaryFormat/Dwarf.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000016#include "llvm/IR/Constants.h"
17#include "llvm/IR/DataLayout.h"
18#include "llvm/IR/DerivedTypes.h"
19#include "llvm/IR/Function.h"
20#include "llvm/IR/GlobalVariable.h"
Rafael Espindola894843c2014-01-07 21:19:40 +000021#include "llvm/IR/Mangler.h"
Chris Lattner4d2c0f92009-07-31 18:48:30 +000022#include "llvm/MC/MCContext.h"
Chris Lattnerb8666022009-09-16 01:46:41 +000023#include "llvm/MC/MCExpr.h"
Chris Lattner03627cb2010-03-11 21:55:20 +000024#include "llvm/MC/MCStreamer.h"
Chris Lattnerccbeed22010-01-13 21:29:21 +000025#include "llvm/MC/MCSymbol.h"
Chris Lattnerd82510e2009-11-07 09:20:54 +000026#include "llvm/Support/ErrorHandling.h"
Chris Lattnerccbeed22010-01-13 21:29:21 +000027#include "llvm/Support/raw_ostream.h"
Chandler Carruth442f7842014-03-04 10:07:28 +000028#include "llvm/Target/TargetMachine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000029#include "llvm/Target/TargetOptions.h"
Chris Lattner5e693ed2009-07-28 03:13:23 +000030using namespace llvm;
31
32//===----------------------------------------------------------------------===//
33// Generic Code
34//===----------------------------------------------------------------------===//
35
Evan Cheng76792992011-07-20 05:58:47 +000036/// Initialize - this method must be called before any actual lowering is
37/// done. This specifies the current context for codegen, and gives the
38/// lowering implementations a chance to set up their default sections.
39void TargetLoweringObjectFile::Initialize(MCContext &ctx,
40 const TargetMachine &TM) {
41 Ctx = &ctx;
Eric Liud07ad512016-09-16 11:50:57 +000042 // `Initialize` can be called more than once.
Gabor Horvath43b72d52017-05-01 16:18:42 +000043 delete Mang;
Eric Christopher4367c7f2016-09-16 07:33:15 +000044 Mang = new Mangler();
Rafael Espindola9f929952017-08-02 20:32:26 +000045 InitMCObjectFileInfo(TM.getTargetTriple(), TM.isPositionIndependent(), *Ctx,
46 TM.getCodeModel() == CodeModel::Large);
Reid Klecknerfce7f732018-08-09 22:24:04 +000047
48 // Reset various EH DWARF encodings.
49 PersonalityEncoding = LSDAEncoding = TTypeEncoding = dwarf::DW_EH_PE_absptr;
Chris Lattner5e693ed2009-07-28 03:13:23 +000050}
Saleem Abdulrasool0d3d6c42014-04-16 04:15:25 +000051
Chris Lattner5e693ed2009-07-28 03:13:23 +000052TargetLoweringObjectFile::~TargetLoweringObjectFile() {
Eric Christopher4367c7f2016-09-16 07:33:15 +000053 delete Mang;
Chris Lattner5e693ed2009-07-28 03:13:23 +000054}
55
Eli Friedmancd07a3e2018-02-06 23:22:14 +000056static bool isNullOrUndef(const Constant *C) {
57 // Check that the constant isn't all zeros or undefs.
58 if (C->isNullValue() || isa<UndefValue>(C))
59 return true;
60 if (!isa<ConstantAggregate>(C))
61 return false;
62 for (auto Operand : C->operand_values()) {
63 if (!isNullOrUndef(cast<Constant>(Operand)))
64 return false;
65 }
66 return true;
67}
68
Eric Christopher958a1f82018-05-27 11:39:34 +000069static bool isSuitableForBSS(const GlobalVariable *GV) {
Jay Foad60020682011-06-19 18:37:11 +000070 const Constant *C = GV->getInitializer();
Anton Korobeynikov1df58862009-09-09 08:41:20 +000071
Chris Lattner5e693ed2009-07-28 03:13:23 +000072 // Must have zero initializer.
Eli Friedmancd07a3e2018-02-06 23:22:14 +000073 if (!isNullOrUndef(C))
Chris Lattner5e693ed2009-07-28 03:13:23 +000074 return false;
Anton Korobeynikov1df58862009-09-09 08:41:20 +000075
Chris Lattner5e693ed2009-07-28 03:13:23 +000076 // Leave constant zeros in readonly constant sections, so they can be shared.
77 if (GV->isConstant())
78 return false;
Anton Korobeynikov1df58862009-09-09 08:41:20 +000079
Chris Lattner5e693ed2009-07-28 03:13:23 +000080 // If the global has an explicit section specified, don't put it in BSS.
David Majnemer483e4e02014-05-17 05:18:40 +000081 if (GV->hasSection())
Chris Lattner5e693ed2009-07-28 03:13:23 +000082 return false;
Anton Korobeynikov1df58862009-09-09 08:41:20 +000083
Chris Lattner5e693ed2009-07-28 03:13:23 +000084 // Otherwise, put it in BSS!
85 return true;
86}
87
Chris Lattner81bbf442009-08-04 16:13:09 +000088/// IsNullTerminatedString - Return true if the specified constant (which is
89/// 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 +000090/// nul value and contains no other nuls in it. Note that this is more general
91/// than ConstantDataSequential::isString because we allow 2 & 4 byte strings.
Chris Lattner81bbf442009-08-04 16:13:09 +000092static bool IsNullTerminatedString(const Constant *C) {
Chris Lattner139822f2012-01-24 14:17:05 +000093 // First check: is we have constant array terminated with zero
Chris Lattner139822f2012-01-24 14:17:05 +000094 if (const ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(C)) {
95 unsigned NumElts = CDS->getNumElements();
96 assert(NumElts != 0 && "Can't have an empty CDS");
Fangrui Songf78650a2018-07-30 19:41:25 +000097
Chris Lattner139822f2012-01-24 14:17:05 +000098 if (CDS->getElementAsInteger(NumElts-1) != 0)
99 return false; // Not null terminated.
Fangrui Songf78650a2018-07-30 19:41:25 +0000100
Chris Lattner139822f2012-01-24 14:17:05 +0000101 // Verify that the null doesn't occur anywhere else in the string.
102 for (unsigned i = 0; i != NumElts-1; ++i)
103 if (CDS->getElementAsInteger(i) == 0)
104 return false;
105 return true;
106 }
Chris Lattner5e693ed2009-07-28 03:13:23 +0000107
108 // Another possibility: [1 x i8] zeroinitializer
109 if (isa<ConstantAggregateZero>(C))
Chris Lattner139822f2012-01-24 14:17:05 +0000110 return cast<ArrayType>(C->getType())->getNumElements() == 1;
Chris Lattner5e693ed2009-07-28 03:13:23 +0000111
112 return false;
113}
114
Rafael Espindolaf4e6b292013-12-02 16:25:47 +0000115MCSymbol *TargetLoweringObjectFile::getSymbolWithGlobalValueBase(
Eric Christopher4367c7f2016-09-16 07:33:15 +0000116 const GlobalValue *GV, StringRef Suffix, const TargetMachine &TM) const {
Rafael Espindola117b20c2013-12-05 05:53:12 +0000117 assert(!Suffix.empty());
Rafael Espindola117b20c2013-12-05 05:53:12 +0000118
Rafael Espindolaf4e6b292013-12-02 16:25:47 +0000119 SmallString<60> NameStr;
Mehdi Amini5c0fa582015-07-16 06:04:17 +0000120 NameStr += GV->getParent()->getDataLayout().getPrivateGlobalPrefix();
Eric Christopher4367c7f2016-09-16 07:33:15 +0000121 TM.getNameWithPrefix(NameStr, GV, *Mang);
Rafael Espindolaf4e6b292013-12-02 16:25:47 +0000122 NameStr.append(Suffix.begin(), Suffix.end());
Jim Grosbach6f482002015-05-18 18:43:14 +0000123 return Ctx->getOrCreateSymbol(NameStr);
Rafael Espindolaf4e6b292013-12-02 16:25:47 +0000124}
Rafael Espindolae133ed82013-10-29 17:28:26 +0000125
Rafael Espindoladaeafb42014-02-19 17:23:20 +0000126MCSymbol *TargetLoweringObjectFile::getCFIPersonalitySymbol(
Eric Christopher4367c7f2016-09-16 07:33:15 +0000127 const GlobalValue *GV, const TargetMachine &TM,
Rafael Espindoladaeafb42014-02-19 17:23:20 +0000128 MachineModuleInfo *MMI) const {
Tim Northoverb64fb452016-11-22 16:17:20 +0000129 return TM.getSymbol(GV);
Rafael Espindolaa83b1772011-04-16 03:51:21 +0000130}
131
132void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
Mehdi Amini5c0fa582015-07-16 06:04:17 +0000133 const DataLayout &,
Rafael Espindolaa83b1772011-04-16 03:51:21 +0000134 const MCSymbol *Sym) const {
Rafael Espindolaa83b1772011-04-16 03:51:21 +0000135}
136
137
Chris Lattnercbc7b262009-08-05 04:25:40 +0000138/// getKindForGlobal - This is a top-level target-independent classifier for
Eric Christophered169ec2018-05-27 11:23:20 +0000139/// a global object. Given a global variable and information from the TM, this
140/// function classifies the global in a target independent manner. This function
141/// may be overridden by the target implementation.
Peter Collingbourne67335642016-10-24 19:23:39 +0000142SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalObject *GO,
Chris Lattnercbc7b262009-08-05 04:25:40 +0000143 const TargetMachine &TM){
Peter Collingbourne67335642016-10-24 19:23:39 +0000144 assert(!GO->isDeclaration() && !GO->hasAvailableExternallyLinkage() &&
Chris Lattnercbc7b262009-08-05 04:25:40 +0000145 "Can only be used for global definitions");
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000146
Eric Christophered169ec2018-05-27 11:23:20 +0000147 // Functions are classified as text sections.
148 if (isa<Function>(GO))
Chris Lattnerf8d97102009-08-01 23:57:16 +0000149 return SectionKind::getText();
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000150
Eric Christophered169ec2018-05-27 11:23:20 +0000151 // Global variables require more detailed analysis.
152 const auto *GVar = cast<GlobalVariable>(GO);
153
Chris Lattner5e693ed2009-07-28 03:13:23 +0000154 // Handle thread-local data first.
155 if (GVar->isThreadLocal()) {
Eric Christopher958a1f82018-05-27 11:39:34 +0000156 if (isSuitableForBSS(GVar) && !TM.Options.NoZerosInBSS)
Chris Lattnerf8d97102009-08-01 23:57:16 +0000157 return SectionKind::getThreadBSS();
158 return SectionKind::getThreadData();
Chris Lattner5e693ed2009-07-28 03:13:23 +0000159 }
160
Chris Lattner5b585f82010-01-19 02:48:26 +0000161 // Variables with common linkage always get classified as common.
162 if (GVar->hasCommonLinkage())
163 return SectionKind::getCommon();
164
Eric Christopher958a1f82018-05-27 11:39:34 +0000165 // Most non-mergeable zero data can be put in the BSS section unless otherwise
166 // specified.
167 if (isSuitableForBSS(GVar) && !TM.Options.NoZerosInBSS) {
Chris Lattnerb2534212010-01-19 04:15:51 +0000168 if (GVar->hasLocalLinkage())
169 return SectionKind::getBSSLocal();
170 else if (GVar->hasExternalLinkage())
171 return SectionKind::getBSSExtern();
Chris Lattnerf8d97102009-08-01 23:57:16 +0000172 return SectionKind::getBSS();
Chris Lattnerb2534212010-01-19 04:15:51 +0000173 }
Chris Lattner5e693ed2009-07-28 03:13:23 +0000174
Chris Lattner5e693ed2009-07-28 03:13:23 +0000175 // If the global is marked constant, we can put it into a mergable section,
176 // a mergable string section, or general .data if it contains relocations.
Chris Lattnerea4e9832011-01-18 01:23:44 +0000177 if (GVar->isConstant()) {
Chris Lattner5e693ed2009-07-28 03:13:23 +0000178 // If the initializer for the global contains something that requires a
Eric Christopherde9e92e2012-05-05 01:16:06 +0000179 // relocation, then we may have to drop this into a writable data section
Chris Lattner5e693ed2009-07-28 03:13:23 +0000180 // even though it is marked const.
Eric Christophered169ec2018-05-27 11:23:20 +0000181 const Constant *C = GVar->getInitializer();
Rafael Espindola65e49022015-11-17 00:51:23 +0000182 if (!C->needsRelocation()) {
Chris Lattnerea4e9832011-01-18 01:23:44 +0000183 // If the global is required to have a unique address, it can't be put
184 // into a mergable section: just drop it into the general read-only
185 // section instead.
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000186 if (!GVar->hasGlobalUnnamedAddr())
Chris Lattnerea4e9832011-01-18 01:23:44 +0000187 return SectionKind::getReadOnly();
Rafael Espindola65e49022015-11-17 00:51:23 +0000188
Chris Lattner5e693ed2009-07-28 03:13:23 +0000189 // If initializer is a null-terminated string, put it in a "cstring"
Chris Lattner81bbf442009-08-04 16:13:09 +0000190 // section of the right width.
Chris Lattner229907c2011-07-18 04:54:35 +0000191 if (ArrayType *ATy = dyn_cast<ArrayType>(C->getType())) {
192 if (IntegerType *ITy =
Chris Lattner81bbf442009-08-04 16:13:09 +0000193 dyn_cast<IntegerType>(ATy->getElementType())) {
194 if ((ITy->getBitWidth() == 8 || ITy->getBitWidth() == 16 ||
195 ITy->getBitWidth() == 32) &&
196 IsNullTerminatedString(C)) {
197 if (ITy->getBitWidth() == 8)
198 return SectionKind::getMergeable1ByteCString();
199 if (ITy->getBitWidth() == 16)
200 return SectionKind::getMergeable2ByteCString();
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000201
Chris Lattner81bbf442009-08-04 16:13:09 +0000202 assert(ITy->getBitWidth() == 32 && "Unknown width");
203 return SectionKind::getMergeable4ByteCString();
204 }
205 }
206 }
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000207
Chris Lattner5e693ed2009-07-28 03:13:23 +0000208 // Otherwise, just drop it into a mergable constant section. If we have
209 // a section for this size, use it, otherwise use the arbitrary sized
210 // mergable section.
Peter Collingbourne67335642016-10-24 19:23:39 +0000211 switch (
212 GVar->getParent()->getDataLayout().getTypeAllocSize(C->getType())) {
Chris Lattnerf8d97102009-08-01 23:57:16 +0000213 case 4: return SectionKind::getMergeableConst4();
214 case 8: return SectionKind::getMergeableConst8();
215 case 16: return SectionKind::getMergeableConst16();
David Majnemer964b70d2016-02-22 22:23:11 +0000216 case 32: return SectionKind::getMergeableConst32();
Rafael Espindola33804ca2015-01-29 14:12:41 +0000217 default:
218 return SectionKind::getReadOnly();
Chris Lattner5e693ed2009-07-28 03:13:23 +0000219 }
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000220
Rafael Espindola65e49022015-11-17 00:51:23 +0000221 } else {
Oliver Stannard8331aae2016-08-08 15:28:31 +0000222 // In static, ROPI and RWPI relocation models, the linker will resolve
223 // all addresses, so the relocation entries will actually be constants by
224 // the time the app starts up. However, we can't put this into a
225 // mergable section, because the linker doesn't take relocations into
226 // consideration when it tries to merge entries in the section.
Eric Christophered169ec2018-05-27 11:23:20 +0000227 Reloc::Model ReloModel = TM.getRelocationModel();
Oliver Stannard8331aae2016-08-08 15:28:31 +0000228 if (ReloModel == Reloc::Static || ReloModel == Reloc::ROPI ||
229 ReloModel == Reloc::RWPI || ReloModel == Reloc::ROPI_RWPI)
Chris Lattnerf8d97102009-08-01 23:57:16 +0000230 return SectionKind::getReadOnly();
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000231
Chris Lattner5e693ed2009-07-28 03:13:23 +0000232 // Otherwise, the dynamic linker needs to fix it up, put it in the
233 // writable data.rel section.
Chris Lattnerf8d97102009-08-01 23:57:16 +0000234 return SectionKind::getReadOnlyWithRel();
Chris Lattner5e693ed2009-07-28 03:13:23 +0000235 }
236 }
237
Rafael Espindolaa686f122016-06-24 22:19:54 +0000238 // Okay, this isn't a constant.
Rafael Espindola449711c2015-11-18 06:02:15 +0000239 return SectionKind::getData();
Chris Lattner5e693ed2009-07-28 03:13:23 +0000240}
241
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000242/// This method computes the appropriate section to emit the specified global
243/// variable or function definition. This should not be passed external (or
244/// available externally) globals.
Eric Christopher4367c7f2016-09-16 07:33:15 +0000245MCSection *TargetLoweringObjectFile::SectionForGlobal(
Peter Collingbourne67335642016-10-24 19:23:39 +0000246 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
Chris Lattner5e693ed2009-07-28 03:13:23 +0000247 // Select section name.
Peter Collingbourne67335642016-10-24 19:23:39 +0000248 if (GO->hasSection())
249 return getExplicitSectionGlobal(GO, Kind, TM);
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000250
Javed Absarb16d1462017-06-05 10:09:13 +0000251 if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {
252 auto Attrs = GVar->getAttributes();
253 if ((Attrs.hasAttribute("bss-section") && Kind.isBSS()) ||
254 (Attrs.hasAttribute("data-section") && Kind.isData()) ||
255 (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly())) {
256 return getExplicitSectionGlobal(GO, Kind, TM);
257 }
258 }
259
260 if (auto *F = dyn_cast<Function>(GO)) {
261 if (F->hasFnAttribute("implicit-section-name"))
262 return getExplicitSectionGlobal(GO, Kind, TM);
263 }
264
Chris Lattner5e693ed2009-07-28 03:13:23 +0000265 // Use default section depending on the 'type' of global
Peter Collingbourne67335642016-10-24 19:23:39 +0000266 return SelectSectionForGlobal(GO, Kind, TM);
Chris Lattner5e693ed2009-07-28 03:13:23 +0000267}
268
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000269MCSection *TargetLoweringObjectFile::getSectionForJumpTable(
Eric Christopher4367c7f2016-09-16 07:33:15 +0000270 const Function &F, const TargetMachine &TM) const {
David Majnemera3ea4072016-02-21 01:30:30 +0000271 unsigned Align = 0;
Mehdi Amini5c0fa582015-07-16 06:04:17 +0000272 return getSectionForConstant(F.getParent()->getDataLayout(),
David Majnemera3ea4072016-02-21 01:30:30 +0000273 SectionKind::getReadOnly(), /*C=*/nullptr,
274 Align);
Rafael Espindola29786d42015-02-12 17:16:46 +0000275}
276
Rafael Espindoladf195192015-02-17 23:34:51 +0000277bool TargetLoweringObjectFile::shouldPutJumpTableInFunctionSection(
278 bool UsesLabelDifference, const Function &F) const {
279 // In PIC mode, we need to emit the jump table to the same section as the
280 // function body itself, otherwise the label differences won't make sense.
281 // FIXME: Need a better predicate for this: what about custom entries?
282 if (UsesLabelDifference)
283 return true;
284
285 // We should also do if the section name is NULL or function is declared
286 // in discardable section
287 // FIXME: this isn't the right predicate, should be based on the MCSection
288 // for the function.
Davide Italiano76de68e2017-01-14 20:09:29 +0000289 return F.isWeakForLinker();
Rafael Espindoladf195192015-02-17 23:34:51 +0000290}
291
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000292/// Given a mergable constant with the specified size and relocation
293/// information, return a section that it should be placed in.
Mehdi Amini5c0fa582015-07-16 06:04:17 +0000294MCSection *TargetLoweringObjectFile::getSectionForConstant(
David Majnemera3ea4072016-02-21 01:30:30 +0000295 const DataLayout &DL, SectionKind Kind, const Constant *C,
296 unsigned &Align) const {
Craig Topper062a2ba2014-04-25 05:30:21 +0000297 if (Kind.isReadOnly() && ReadOnlySection != nullptr)
Chris Lattner5e693ed2009-07-28 03:13:23 +0000298 return ReadOnlySection;
Anton Korobeynikov1df58862009-09-09 08:41:20 +0000299
Chris Lattner5e693ed2009-07-28 03:13:23 +0000300 return DataSection;
301}
302
Anton Korobeynikove42af362012-11-14 01:47:00 +0000303/// getTTypeGlobalReference - Return an MCExpr to use for a
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +0000304/// reference to the specified global variable from exception
305/// handling information.
Rafael Espindola15b26692014-02-09 14:50:44 +0000306const MCExpr *TargetLoweringObjectFile::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +0000307 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
308 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
Anton Korobeynikove42af362012-11-14 01:47:00 +0000309 const MCSymbolRefExpr *Ref =
Tim Northoverb64fb452016-11-22 16:17:20 +0000310 MCSymbolRefExpr::create(TM.getSymbol(GV), getContext());
Anton Korobeynikove42af362012-11-14 01:47:00 +0000311
312 return getTTypeReference(Ref, Encoding, Streamer);
Chris Lattnerb8666022009-09-16 01:46:41 +0000313}
Chris Lattner5e693ed2009-07-28 03:13:23 +0000314
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +0000315const MCExpr *TargetLoweringObjectFile::
Anton Korobeynikove42af362012-11-14 01:47:00 +0000316getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
317 MCStreamer &Streamer) const {
Rafael Espindolaa01cdb02011-04-15 15:11:06 +0000318 switch (Encoding & 0x70) {
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +0000319 default:
Chris Lattner2104b8d2010-04-07 22:58:41 +0000320 report_fatal_error("We do not support this DWARF encoding yet!");
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +0000321 case dwarf::DW_EH_PE_absptr:
322 // Do nothing special
Anton Korobeynikove42af362012-11-14 01:47:00 +0000323 return Sym;
Chris Lattner03627cb2010-03-11 21:55:20 +0000324 case dwarf::DW_EH_PE_pcrel: {
325 // Emit a label to the streamer for the current position. This gives us
326 // .-foo addressing.
Jim Grosbach6f482002015-05-18 18:43:14 +0000327 MCSymbol *PCSym = getContext().createTempSymbol();
Chris Lattner03627cb2010-03-11 21:55:20 +0000328 Streamer.EmitLabel(PCSym);
Jim Grosbach13760bd2015-05-30 01:25:56 +0000329 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
330 return MCBinaryExpr::createSub(Sym, PC, getContext());
Chris Lattner03627cb2010-03-11 21:55:20 +0000331 }
332 }
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +0000333}
David Blaikief2694972013-06-28 20:05:11 +0000334
Ulrich Weigand2b6fc8d2013-07-02 18:47:09 +0000335const MCExpr *TargetLoweringObjectFile::getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
David Blaikief2694972013-06-28 20:05:11 +0000336 // FIXME: It's not clear what, if any, default this should have - perhaps a
337 // null return could mean 'no location' & we should just do that here.
Jim Grosbach13760bd2015-05-30 01:25:56 +0000338 return MCSymbolRefExpr::create(Sym, *Ctx);
David Blaikief2694972013-06-28 20:05:11 +0000339}
David Majnemer7db449a2015-03-17 23:54:51 +0000340
341void TargetLoweringObjectFile::getNameWithPrefix(
Eric Christopher4367c7f2016-09-16 07:33:15 +0000342 SmallVectorImpl<char> &OutName, const GlobalValue *GV,
Peter Collingbourne94d77862015-11-03 23:40:03 +0000343 const TargetMachine &TM) const {
Eric Christopher4367c7f2016-09-16 07:33:15 +0000344 Mang->getNameWithPrefix(OutName, GV, /*CannotUsePrivateLabel=*/false);
David Majnemer7db449a2015-03-17 23:54:51 +0000345}