blob: bb937923b47ead28e467ed013529688233ec3ab6 [file] [log] [blame]
Chris Lattnerf0144122009-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 Blaikiefe42bd52018-03-23 23:58:19 +000015#include "llvm/Target/TargetLoweringObjectFile.h"
Zachary Turner19ca2b02017-06-07 03:48:56 +000016#include "llvm/BinaryFormat/Dwarf.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000017#include "llvm/IR/Constants.h"
18#include "llvm/IR/DataLayout.h"
19#include "llvm/IR/DerivedTypes.h"
20#include "llvm/IR/Function.h"
21#include "llvm/IR/GlobalVariable.h"
Rafael Espindolab56c57b2014-01-07 21:19:40 +000022#include "llvm/IR/Mangler.h"
Chris Lattnera87dea42009-07-31 18:48:30 +000023#include "llvm/MC/MCContext.h"
Chris Lattner8c6ed052009-09-16 01:46:41 +000024#include "llvm/MC/MCExpr.h"
Chris Lattner42263e22010-03-11 21:55:20 +000025#include "llvm/MC/MCStreamer.h"
Chris Lattner8da8d4b2010-01-13 21:29:21 +000026#include "llvm/MC/MCSymbol.h"
Chris Lattner8f9b0f62009-11-07 09:20:54 +000027#include "llvm/Support/ErrorHandling.h"
Chris Lattner8da8d4b2010-01-13 21:29:21 +000028#include "llvm/Support/raw_ostream.h"
Chandler Carruth1decd562014-03-04 10:07:28 +000029#include "llvm/Target/TargetMachine.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000030#include "llvm/Target/TargetOptions.h"
Chris Lattnerf0144122009-07-28 03:13:23 +000031using namespace llvm;
32
33//===----------------------------------------------------------------------===//
34// Generic Code
35//===----------------------------------------------------------------------===//
36
Evan Chenge76a33b2011-07-20 05:58:47 +000037/// Initialize - this method must be called before any actual lowering is
38/// done. This specifies the current context for codegen, and gives the
39/// lowering implementations a chance to set up their default sections.
40void TargetLoweringObjectFile::Initialize(MCContext &ctx,
41 const TargetMachine &TM) {
42 Ctx = &ctx;
Eric Liu6c1574b2016-09-16 11:50:57 +000043 // `Initialize` can be called more than once.
Gabor Horvath4d5ff6d2017-05-01 16:18:42 +000044 delete Mang;
Eric Christopher88a23b62016-09-16 07:33:15 +000045 Mang = new Mangler();
Rafael Espindola2600a672017-08-02 20:32:26 +000046 InitMCObjectFileInfo(TM.getTargetTriple(), TM.isPositionIndependent(), *Ctx,
47 TM.getCodeModel() == CodeModel::Large);
Reid Kleckner3b9733f2018-08-09 22:24:04 +000048
49 // Reset various EH DWARF encodings.
50 PersonalityEncoding = LSDAEncoding = TTypeEncoding = dwarf::DW_EH_PE_absptr;
Chris Lattnerf0144122009-07-28 03:13:23 +000051}
Saleem Abdulrasooleb0eb5d2014-04-16 04:15:25 +000052
Chris Lattnerf0144122009-07-28 03:13:23 +000053TargetLoweringObjectFile::~TargetLoweringObjectFile() {
Eric Christopher88a23b62016-09-16 07:33:15 +000054 delete Mang;
Chris Lattnerf0144122009-07-28 03:13:23 +000055}
56
Eli Friedmana5bd5432018-02-06 23:22:14 +000057static bool isNullOrUndef(const Constant *C) {
58 // Check that the constant isn't all zeros or undefs.
59 if (C->isNullValue() || isa<UndefValue>(C))
60 return true;
61 if (!isa<ConstantAggregate>(C))
62 return false;
63 for (auto Operand : C->operand_values()) {
64 if (!isNullOrUndef(cast<Constant>(Operand)))
65 return false;
66 }
67 return true;
68}
69
Eric Christopher717390c2018-05-27 11:39:34 +000070static bool isSuitableForBSS(const GlobalVariable *GV) {
Jay Foad7d715df2011-06-19 18:37:11 +000071 const Constant *C = GV->getInitializer();
Anton Korobeynikov8ddb5692009-09-09 08:41:20 +000072
Chris Lattnerf0144122009-07-28 03:13:23 +000073 // Must have zero initializer.
Eli Friedmana5bd5432018-02-06 23:22:14 +000074 if (!isNullOrUndef(C))
Chris Lattnerf0144122009-07-28 03:13:23 +000075 return false;
Anton Korobeynikov8ddb5692009-09-09 08:41:20 +000076
Chris Lattnerf0144122009-07-28 03:13:23 +000077 // Leave constant zeros in readonly constant sections, so they can be shared.
78 if (GV->isConstant())
79 return false;
Anton Korobeynikov8ddb5692009-09-09 08:41:20 +000080
Chris Lattnerf0144122009-07-28 03:13:23 +000081 // If the global has an explicit section specified, don't put it in BSS.
David Majnemer575fc082014-05-17 05:18:40 +000082 if (GV->hasSection())
Chris Lattnerf0144122009-07-28 03:13:23 +000083 return false;
Anton Korobeynikov8ddb5692009-09-09 08:41:20 +000084
Chris Lattnerf0144122009-07-28 03:13:23 +000085 // Otherwise, put it in BSS!
86 return true;
87}
88
Chris Lattner1850e5a2009-08-04 16:13:09 +000089/// IsNullTerminatedString - Return true if the specified constant (which is
90/// known to have a type that is an array of 1/2/4 byte elements) ends with a
Chris Lattner29cc6cb2012-01-24 14:17:05 +000091/// nul value and contains no other nuls in it. Note that this is more general
92/// than ConstantDataSequential::isString because we allow 2 & 4 byte strings.
Chris Lattner1850e5a2009-08-04 16:13:09 +000093static bool IsNullTerminatedString(const Constant *C) {
Chris Lattner29cc6cb2012-01-24 14:17:05 +000094 // First check: is we have constant array terminated with zero
Chris Lattner29cc6cb2012-01-24 14:17:05 +000095 if (const ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(C)) {
96 unsigned NumElts = CDS->getNumElements();
97 assert(NumElts != 0 && "Can't have an empty CDS");
Fangrui Songaf7b1832018-07-30 19:41:25 +000098
Chris Lattner29cc6cb2012-01-24 14:17:05 +000099 if (CDS->getElementAsInteger(NumElts-1) != 0)
100 return false; // Not null terminated.
Fangrui Songaf7b1832018-07-30 19:41:25 +0000101
Chris Lattner29cc6cb2012-01-24 14:17:05 +0000102 // Verify that the null doesn't occur anywhere else in the string.
103 for (unsigned i = 0; i != NumElts-1; ++i)
104 if (CDS->getElementAsInteger(i) == 0)
105 return false;
106 return true;
107 }
Chris Lattnerf0144122009-07-28 03:13:23 +0000108
109 // Another possibility: [1 x i8] zeroinitializer
110 if (isa<ConstantAggregateZero>(C))
Chris Lattner29cc6cb2012-01-24 14:17:05 +0000111 return cast<ArrayType>(C->getType())->getNumElements() == 1;
Chris Lattnerf0144122009-07-28 03:13:23 +0000112
113 return false;
114}
115
Rafael Espindolacce58732013-12-02 16:25:47 +0000116MCSymbol *TargetLoweringObjectFile::getSymbolWithGlobalValueBase(
Eric Christopher88a23b62016-09-16 07:33:15 +0000117 const GlobalValue *GV, StringRef Suffix, const TargetMachine &TM) const {
Rafael Espindolafac7a9e2013-12-05 05:53:12 +0000118 assert(!Suffix.empty());
Rafael Espindolafac7a9e2013-12-05 05:53:12 +0000119
Rafael Espindolacce58732013-12-02 16:25:47 +0000120 SmallString<60> NameStr;
Mehdi Aminia5574d62015-07-16 06:04:17 +0000121 NameStr += GV->getParent()->getDataLayout().getPrivateGlobalPrefix();
Eric Christopher88a23b62016-09-16 07:33:15 +0000122 TM.getNameWithPrefix(NameStr, GV, *Mang);
Rafael Espindolacce58732013-12-02 16:25:47 +0000123 NameStr.append(Suffix.begin(), Suffix.end());
Jim Grosbach19696da2015-05-18 18:43:14 +0000124 return Ctx->getOrCreateSymbol(NameStr);
Rafael Espindolacce58732013-12-02 16:25:47 +0000125}
Rafael Espindola93cf0932013-10-29 17:28:26 +0000126
Rafael Espindola737c9f62014-02-19 17:23:20 +0000127MCSymbol *TargetLoweringObjectFile::getCFIPersonalitySymbol(
Eric Christopher88a23b62016-09-16 07:33:15 +0000128 const GlobalValue *GV, const TargetMachine &TM,
Rafael Espindola737c9f62014-02-19 17:23:20 +0000129 MachineModuleInfo *MMI) const {
Tim Northoverbc347f22016-11-22 16:17:20 +0000130 return TM.getSymbol(GV);
Rafael Espindola30deafc2011-04-16 03:51:21 +0000131}
132
133void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
Mehdi Aminia5574d62015-07-16 06:04:17 +0000134 const DataLayout &,
Rafael Espindola30deafc2011-04-16 03:51:21 +0000135 const MCSymbol *Sym) const {
Rafael Espindola30deafc2011-04-16 03:51:21 +0000136}
137
138
Chris Lattner58bed8f2009-08-05 04:25:40 +0000139/// getKindForGlobal - This is a top-level target-independent classifier for
Eric Christopher9532fa42018-05-27 11:23:20 +0000140/// a global object. Given a global variable and information from the TM, this
141/// function classifies the global in a target independent manner. This function
142/// may be overridden by the target implementation.
Peter Collingbourne80e2a2f2016-10-24 19:23:39 +0000143SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalObject *GO,
Chris Lattner58bed8f2009-08-05 04:25:40 +0000144 const TargetMachine &TM){
Peter Collingbourne80e2a2f2016-10-24 19:23:39 +0000145 assert(!GO->isDeclaration() && !GO->hasAvailableExternallyLinkage() &&
Chris Lattner58bed8f2009-08-05 04:25:40 +0000146 "Can only be used for global definitions");
Anton Korobeynikov8ddb5692009-09-09 08:41:20 +0000147
Eric Christopher9532fa42018-05-27 11:23:20 +0000148 // Functions are classified as text sections.
149 if (isa<Function>(GO))
Chris Lattner27981192009-08-01 23:57:16 +0000150 return SectionKind::getText();
Anton Korobeynikov8ddb5692009-09-09 08:41:20 +0000151
Eric Christopher9532fa42018-05-27 11:23:20 +0000152 // Global variables require more detailed analysis.
153 const auto *GVar = cast<GlobalVariable>(GO);
154
Chris Lattnerf0144122009-07-28 03:13:23 +0000155 // Handle thread-local data first.
156 if (GVar->isThreadLocal()) {
Eric Christopher717390c2018-05-27 11:39:34 +0000157 if (isSuitableForBSS(GVar) && !TM.Options.NoZerosInBSS)
Chris Lattner27981192009-08-01 23:57:16 +0000158 return SectionKind::getThreadBSS();
159 return SectionKind::getThreadData();
Chris Lattnerf0144122009-07-28 03:13:23 +0000160 }
161
Chris Lattnera3839bc2010-01-19 02:48:26 +0000162 // Variables with common linkage always get classified as common.
163 if (GVar->hasCommonLinkage())
164 return SectionKind::getCommon();
165
Eric Christopher717390c2018-05-27 11:39:34 +0000166 // Most non-mergeable zero data can be put in the BSS section unless otherwise
167 // specified.
168 if (isSuitableForBSS(GVar) && !TM.Options.NoZerosInBSS) {
Chris Lattnerce8749e2010-01-19 04:15:51 +0000169 if (GVar->hasLocalLinkage())
170 return SectionKind::getBSSLocal();
171 else if (GVar->hasExternalLinkage())
172 return SectionKind::getBSSExtern();
Chris Lattner27981192009-08-01 23:57:16 +0000173 return SectionKind::getBSS();
Chris Lattnerce8749e2010-01-19 04:15:51 +0000174 }
Chris Lattnerf0144122009-07-28 03:13:23 +0000175
Chris Lattnerf0144122009-07-28 03:13:23 +0000176 // If the global is marked constant, we can put it into a mergable section,
177 // a mergable string section, or general .data if it contains relocations.
Chris Lattner32899192011-01-18 01:23:44 +0000178 if (GVar->isConstant()) {
Chris Lattnerf0144122009-07-28 03:13:23 +0000179 // If the initializer for the global contains something that requires a
Eric Christopherf2eed382012-05-05 01:16:06 +0000180 // relocation, then we may have to drop this into a writable data section
Chris Lattnerf0144122009-07-28 03:13:23 +0000181 // even though it is marked const.
Eric Christopher9532fa42018-05-27 11:23:20 +0000182 const Constant *C = GVar->getInitializer();
Rafael Espindola8dcaa9f2015-11-17 00:51:23 +0000183 if (!C->needsRelocation()) {
Chris Lattner32899192011-01-18 01:23:44 +0000184 // If the global is required to have a unique address, it can't be put
185 // into a mergable section: just drop it into the general read-only
186 // section instead.
Peter Collingbourne63b34cd2016-06-14 21:01:22 +0000187 if (!GVar->hasGlobalUnnamedAddr())
Chris Lattner32899192011-01-18 01:23:44 +0000188 return SectionKind::getReadOnly();
Rafael Espindola8dcaa9f2015-11-17 00:51:23 +0000189
Chris Lattnerf0144122009-07-28 03:13:23 +0000190 // If initializer is a null-terminated string, put it in a "cstring"
Chris Lattner1850e5a2009-08-04 16:13:09 +0000191 // section of the right width.
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000192 if (ArrayType *ATy = dyn_cast<ArrayType>(C->getType())) {
193 if (IntegerType *ITy =
Chris Lattner1850e5a2009-08-04 16:13:09 +0000194 dyn_cast<IntegerType>(ATy->getElementType())) {
195 if ((ITy->getBitWidth() == 8 || ITy->getBitWidth() == 16 ||
196 ITy->getBitWidth() == 32) &&
197 IsNullTerminatedString(C)) {
198 if (ITy->getBitWidth() == 8)
199 return SectionKind::getMergeable1ByteCString();
200 if (ITy->getBitWidth() == 16)
201 return SectionKind::getMergeable2ByteCString();
Anton Korobeynikov8ddb5692009-09-09 08:41:20 +0000202
Chris Lattner1850e5a2009-08-04 16:13:09 +0000203 assert(ITy->getBitWidth() == 32 && "Unknown width");
204 return SectionKind::getMergeable4ByteCString();
205 }
206 }
207 }
Anton Korobeynikov8ddb5692009-09-09 08:41:20 +0000208
Chris Lattnerf0144122009-07-28 03:13:23 +0000209 // Otherwise, just drop it into a mergable constant section. If we have
210 // a section for this size, use it, otherwise use the arbitrary sized
211 // mergable section.
Peter Collingbourne80e2a2f2016-10-24 19:23:39 +0000212 switch (
213 GVar->getParent()->getDataLayout().getTypeAllocSize(C->getType())) {
Chris Lattner27981192009-08-01 23:57:16 +0000214 case 4: return SectionKind::getMergeableConst4();
215 case 8: return SectionKind::getMergeableConst8();
216 case 16: return SectionKind::getMergeableConst16();
David Majnemerb23b0ff2016-02-22 22:23:11 +0000217 case 32: return SectionKind::getMergeableConst32();
Rafael Espindola248a6cf2015-01-29 14:12:41 +0000218 default:
219 return SectionKind::getReadOnly();
Chris Lattnerf0144122009-07-28 03:13:23 +0000220 }
Anton Korobeynikov8ddb5692009-09-09 08:41:20 +0000221
Rafael Espindola8dcaa9f2015-11-17 00:51:23 +0000222 } else {
Oliver Stannardb85d8f42016-08-08 15:28:31 +0000223 // In static, ROPI and RWPI relocation models, the linker will resolve
224 // all addresses, so the relocation entries will actually be constants by
225 // the time the app starts up. However, we can't put this into a
226 // mergable section, because the linker doesn't take relocations into
227 // consideration when it tries to merge entries in the section.
Eric Christopher9532fa42018-05-27 11:23:20 +0000228 Reloc::Model ReloModel = TM.getRelocationModel();
Oliver Stannardb85d8f42016-08-08 15:28:31 +0000229 if (ReloModel == Reloc::Static || ReloModel == Reloc::ROPI ||
230 ReloModel == Reloc::RWPI || ReloModel == Reloc::ROPI_RWPI)
Chris Lattner27981192009-08-01 23:57:16 +0000231 return SectionKind::getReadOnly();
Anton Korobeynikov8ddb5692009-09-09 08:41:20 +0000232
Chris Lattnerf0144122009-07-28 03:13:23 +0000233 // Otherwise, the dynamic linker needs to fix it up, put it in the
234 // writable data.rel section.
Chris Lattner27981192009-08-01 23:57:16 +0000235 return SectionKind::getReadOnlyWithRel();
Chris Lattnerf0144122009-07-28 03:13:23 +0000236 }
237 }
238
Rafael Espindola3cc07212016-06-24 22:19:54 +0000239 // Okay, this isn't a constant.
Rafael Espindolacfc74b72015-11-18 06:02:15 +0000240 return SectionKind::getData();
Chris Lattnerf0144122009-07-28 03:13:23 +0000241}
242
Rafael Espindola75219642015-05-21 19:20:38 +0000243/// This method computes the appropriate section to emit the specified global
244/// variable or function definition. This should not be passed external (or
245/// available externally) globals.
Eric Christopher88a23b62016-09-16 07:33:15 +0000246MCSection *TargetLoweringObjectFile::SectionForGlobal(
Peter Collingbourne80e2a2f2016-10-24 19:23:39 +0000247 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
Chris Lattnerf0144122009-07-28 03:13:23 +0000248 // Select section name.
Peter Collingbourne80e2a2f2016-10-24 19:23:39 +0000249 if (GO->hasSection())
250 return getExplicitSectionGlobal(GO, Kind, TM);
Anton Korobeynikov8ddb5692009-09-09 08:41:20 +0000251
Javed Absar13aa0772017-06-05 10:09:13 +0000252 if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {
253 auto Attrs = GVar->getAttributes();
254 if ((Attrs.hasAttribute("bss-section") && Kind.isBSS()) ||
255 (Attrs.hasAttribute("data-section") && Kind.isData()) ||
256 (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly())) {
257 return getExplicitSectionGlobal(GO, Kind, TM);
258 }
259 }
260
261 if (auto *F = dyn_cast<Function>(GO)) {
262 if (F->hasFnAttribute("implicit-section-name"))
263 return getExplicitSectionGlobal(GO, Kind, TM);
264 }
265
Chris Lattnerf0144122009-07-28 03:13:23 +0000266 // Use default section depending on the 'type' of global
Peter Collingbourne80e2a2f2016-10-24 19:23:39 +0000267 return SelectSectionForGlobal(GO, Kind, TM);
Chris Lattnerf0144122009-07-28 03:13:23 +0000268}
269
Rafael Espindola75219642015-05-21 19:20:38 +0000270MCSection *TargetLoweringObjectFile::getSectionForJumpTable(
Eric Christopher88a23b62016-09-16 07:33:15 +0000271 const Function &F, const TargetMachine &TM) const {
David Majnemer36935fd2016-02-21 01:30:30 +0000272 unsigned Align = 0;
Mehdi Aminia5574d62015-07-16 06:04:17 +0000273 return getSectionForConstant(F.getParent()->getDataLayout(),
David Majnemer36935fd2016-02-21 01:30:30 +0000274 SectionKind::getReadOnly(), /*C=*/nullptr,
275 Align);
Rafael Espindola8eeedf72015-02-12 17:16:46 +0000276}
277
Rafael Espindola3b75cfe2015-02-17 23:34:51 +0000278bool TargetLoweringObjectFile::shouldPutJumpTableInFunctionSection(
279 bool UsesLabelDifference, const Function &F) const {
280 // In PIC mode, we need to emit the jump table to the same section as the
281 // function body itself, otherwise the label differences won't make sense.
282 // FIXME: Need a better predicate for this: what about custom entries?
283 if (UsesLabelDifference)
284 return true;
285
286 // We should also do if the section name is NULL or function is declared
287 // in discardable section
288 // FIXME: this isn't the right predicate, should be based on the MCSection
289 // for the function.
Davide Italiano3bd35332017-01-14 20:09:29 +0000290 return F.isWeakForLinker();
Rafael Espindola3b75cfe2015-02-17 23:34:51 +0000291}
292
Rafael Espindola75219642015-05-21 19:20:38 +0000293/// Given a mergable constant with the specified size and relocation
294/// information, return a section that it should be placed in.
Mehdi Aminia5574d62015-07-16 06:04:17 +0000295MCSection *TargetLoweringObjectFile::getSectionForConstant(
David Majnemer36935fd2016-02-21 01:30:30 +0000296 const DataLayout &DL, SectionKind Kind, const Constant *C,
297 unsigned &Align) const {
Craig Topperc848b1b2014-04-25 05:30:21 +0000298 if (Kind.isReadOnly() && ReadOnlySection != nullptr)
Chris Lattnerf0144122009-07-28 03:13:23 +0000299 return ReadOnlySection;
Anton Korobeynikov8ddb5692009-09-09 08:41:20 +0000300
Chris Lattnerf0144122009-07-28 03:13:23 +0000301 return DataSection;
302}
303
Anton Korobeynikov25efd6d2012-11-14 01:47:00 +0000304/// getTTypeGlobalReference - Return an MCExpr to use for a
Anton Korobeynikov9184b252010-02-15 22:35:59 +0000305/// reference to the specified global variable from exception
306/// handling information.
Rafael Espindola965e3bc2014-02-09 14:50:44 +0000307const MCExpr *TargetLoweringObjectFile::getTTypeGlobalReference(
Eric Christopher88a23b62016-09-16 07:33:15 +0000308 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
309 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
Anton Korobeynikov25efd6d2012-11-14 01:47:00 +0000310 const MCSymbolRefExpr *Ref =
Tim Northoverbc347f22016-11-22 16:17:20 +0000311 MCSymbolRefExpr::create(TM.getSymbol(GV), getContext());
Anton Korobeynikov25efd6d2012-11-14 01:47:00 +0000312
313 return getTTypeReference(Ref, Encoding, Streamer);
Chris Lattner8c6ed052009-09-16 01:46:41 +0000314}
Chris Lattnerf0144122009-07-28 03:13:23 +0000315
Anton Korobeynikov9184b252010-02-15 22:35:59 +0000316const MCExpr *TargetLoweringObjectFile::
Anton Korobeynikov25efd6d2012-11-14 01:47:00 +0000317getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
318 MCStreamer &Streamer) const {
Rafael Espindolaf0adba92011-04-15 15:11:06 +0000319 switch (Encoding & 0x70) {
Anton Korobeynikov9184b252010-02-15 22:35:59 +0000320 default:
Chris Lattner75361b62010-04-07 22:58:41 +0000321 report_fatal_error("We do not support this DWARF encoding yet!");
Anton Korobeynikov9184b252010-02-15 22:35:59 +0000322 case dwarf::DW_EH_PE_absptr:
323 // Do nothing special
Anton Korobeynikov25efd6d2012-11-14 01:47:00 +0000324 return Sym;
Chris Lattner42263e22010-03-11 21:55:20 +0000325 case dwarf::DW_EH_PE_pcrel: {
326 // Emit a label to the streamer for the current position. This gives us
327 // .-foo addressing.
Jim Grosbach19696da2015-05-18 18:43:14 +0000328 MCSymbol *PCSym = getContext().createTempSymbol();
Chris Lattner42263e22010-03-11 21:55:20 +0000329 Streamer.EmitLabel(PCSym);
Jim Grosbach586c0042015-05-30 01:25:56 +0000330 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
331 return MCBinaryExpr::createSub(Sym, PC, getContext());
Chris Lattner42263e22010-03-11 21:55:20 +0000332 }
333 }
Anton Korobeynikov9184b252010-02-15 22:35:59 +0000334}
David Blaikie59eaa382013-06-28 20:05:11 +0000335
Ulrich Weigand716a94f2013-07-02 18:47:09 +0000336const MCExpr *TargetLoweringObjectFile::getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
David Blaikie59eaa382013-06-28 20:05:11 +0000337 // FIXME: It's not clear what, if any, default this should have - perhaps a
338 // null return could mean 'no location' & we should just do that here.
Jim Grosbach586c0042015-05-30 01:25:56 +0000339 return MCSymbolRefExpr::create(Sym, *Ctx);
David Blaikie59eaa382013-06-28 20:05:11 +0000340}
David Majnemer7605cdd2015-03-17 23:54:51 +0000341
342void TargetLoweringObjectFile::getNameWithPrefix(
Eric Christopher88a23b62016-09-16 07:33:15 +0000343 SmallVectorImpl<char> &OutName, const GlobalValue *GV,
Peter Collingbourne05f66f32015-11-03 23:40:03 +0000344 const TargetMachine &TM) const {
Eric Christopher88a23b62016-09-16 07:33:15 +0000345 Mang->getNameWithPrefix(OutName, GV, /*CannotUsePrivateLabel=*/false);
David Majnemer7605cdd2015-03-17 23:54:51 +0000346}