Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
TargetLoweringObjectFileImpl.cpp
Go to the documentation of this file.
1//===- llvm/CodeGen/TargetLoweringObjectFileImpl.cpp - Object File Info ---===//
2//
3// 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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements classes used to handle lowerings specific to common
10// object file formats.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
15#include "llvm/ADT/SmallString.h"
16#include "llvm/ADT/SmallVector.h"
17#include "llvm/ADT/StringExtras.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/BinaryFormat/COFF.h"
20#include "llvm/BinaryFormat/Dwarf.h"
21#include "llvm/BinaryFormat/ELF.h"
22#include "llvm/BinaryFormat/MachO.h"
23#include "llvm/BinaryFormat/Wasm.h"
24#include "llvm/CodeGen/BasicBlockSectionUtils.h"
25#include "llvm/CodeGen/MachineBasicBlock.h"
26#include "llvm/CodeGen/MachineFunction.h"
27#include "llvm/CodeGen/MachineModuleInfo.h"
28#include "llvm/CodeGen/MachineModuleInfoImpls.h"
29#include "llvm/IR/Comdat.h"
30#include "llvm/IR/Constants.h"
31#include "llvm/IR/DataLayout.h"
32#include "llvm/IR/DerivedTypes.h"
33#include "llvm/IR/DiagnosticInfo.h"
34#include "llvm/IR/DiagnosticPrinter.h"
35#include "llvm/IR/Function.h"
36#include "llvm/IR/GlobalAlias.h"
37#include "llvm/IR/GlobalObject.h"
38#include "llvm/IR/GlobalValue.h"
39#include "llvm/IR/GlobalVariable.h"
40#include "llvm/IR/Mangler.h"
41#include "llvm/IR/Metadata.h"
42#include "llvm/IR/Module.h"
43#include "llvm/IR/PseudoProbe.h"
44#include "llvm/IR/Type.h"
45#include "llvm/MC/MCAsmInfo.h"
46#include "llvm/MC/MCAsmInfoDarwin.h"
47#include "llvm/MC/MCContext.h"
48#include "llvm/MC/MCExpr.h"
49#include "llvm/MC/MCSectionCOFF.h"
50#include "llvm/MC/MCSectionELF.h"
51#include "llvm/MC/MCSectionGOFF.h"
52#include "llvm/MC/MCSectionMachO.h"
53#include "llvm/MC/MCSectionWasm.h"
54#include "llvm/MC/MCSectionXCOFF.h"
55#include "llvm/MC/MCStreamer.h"
56#include "llvm/MC/MCSymbol.h"
57#include "llvm/MC/MCSymbolELF.h"
58#include "llvm/MC/MCValue.h"
59#include "llvm/MC/SectionKind.h"
60#include "llvm/ProfileData/InstrProf.h"
61#include "llvm/Support/Base64.h"
62#include "llvm/Support/Casting.h"
63#include "llvm/Support/CodeGen.h"
64#include "llvm/Support/ErrorHandling.h"
65#include "llvm/Support/Format.h"
66#include "llvm/Support/raw_ostream.h"
67#include "llvm/Target/TargetMachine.h"
68#include "llvm/TargetParser/Triple.h"
69#include <cassert>
70#include <string>
71
72using namespacellvm;
73using namespacedwarf;
74
75staticcl::opt<bool>JumpTableInFunctionSection(
76"jumptable-in-function-section",cl::Hidden,cl::init(false),
77cl::desc("Putting Jump Table in function section"));
78
79staticvoidGetObjCImageInfo(Module &M,unsigned &Version,unsigned &Flags,
80StringRef &Section) {
81SmallVector<Module::ModuleFlagEntry, 8> ModuleFlags;
82 M.getModuleFlagsMetadata(ModuleFlags);
83
84for (constauto &MFE: ModuleFlags) {
85// Ignore flags with 'Require' behaviour.
86if (MFE.Behavior ==Module::Require)
87continue;
88
89StringRef Key = MFE.Key->getString();
90if (Key =="Objective-C Image Info Version") {
91 Version = mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue();
92 }elseif (Key =="Objective-C Garbage Collection" ||
93 Key =="Objective-C GC Only" ||
94 Key =="Objective-C Is Simulated" ||
95 Key =="Objective-C Class Properties" ||
96 Key =="Objective-C Image Swift Version") {
97 Flags |= mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue();
98 }elseif (Key =="Objective-C Image Info Section") {
99 Section = cast<MDString>(MFE.Val)->getString();
100 }
101// Backend generates L_OBJC_IMAGE_INFO from Swift ABI version + major + minor +
102// "Objective-C Garbage Collection".
103elseif (Key =="Swift ABI Version") {
104 Flags |= (mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue()) << 8;
105 }elseif (Key =="Swift Major Version") {
106 Flags |= (mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue()) << 24;
107 }elseif (Key =="Swift Minor Version") {
108 Flags |= (mdconst::extract<ConstantInt>(MFE.Val)->getZExtValue()) << 16;
109 }
110 }
111}
112
113//===----------------------------------------------------------------------===//
114// ELF
115//===----------------------------------------------------------------------===//
116
117TargetLoweringObjectFileELF::TargetLoweringObjectFileELF() {
118SupportDSOLocalEquivalentLowering =true;
119}
120
121voidTargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
122constTargetMachine &TgtM) {
123TargetLoweringObjectFile::Initialize(Ctx, TgtM);
124
125CodeModel::Model CM = TgtM.getCodeModel();
126InitializeELF(TgtM.Options.UseInitArray);
127
128switch (TgtM.getTargetTriple().getArch()) {
129caseTriple::arm:
130caseTriple::armeb:
131caseTriple::thumb:
132caseTriple::thumbeb:
133if (Ctx.getAsmInfo()->getExceptionHandlingType() ==ExceptionHandling::ARM)
134break;
135// Fallthrough if not using EHABI
136 [[fallthrough]];
137caseTriple::ppc:
138caseTriple::ppcle:
139caseTriple::x86:
140PersonalityEncoding =isPositionIndependent()
141 ?dwarf::DW_EH_PE_indirect |
142dwarf::DW_EH_PE_pcrel |
143dwarf::DW_EH_PE_sdata4
144 :dwarf::DW_EH_PE_absptr;
145LSDAEncoding =isPositionIndependent()
146 ?dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4
147 :dwarf::DW_EH_PE_absptr;
148TTypeEncoding =isPositionIndependent()
149 ?dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |
150dwarf::DW_EH_PE_sdata4
151 :dwarf::DW_EH_PE_absptr;
152break;
153caseTriple::x86_64:
154if (isPositionIndependent()) {
155PersonalityEncoding =dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |
156 ((CM ==CodeModel::Small || CM ==CodeModel::Medium)
157 ?dwarf::DW_EH_PE_sdata4 :dwarf::DW_EH_PE_sdata8);
158LSDAEncoding =dwarf::DW_EH_PE_pcrel |
159 (CM ==CodeModel::Small
160 ?dwarf::DW_EH_PE_sdata4 :dwarf::DW_EH_PE_sdata8);
161TTypeEncoding =dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |
162 ((CM ==CodeModel::Small || CM ==CodeModel::Medium)
163 ?dwarf::DW_EH_PE_sdata4 :dwarf::DW_EH_PE_sdata8);
164 }else {
165PersonalityEncoding =
166 (CM ==CodeModel::Small || CM ==CodeModel::Medium)
167 ?dwarf::DW_EH_PE_udata4 :dwarf::DW_EH_PE_absptr;
168LSDAEncoding = (CM ==CodeModel::Small)
169 ?dwarf::DW_EH_PE_udata4 :dwarf::DW_EH_PE_absptr;
170TTypeEncoding = (CM ==CodeModel::Small)
171 ?dwarf::DW_EH_PE_udata4 :dwarf::DW_EH_PE_absptr;
172 }
173break;
174caseTriple::hexagon:
175PersonalityEncoding =dwarf::DW_EH_PE_absptr;
176LSDAEncoding =dwarf::DW_EH_PE_absptr;
177TTypeEncoding =dwarf::DW_EH_PE_absptr;
178if (isPositionIndependent()) {
179PersonalityEncoding |=dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel;
180LSDAEncoding |=dwarf::DW_EH_PE_pcrel;
181TTypeEncoding |=dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel;
182 }
183break;
184caseTriple::aarch64:
185caseTriple::aarch64_be:
186caseTriple::aarch64_32:
187// The small model guarantees static code/data size < 4GB, but not where it
188// will be in memory. Most of these could end up >2GB away so even a signed
189// pc-relative 32-bit address is insufficient, theoretically.
190//
191// Use DW_EH_PE_indirect even for -fno-pic to avoid copy relocations.
192LSDAEncoding =dwarf::DW_EH_PE_pcrel |
193 (TgtM.getTargetTriple().getEnvironment() ==Triple::GNUILP32
194 ?dwarf::DW_EH_PE_sdata4
195 :dwarf::DW_EH_PE_sdata8);
196PersonalityEncoding =LSDAEncoding |dwarf::DW_EH_PE_indirect;
197TTypeEncoding =LSDAEncoding |dwarf::DW_EH_PE_indirect;
198break;
199caseTriple::lanai:
200LSDAEncoding =dwarf::DW_EH_PE_absptr;
201PersonalityEncoding =dwarf::DW_EH_PE_absptr;
202TTypeEncoding =dwarf::DW_EH_PE_absptr;
203break;
204caseTriple::mips:
205caseTriple::mipsel:
206caseTriple::mips64:
207caseTriple::mips64el:
208// MIPS uses indirect pointer to refer personality functions and types, so
209// that the eh_frame section can be read-only. DW.ref.personality will be
210// generated for relocation.
211PersonalityEncoding =dwarf::DW_EH_PE_indirect;
212// FIXME: The N64 ABI probably ought to use DW_EH_PE_sdata8 but we can't
213// identify N64 from just a triple.
214TTypeEncoding =dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |
215dwarf::DW_EH_PE_sdata4;
216
217// FreeBSD must be explicit about the data size and using pcrel since it's
218// assembler/linker won't do the automatic conversion that the Linux tools
219// do.
220if (isPositionIndependent() || TgtM.getTargetTriple().isOSFreeBSD()) {
221PersonalityEncoding |=dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4;
222LSDAEncoding =dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4;
223 }
224break;
225caseTriple::ppc64:
226caseTriple::ppc64le:
227PersonalityEncoding =dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |
228dwarf::DW_EH_PE_udata8;
229LSDAEncoding =dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata8;
230TTypeEncoding =dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |
231dwarf::DW_EH_PE_udata8;
232break;
233caseTriple::sparcel:
234caseTriple::sparc:
235if (isPositionIndependent()) {
236LSDAEncoding =dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4;
237PersonalityEncoding =dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |
238dwarf::DW_EH_PE_sdata4;
239TTypeEncoding =dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |
240dwarf::DW_EH_PE_sdata4;
241 }else {
242LSDAEncoding =dwarf::DW_EH_PE_absptr;
243PersonalityEncoding =dwarf::DW_EH_PE_absptr;
244TTypeEncoding =dwarf::DW_EH_PE_absptr;
245 }
246CallSiteEncoding =dwarf::DW_EH_PE_udata4;
247break;
248caseTriple::riscv32:
249caseTriple::riscv64:
250LSDAEncoding =dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4;
251PersonalityEncoding =dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |
252dwarf::DW_EH_PE_sdata4;
253TTypeEncoding =dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |
254dwarf::DW_EH_PE_sdata4;
255CallSiteEncoding =dwarf::DW_EH_PE_udata4;
256break;
257caseTriple::sparcv9:
258LSDAEncoding =dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4;
259if (isPositionIndependent()) {
260PersonalityEncoding =dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |
261dwarf::DW_EH_PE_sdata4;
262TTypeEncoding =dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |
263dwarf::DW_EH_PE_sdata4;
264 }else {
265PersonalityEncoding =dwarf::DW_EH_PE_absptr;
266TTypeEncoding =dwarf::DW_EH_PE_absptr;
267 }
268break;
269caseTriple::systemz:
270// All currently-defined code models guarantee that 4-byte PC-relative
271// values will be in range.
272if (isPositionIndependent()) {
273PersonalityEncoding =dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |
274dwarf::DW_EH_PE_sdata4;
275LSDAEncoding =dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4;
276TTypeEncoding =dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |
277dwarf::DW_EH_PE_sdata4;
278 }else {
279PersonalityEncoding =dwarf::DW_EH_PE_absptr;
280LSDAEncoding =dwarf::DW_EH_PE_absptr;
281TTypeEncoding =dwarf::DW_EH_PE_absptr;
282 }
283break;
284caseTriple::loongarch32:
285caseTriple::loongarch64:
286LSDAEncoding =dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4;
287PersonalityEncoding =dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |
288dwarf::DW_EH_PE_sdata4;
289TTypeEncoding =dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |
290dwarf::DW_EH_PE_sdata4;
291break;
292default:
293break;
294 }
295}
296
297voidTargetLoweringObjectFileELF::getModuleMetadata(Module &M) {
298SmallVector<GlobalValue *, 4> Vec;
299collectUsedGlobalVariables(M, Vec,false);
300for (GlobalValue *GV : Vec)
301if (auto *GO = dyn_cast<GlobalObject>(GV))
302 Used.insert(GO);
303}
304
305voidTargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer,
306Module &M) const{
307auto &C =getContext();
308
309emitLinkerDirectives(Streamer, M);
310
311if (NamedMDNode *DependentLibraries = M.getNamedMetadata("llvm.dependent-libraries")) {
312auto *S =C.getELFSection(".deplibs",ELF::SHT_LLVM_DEPENDENT_LIBRARIES,
313ELF::SHF_MERGE |ELF::SHF_STRINGS, 1);
314
315 Streamer.switchSection(S);
316
317for (constauto *Operand : DependentLibraries->operands()) {
318 Streamer.emitBytes(
319 cast<MDString>(cast<MDNode>(Operand)->getOperand(0))->getString());
320 Streamer.emitInt8(0);
321 }
322 }
323
324if (NamedMDNode *FuncInfo = M.getNamedMetadata(PseudoProbeDescMetadataName)) {
325// Emit a descriptor for every function including functions that have an
326// available external linkage. We may not want this for imported functions
327// that has code in another thinLTO module but we don't have a good way to
328// tell them apart from inline functions defined in header files. Therefore
329// we put each descriptor in a separate comdat section and rely on the
330// linker to deduplicate.
331for (constauto *Operand : FuncInfo->operands()) {
332constauto *MD = cast<MDNode>(Operand);
333auto *GUID = mdconst::dyn_extract<ConstantInt>(MD->getOperand(0));
334auto *Hash = mdconst::dyn_extract<ConstantInt>(MD->getOperand(1));
335auto *Name = cast<MDString>(MD->getOperand(2));
336auto *S =C.getObjectFileInfo()->getPseudoProbeDescSection(
337TM->getFunctionSections() ?Name->getString() :StringRef());
338
339 Streamer.switchSection(S);
340 Streamer.emitInt64(GUID->getZExtValue());
341 Streamer.emitInt64(Hash->getZExtValue());
342 Streamer.emitULEB128IntValue(Name->getString().size());
343 Streamer.emitBytes(Name->getString());
344 }
345 }
346
347if (NamedMDNode *LLVMStats = M.getNamedMetadata("llvm.stats")) {
348// Emit the metadata for llvm statistics into .llvm_stats section, which is
349// formatted as a list of key/value pair, the value is base64 encoded.
350auto *S =C.getObjectFileInfo()->getLLVMStatsSection();
351 Streamer.switchSection(S);
352for (constauto *Operand : LLVMStats->operands()) {
353constauto *MD = cast<MDNode>(Operand);
354assert(MD->getNumOperands() % 2 == 0 &&
355 ("Operand num should be even for a list of key/value pair"));
356for (size_tI = 0;I < MD->getNumOperands();I += 2) {
357// Encode the key string size.
358auto *Key = cast<MDString>(MD->getOperand(I));
359 Streamer.emitULEB128IntValue(Key->getString().size());
360 Streamer.emitBytes(Key->getString());
361// Encode the value into a Base64 string.
362 std::stringValue =encodeBase64(
363Twine(mdconst::dyn_extract<ConstantInt>(MD->getOperand(I + 1))
364 ->getZExtValue())
365 .str());
366 Streamer.emitULEB128IntValue(Value.size());
367 Streamer.emitBytes(Value);
368 }
369 }
370 }
371
372unsignedVersion = 0;
373unsigned Flags = 0;
374StringRef Section;
375
376GetObjCImageInfo(M,Version, Flags, Section);
377if (!Section.empty()) {
378auto *S =C.getELFSection(Section,ELF::SHT_PROGBITS,ELF::SHF_ALLOC);
379 Streamer.switchSection(S);
380 Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
381 Streamer.emitInt32(Version);
382 Streamer.emitInt32(Flags);
383 Streamer.addBlankLine();
384 }
385
386emitCGProfileMetadata(Streamer, M);
387}
388
389voidTargetLoweringObjectFileELF::emitLinkerDirectives(MCStreamer &Streamer,
390Module &M) const{
391auto &C =getContext();
392if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
393auto *S =C.getELFSection(".linker-options",ELF::SHT_LLVM_LINKER_OPTIONS,
394ELF::SHF_EXCLUDE);
395
396 Streamer.switchSection(S);
397
398for (constauto *Operand : LinkerOptions->operands()) {
399if (cast<MDNode>(Operand)->getNumOperands() != 2)
400report_fatal_error("invalid llvm.linker.options");
401for (constauto &Option : cast<MDNode>(Operand)->operands()) {
402 Streamer.emitBytes(cast<MDString>(Option)->getString());
403 Streamer.emitInt8(0);
404 }
405 }
406 }
407}
408
409MCSymbol *TargetLoweringObjectFileELF::getCFIPersonalitySymbol(
410constGlobalValue *GV,constTargetMachine &TM,
411MachineModuleInfo *MMI) const{
412unsigned Encoding =getPersonalityEncoding();
413if ((Encoding & 0x80) ==DW_EH_PE_indirect)
414returngetContext().getOrCreateSymbol(StringRef("DW.ref.") +
415TM.getSymbol(GV)->getName());
416if ((Encoding & 0x70) ==DW_EH_PE_absptr)
417returnTM.getSymbol(GV);
418report_fatal_error("We do not support this DWARF encoding yet!");
419}
420
421voidTargetLoweringObjectFileELF::emitPersonalityValue(
422MCStreamer &Streamer,constDataLayout &DL,constMCSymbol *Sym,
423constMachineModuleInfo *MMI) const{
424SmallString<64> NameData("DW.ref.");
425 NameData +=Sym->getName();
426MCSymbolELF *Label =
427 cast<MCSymbolELF>(getContext().getOrCreateSymbol(NameData));
428 Streamer.emitSymbolAttribute(Label,MCSA_Hidden);
429 Streamer.emitSymbolAttribute(Label,MCSA_Weak);
430unsigned Flags =ELF::SHF_ALLOC |ELF::SHF_WRITE |ELF::SHF_GROUP;
431MCSection *Sec =getContext().getELFNamedSection(".data", Label->getName(),
432ELF::SHT_PROGBITS, Flags, 0);
433unsignedSize =DL.getPointerSize();
434 Streamer.switchSection(Sec);
435 Streamer.emitValueToAlignment(DL.getPointerABIAlignment(0));
436 Streamer.emitSymbolAttribute(Label,MCSA_ELF_TypeObject);
437constMCExpr *E =MCConstantExpr::create(Size,getContext());
438 Streamer.emitELFSize(Label, E);
439 Streamer.emitLabel(Label);
440
441emitPersonalityValueImpl(Streamer,DL,Sym, MMI);
442}
443
444voidTargetLoweringObjectFileELF::emitPersonalityValueImpl(
445MCStreamer &Streamer,constDataLayout &DL,constMCSymbol *Sym,
446constMachineModuleInfo *MMI) const{
447 Streamer.emitSymbolValue(Sym,DL.getPointerSize());
448}
449
450constMCExpr *TargetLoweringObjectFileELF::getTTypeGlobalReference(
451constGlobalValue *GV,unsigned Encoding,constTargetMachine &TM,
452MachineModuleInfo *MMI,MCStreamer &Streamer) const{
453if (Encoding &DW_EH_PE_indirect) {
454MachineModuleInfoELF &ELFMMI = MMI->getObjFileInfo<MachineModuleInfoELF>();
455
456MCSymbol *SSym =getSymbolWithGlobalValueBase(GV,".DW.stub",TM);
457
458// Add information about the stub reference to ELFMMI so that the stub
459// gets emitted by the asmprinter.
460MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym);
461if (!StubSym.getPointer()) {
462MCSymbol *Sym =TM.getSymbol(GV);
463 StubSym =MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
464 }
465
466returnTargetLoweringObjectFile::
467 getTTypeReference(MCSymbolRefExpr::create(SSym,getContext()),
468 Encoding & ~DW_EH_PE_indirect, Streamer);
469 }
470
471returnTargetLoweringObjectFile::getTTypeGlobalReference(GV, Encoding,TM,
472 MMI, Streamer);
473}
474
475staticSectionKindgetELFKindForNamedSection(StringRefName,SectionKind K) {
476// N.B.: The defaults used in here are not the same ones used in MC.
477// We follow gcc, MC follows gas. For example, given ".section .eh_frame",
478// both gas and MC will produce a section with no flags. Given
479// section(".eh_frame") gcc will produce:
480//
481// .section .eh_frame,"a",@progbits
482
483if (Name ==getInstrProfSectionName(IPSK_covmap,Triple::ELF,
484/*AddSegmentInfo=*/false) ||
485Name ==getInstrProfSectionName(IPSK_covfun,Triple::ELF,
486/*AddSegmentInfo=*/false) ||
487Name ==getInstrProfSectionName(IPSK_covdata,Triple::ELF,
488/*AddSegmentInfo=*/false) ||
489Name ==getInstrProfSectionName(IPSK_covname,Triple::ELF,
490/*AddSegmentInfo=*/false) ||
491Name ==".llvmbc" ||Name ==".llvmcmd")
492returnSectionKind::getMetadata();
493
494if (!Name.starts_with("."))return K;
495
496// Default implementation based on some magic section names.
497if (Name ==".bss" ||Name.starts_with(".bss.") ||
498Name.starts_with(".gnu.linkonce.b.") ||
499Name.starts_with(".llvm.linkonce.b.") ||Name ==".sbss" ||
500Name.starts_with(".sbss.") ||Name.starts_with(".gnu.linkonce.sb.") ||
501Name.starts_with(".llvm.linkonce.sb."))
502returnSectionKind::getBSS();
503
504if (Name ==".tdata" ||Name.starts_with(".tdata.") ||
505Name.starts_with(".gnu.linkonce.td.") ||
506Name.starts_with(".llvm.linkonce.td."))
507returnSectionKind::getThreadData();
508
509if (Name ==".tbss" ||Name.starts_with(".tbss.") ||
510Name.starts_with(".gnu.linkonce.tb.") ||
511Name.starts_with(".llvm.linkonce.tb."))
512returnSectionKind::getThreadBSS();
513
514return K;
515}
516
517staticboolhasPrefix(StringRefSectionName,StringRef Prefix) {
518returnSectionName.consume_front(Prefix) &&
519 (SectionName.empty() ||SectionName[0] =='.');
520}
521
522staticunsignedgetELFSectionType(StringRefName,SectionKind K) {
523// Use SHT_NOTE for section whose name starts with ".note" to allow
524// emitting ELF notes from C variable declaration.
525// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77609
526if (Name.starts_with(".note"))
527returnELF::SHT_NOTE;
528
529if (hasPrefix(Name,".init_array"))
530returnELF::SHT_INIT_ARRAY;
531
532if (hasPrefix(Name,".fini_array"))
533returnELF::SHT_FINI_ARRAY;
534
535if (hasPrefix(Name,".preinit_array"))
536returnELF::SHT_PREINIT_ARRAY;
537
538if (hasPrefix(Name,".llvm.offloading"))
539returnELF::SHT_LLVM_OFFLOADING;
540if (Name ==".llvm.lto")
541returnELF::SHT_LLVM_LTO;
542
543if (K.isBSS() || K.isThreadBSS())
544returnELF::SHT_NOBITS;
545
546returnELF::SHT_PROGBITS;
547}
548
549staticunsignedgetELFSectionFlags(SectionKind K) {
550unsigned Flags = 0;
551
552if (!K.isMetadata() && !K.isExclude())
553 Flags |=ELF::SHF_ALLOC;
554
555if (K.isExclude())
556 Flags |=ELF::SHF_EXCLUDE;
557
558if (K.isText())
559 Flags |=ELF::SHF_EXECINSTR;
560
561if (K.isExecuteOnly())
562 Flags |=ELF::SHF_ARM_PURECODE;
563
564if (K.isWriteable())
565 Flags |=ELF::SHF_WRITE;
566
567if (K.isThreadLocal())
568 Flags |=ELF::SHF_TLS;
569
570if (K.isMergeableCString() || K.isMergeableConst())
571 Flags |=ELF::SHF_MERGE;
572
573if (K.isMergeableCString())
574 Flags |=ELF::SHF_STRINGS;
575
576return Flags;
577}
578
579staticconstComdat *getELFComdat(constGlobalValue *GV) {
580constComdat *C = GV->getComdat();
581if (!C)
582returnnullptr;
583
584if (C->getSelectionKind() !=Comdat::Any &&
585C->getSelectionKind() !=Comdat::NoDeduplicate)
586report_fatal_error("ELF COMDATs only support SelectionKind::Any and "
587"SelectionKind::NoDeduplicate, '" +
588C->getName() +"' cannot be lowered.");
589
590returnC;
591}
592
593staticconstMCSymbolELF *getLinkedToSymbol(constGlobalObject *GO,
594constTargetMachine &TM) {
595MDNode *MD = GO->getMetadata(LLVMContext::MD_associated);
596if (!MD)
597returnnullptr;
598
599auto *VM = cast<ValueAsMetadata>(MD->getOperand(0).get());
600auto *OtherGV = dyn_cast<GlobalValue>(VM->getValue());
601return OtherGV ? dyn_cast<MCSymbolELF>(TM.getSymbol(OtherGV)) :nullptr;
602}
603
604staticunsignedgetEntrySizeForKind(SectionKind Kind) {
605if (Kind.isMergeable1ByteCString())
606return 1;
607elseif (Kind.isMergeable2ByteCString())
608return 2;
609elseif (Kind.isMergeable4ByteCString())
610return 4;
611elseif (Kind.isMergeableConst4())
612return 4;
613elseif (Kind.isMergeableConst8())
614return 8;
615elseif (Kind.isMergeableConst16())
616return 16;
617elseif (Kind.isMergeableConst32())
618return 32;
619else {
620// We shouldn't have mergeable C strings or mergeable constants that we
621// didn't handle above.
622assert(!Kind.isMergeableCString() &&"unknown string width");
623assert(!Kind.isMergeableConst() &&"unknown data width");
624return 0;
625 }
626}
627
628/// Return the section prefix name used by options FunctionsSections and
629/// DataSections.
630staticStringRefgetSectionPrefixForGlobal(SectionKind Kind,bool IsLarge) {
631if (Kind.isText())
632return IsLarge ?".ltext" :".text";
633if (Kind.isReadOnly())
634return IsLarge ?".lrodata" :".rodata";
635if (Kind.isBSS())
636return IsLarge ?".lbss" :".bss";
637if (Kind.isThreadData())
638return".tdata";
639if (Kind.isThreadBSS())
640return".tbss";
641if (Kind.isData())
642return IsLarge ?".ldata" :".data";
643if (Kind.isReadOnlyWithRel())
644return IsLarge ?".ldata.rel.ro" :".data.rel.ro";
645llvm_unreachable("Unknown section kind");
646}
647
648staticSmallString<128>
649getELFSectionNameForGlobal(constGlobalObject *GO,SectionKind Kind,
650Mangler &Mang,constTargetMachine &TM,
651unsigned EntrySize,bool UniqueSectionName) {
652SmallString<128>Name =
653getSectionPrefixForGlobal(Kind, TM.isLargeGlobalValue(GO));
654if (Kind.isMergeableCString()) {
655// We also need alignment here.
656// FIXME: this is getting the alignment of the character, not the
657// alignment of the global!
658Align Alignment = GO->getDataLayout().getPreferredAlign(
659 cast<GlobalVariable>(GO));
660
661Name +=".str";
662Name += utostr(EntrySize);
663Name +=".";
664Name += utostr(Alignment.value());
665 }elseif (Kind.isMergeableConst()) {
666Name +=".cst";
667Name += utostr(EntrySize);
668 }
669
670bool HasPrefix =false;
671if (constauto *F = dyn_cast<Function>(GO)) {
672if (std::optional<StringRef> Prefix =F->getSectionPrefix()) {
673raw_svector_ostream(Name) <<'.' << *Prefix;
674 HasPrefix =true;
675 }
676 }
677
678if (UniqueSectionName) {
679Name.push_back('.');
680 TM.getNameWithPrefix(Name, GO, Mang,/*MayAlwaysUsePrivate*/true);
681 }elseif (HasPrefix)
682// For distinguishing between .text.${text-section-prefix}. (with trailing
683// dot) and .text.${function-name}
684Name.push_back('.');
685returnName;
686}
687
688namespace{
689classLoweringDiagnosticInfo :publicDiagnosticInfo {
690constTwine &Msg;
691
692public:
693 LoweringDiagnosticInfo(constTwine &DiagMsg,
694DiagnosticSeverity Severity =DS_Error)
695 :DiagnosticInfo(DK_Lowering, Severity), Msg(DiagMsg) {}
696voidprint(DiagnosticPrinter &DP) const override{ DP << Msg; }
697};
698}
699
700/// Calculate an appropriate unique ID for a section, and update Flags,
701/// EntrySize and NextUniqueID where appropriate.
702staticunsigned
703calcUniqueIDUpdateFlagsAndSize(constGlobalObject *GO,StringRefSectionName,
704SectionKind Kind,constTargetMachine &TM,
705MCContext &Ctx,Mangler &Mang,unsigned &Flags,
706unsigned &EntrySize,unsigned &NextUniqueID,
707constbool Retain,constbool ForceUnique) {
708// Increment uniqueID if we are forced to emit a unique section.
709// This works perfectly fine with section attribute or pragma section as the
710// sections with the same name are grouped together by the assembler.
711if (ForceUnique)
712return NextUniqueID++;
713
714// A section can have at most one associated section. Put each global with
715// MD_associated in a unique section.
716constbool Associated = GO->getMetadata(LLVMContext::MD_associated);
717if (Associated) {
718 Flags |=ELF::SHF_LINK_ORDER;
719return NextUniqueID++;
720 }
721
722if (Retain) {
723if (TM.getTargetTriple().isOSSolaris())
724 Flags |=ELF::SHF_SUNW_NODISCARD;
725elseif (Ctx.getAsmInfo()->useIntegratedAssembler() ||
726 Ctx.getAsmInfo()->binutilsIsAtLeast(2, 36))
727 Flags |=ELF::SHF_GNU_RETAIN;
728return NextUniqueID++;
729 }
730
731// If two symbols with differing sizes end up in the same mergeable section
732// that section can be assigned an incorrect entry size. To avoid this we
733// usually put symbols of the same size into distinct mergeable sections with
734// the same name. Doing so relies on the ",unique ," assembly feature. This
735// feature is not available until binutils version 2.35
736// (https://sourceware.org/bugzilla/show_bug.cgi?id=25380).
737constbool SupportsUnique = Ctx.getAsmInfo()->useIntegratedAssembler() ||
738 Ctx.getAsmInfo()->binutilsIsAtLeast(2, 35);
739if (!SupportsUnique) {
740 Flags &= ~ELF::SHF_MERGE;
741 EntrySize = 0;
742returnMCContext::GenericSectionID;
743 }
744
745constbool SymbolMergeable = Flags &ELF::SHF_MERGE;
746constbool SeenSectionNameBefore =
747 Ctx.isELFGenericMergeableSection(SectionName);
748// If this is the first occurrence of this section name, treat it as the
749// generic section
750if (!SymbolMergeable && !SeenSectionNameBefore) {
751if (TM.getSeparateNamedSections())
752return NextUniqueID++;
753else
754returnMCContext::GenericSectionID;
755 }
756
757// Symbols must be placed into sections with compatible entry sizes. Generate
758// unique sections for symbols that have not been assigned to compatible
759// sections.
760constauto PreviousID =
761 Ctx.getELFUniqueIDForEntsize(SectionName, Flags, EntrySize);
762if (PreviousID && (!TM.getSeparateNamedSections() ||
763 *PreviousID ==MCContext::GenericSectionID))
764return *PreviousID;
765
766// If the user has specified the same section name as would be created
767// implicitly for this symbol e.g. .rodata.str1.1, then we don't need
768// to unique the section as the entry size for this symbol will be
769// compatible with implicitly created sections.
770SmallString<128> ImplicitSectionNameStem =
771getELFSectionNameForGlobal(GO, Kind, Mang, TM, EntrySize,false);
772if (SymbolMergeable &&
773 Ctx.isELFImplicitMergeableSectionNamePrefix(SectionName) &&
774SectionName.starts_with(ImplicitSectionNameStem))
775returnMCContext::GenericSectionID;
776
777// We have seen this section name before, but with different flags or entity
778// size. Create a new unique ID.
779return NextUniqueID++;
780}
781
782static std::tuple<StringRef, bool, unsigned>
783getGlobalObjectInfo(constGlobalObject *GO,constTargetMachine &TM) {
784StringRef Group ="";
785bool IsComdat =false;
786unsigned Flags = 0;
787if (constComdat *C =getELFComdat(GO)) {
788 Flags |=ELF::SHF_GROUP;
789 Group =C->getName();
790 IsComdat =C->getSelectionKind() ==Comdat::Any;
791 }
792if (TM.isLargeGlobalValue(GO))
793 Flags |=ELF::SHF_X86_64_LARGE;
794return {Group, IsComdat, Flags};
795}
796
797staticStringRefhandlePragmaClangSection(constGlobalObject *GO,
798SectionKind Kind) {
799// Check if '#pragma clang section' name is applicable.
800// Note that pragma directive overrides -ffunction-section, -fdata-section
801// and so section name is exactly as user specified and not uniqued.
802constGlobalVariable *GV = dyn_cast<GlobalVariable>(GO);
803if (GV && GV->hasImplicitSection()) {
804auto Attrs = GV->getAttributes();
805if (Attrs.hasAttribute("bss-section") && Kind.isBSS())
806return Attrs.getAttribute("bss-section").getValueAsString();
807elseif (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly())
808return Attrs.getAttribute("rodata-section").getValueAsString();
809elseif (Attrs.hasAttribute("relro-section") && Kind.isReadOnlyWithRel())
810return Attrs.getAttribute("relro-section").getValueAsString();
811elseif (Attrs.hasAttribute("data-section") && Kind.isData())
812return Attrs.getAttribute("data-section").getValueAsString();
813 }
814
815return GO->getSection();
816}
817
818staticMCSection *selectExplicitSectionGlobal(constGlobalObject *GO,
819SectionKind Kind,
820constTargetMachine &TM,
821MCContext &Ctx,Mangler &Mang,
822unsigned &NextUniqueID,
823bool Retain,bool ForceUnique) {
824StringRefSectionName =handlePragmaClangSection(GO, Kind);
825
826// Infer section flags from the section name if we can.
827 Kind =getELFKindForNamedSection(SectionName, Kind);
828
829unsigned Flags =getELFSectionFlags(Kind);
830auto [Group, IsComdat, ExtraFlags] =getGlobalObjectInfo(GO, TM);
831 Flags |= ExtraFlags;
832
833unsigned EntrySize =getEntrySizeForKind(Kind);
834constunsigned UniqueID =calcUniqueIDUpdateFlagsAndSize(
835 GO,SectionName, Kind, TM, Ctx, Mang, Flags, EntrySize, NextUniqueID,
836 Retain, ForceUnique);
837
838constMCSymbolELF *LinkedToSym =getLinkedToSymbol(GO, TM);
839MCSectionELF *Section = Ctx.getELFSection(
840SectionName,getELFSectionType(SectionName, Kind), Flags, EntrySize,
841 Group, IsComdat, UniqueID, LinkedToSym);
842// Make sure that we did not get some other section with incompatible sh_link.
843// This should not be possible due to UniqueID code above.
844assert(Section->getLinkedToSymbol() == LinkedToSym &&
845"Associated symbol mismatch between sections");
846
847if (!(Ctx.getAsmInfo()->useIntegratedAssembler() ||
848 Ctx.getAsmInfo()->binutilsIsAtLeast(2, 35))) {
849// If we are using GNU as before 2.35, then this symbol might have
850// been placed in an incompatible mergeable section. Emit an error if this
851// is the case to avoid creating broken output.
852if ((Section->getFlags() &ELF::SHF_MERGE) &&
853 (Section->getEntrySize() !=getEntrySizeForKind(Kind)))
854 GO->getContext().diagnose(LoweringDiagnosticInfo(
855"Symbol '" + GO->getName() +"' from module '" +
856 (GO->getParent() ? GO->getParent()->getSourceFileName() :"unknown") +
857"' required a section with entry-size=" +
858Twine(getEntrySizeForKind(Kind)) +" but was placed in section '" +
859SectionName +"' with entry-size=" +Twine(Section->getEntrySize()) +
860": Explicit assignment by pragma or attribute of an incompatible "
861"symbol to this section?"));
862 }
863
864return Section;
865}
866
867MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
868constGlobalObject *GO,SectionKind Kind,constTargetMachine &TM) const{
869returnselectExplicitSectionGlobal(GO, Kind,TM,getContext(),getMangler(),
870 NextUniqueID, Used.count(GO),
871/* ForceUnique = */false);
872}
873
874staticMCSectionELF *selectELFSectionForGlobal(
875MCContext &Ctx,constGlobalObject *GO,SectionKind Kind,Mangler &Mang,
876constTargetMachine &TM,bool EmitUniqueSection,unsigned Flags,
877unsigned *NextUniqueID,constMCSymbolELF *AssociatedSymbol) {
878
879auto [Group, IsComdat, ExtraFlags] =getGlobalObjectInfo(GO, TM);
880 Flags |= ExtraFlags;
881
882// Get the section entry size based on the kind.
883unsigned EntrySize =getEntrySizeForKind(Kind);
884
885bool UniqueSectionName =false;
886unsigned UniqueID =MCContext::GenericSectionID;
887if (EmitUniqueSection) {
888if (TM.getUniqueSectionNames()) {
889 UniqueSectionName =true;
890 }else {
891 UniqueID = *NextUniqueID;
892 (*NextUniqueID)++;
893 }
894 }
895SmallString<128>Name =getELFSectionNameForGlobal(
896 GO, Kind, Mang, TM, EntrySize, UniqueSectionName);
897
898// Use 0 as the unique ID for execute-only text.
899if (Kind.isExecuteOnly())
900 UniqueID = 0;
901return Ctx.getELFSection(Name,getELFSectionType(Name, Kind), Flags,
902 EntrySize, Group, IsComdat, UniqueID,
903 AssociatedSymbol);
904}
905
906staticMCSection *selectELFSectionForGlobal(
907MCContext &Ctx,constGlobalObject *GO,SectionKind Kind,Mangler &Mang,
908constTargetMachine &TM,bool Retain,bool EmitUniqueSection,
909unsigned Flags,unsigned *NextUniqueID) {
910constMCSymbolELF *LinkedToSym =getLinkedToSymbol(GO, TM);
911if (LinkedToSym) {
912 EmitUniqueSection =true;
913 Flags |=ELF::SHF_LINK_ORDER;
914 }
915if (Retain) {
916if (TM.getTargetTriple().isOSSolaris()) {
917 EmitUniqueSection =true;
918 Flags |=ELF::SHF_SUNW_NODISCARD;
919 }elseif (Ctx.getAsmInfo()->useIntegratedAssembler() ||
920 Ctx.getAsmInfo()->binutilsIsAtLeast(2, 36)) {
921 EmitUniqueSection =true;
922 Flags |=ELF::SHF_GNU_RETAIN;
923 }
924 }
925
926MCSectionELF *Section =selectELFSectionForGlobal(
927 Ctx, GO, Kind, Mang, TM, EmitUniqueSection, Flags,
928 NextUniqueID, LinkedToSym);
929assert(Section->getLinkedToSymbol() == LinkedToSym);
930return Section;
931}
932
933MCSection *TargetLoweringObjectFileELF::SelectSectionForGlobal(
934constGlobalObject *GO,SectionKind Kind,constTargetMachine &TM) const{
935unsigned Flags =getELFSectionFlags(Kind);
936
937// If we have -ffunction-section or -fdata-section then we should emit the
938// global value to a uniqued section specifically for it.
939bool EmitUniqueSection =false;
940if (!(Flags &ELF::SHF_MERGE) && !Kind.isCommon()) {
941if (Kind.isText())
942 EmitUniqueSection =TM.getFunctionSections();
943else
944 EmitUniqueSection =TM.getDataSections();
945 }
946 EmitUniqueSection |= GO->hasComdat();
947returnselectELFSectionForGlobal(getContext(), GO, Kind,getMangler(),TM,
948 Used.count(GO), EmitUniqueSection, Flags,
949 &NextUniqueID);
950}
951
952MCSection *TargetLoweringObjectFileELF::getUniqueSectionForFunction(
953constFunction &F,constTargetMachine &TM) const{
954SectionKind Kind =SectionKind::getText();
955unsigned Flags =getELFSectionFlags(Kind);
956// If the function's section names is pre-determined via pragma or a
957// section attribute, call selectExplicitSectionGlobal.
958if (F.hasSection())
959returnselectExplicitSectionGlobal(
960 &F, Kind,TM,getContext(),getMangler(), NextUniqueID,
961 Used.count(&F),/* ForceUnique = */true);
962else
963returnselectELFSectionForGlobal(
964getContext(), &F, Kind,getMangler(),TM, Used.count(&F),
965/*EmitUniqueSection=*/true, Flags, &NextUniqueID);
966}
967
968MCSection *TargetLoweringObjectFileELF::getSectionForJumpTable(
969constFunction &F,constTargetMachine &TM) const{
970// If the function can be removed, produce a unique section so that
971// the table doesn't prevent the removal.
972constComdat *C =F.getComdat();
973bool EmitUniqueSection =TM.getFunctionSections() ||C;
974if (!EmitUniqueSection)
975returnReadOnlySection;
976
977returnselectELFSectionForGlobal(getContext(), &F,SectionKind::getReadOnly(),
978getMangler(),TM, EmitUniqueSection,
979ELF::SHF_ALLOC, &NextUniqueID,
980/* AssociatedSymbol */nullptr);
981}
982
983MCSection *TargetLoweringObjectFileELF::getSectionForLSDA(
984constFunction &F,constMCSymbol &FnSym,constTargetMachine &TM) const{
985// If neither COMDAT nor function sections, use the monolithic LSDA section.
986// Re-use this path if LSDASection is null as in the Arm EHABI.
987if (!LSDASection || (!F.hasComdat() && !TM.getFunctionSections()))
988returnLSDASection;
989
990constauto *LSDA = cast<MCSectionELF>(LSDASection);
991unsigned Flags = LSDA->getFlags();
992constMCSymbolELF *LinkedToSym =nullptr;
993StringRef Group;
994bool IsComdat =false;
995if (constComdat *C =getELFComdat(&F)) {
996 Flags |=ELF::SHF_GROUP;
997 Group =C->getName();
998 IsComdat =C->getSelectionKind() ==Comdat::Any;
999 }
1000// Use SHF_LINK_ORDER to facilitate --gc-sections if we can use GNU ld>=2.36
1001// or LLD, which support mixed SHF_LINK_ORDER & non-SHF_LINK_ORDER.
1002if (TM.getFunctionSections() &&
1003 (getContext().getAsmInfo()->useIntegratedAssembler() &&
1004getContext().getAsmInfo()->binutilsIsAtLeast(2, 36))) {
1005 Flags |=ELF::SHF_LINK_ORDER;
1006 LinkedToSym = cast<MCSymbolELF>(&FnSym);
1007 }
1008
1009// Append the function name as the suffix like GCC, assuming
1010// -funique-section-names applies to .gcc_except_table sections.
1011returngetContext().getELFSection(
1012 (TM.getUniqueSectionNames() ? LSDA->getName() +"." +F.getName()
1013 : LSDA->getName()),
1014 LSDA->getType(), Flags, 0, Group, IsComdat,MCSection::NonUniqueID,
1015 LinkedToSym);
1016}
1017
1018boolTargetLoweringObjectFileELF::shouldPutJumpTableInFunctionSection(
1019bool UsesLabelDifference,constFunction &F) const{
1020// We can always create relative relocations, so use another section
1021// that can be marked non-executable.
1022returnfalse;
1023}
1024
1025/// Given a mergeable constant with the specified size and relocation
1026/// information, return a section that it should be placed in.
1027MCSection *TargetLoweringObjectFileELF::getSectionForConstant(
1028constDataLayout &DL,SectionKind Kind,constConstant *C,
1029Align &Alignment) const{
1030if (Kind.isMergeableConst4() &&MergeableConst4Section)
1031returnMergeableConst4Section;
1032if (Kind.isMergeableConst8() &&MergeableConst8Section)
1033returnMergeableConst8Section;
1034if (Kind.isMergeableConst16() &&MergeableConst16Section)
1035returnMergeableConst16Section;
1036if (Kind.isMergeableConst32() &&MergeableConst32Section)
1037returnMergeableConst32Section;
1038if (Kind.isReadOnly())
1039returnReadOnlySection;
1040
1041assert(Kind.isReadOnlyWithRel() &&"Unknown section kind");
1042returnDataRelROSection;
1043}
1044
1045/// Returns a unique section for the given machine basic block.
1046MCSection *TargetLoweringObjectFileELF::getSectionForMachineBasicBlock(
1047constFunction &F,constMachineBasicBlock &MBB,
1048constTargetMachine &TM) const{
1049assert(MBB.isBeginSection() &&"Basic block does not start a section!");
1050unsigned UniqueID =MCContext::GenericSectionID;
1051
1052// For cold sections use the .text.split. prefix along with the parent
1053// function name. All cold blocks for the same function go to the same
1054// section. Similarly all exception blocks are grouped by symbol name
1055// under the .text.eh prefix. For regular sections, we either use a unique
1056// name, or a unique ID for the section.
1057SmallString<128>Name;
1058StringRef FunctionSectionName =MBB.getParent()->getSection()->getName();
1059if (FunctionSectionName ==".text" ||
1060 FunctionSectionName.starts_with(".text.")) {
1061// Function is in a regular .text section.
1062StringRef FunctionName =MBB.getParent()->getName();
1063if (MBB.getSectionID() ==MBBSectionID::ColdSectionID) {
1064Name +=BBSectionsColdTextPrefix;
1065Name += FunctionName;
1066 }elseif (MBB.getSectionID() ==MBBSectionID::ExceptionSectionID) {
1067Name +=".text.eh.";
1068Name += FunctionName;
1069 }else {
1070Name += FunctionSectionName;
1071if (TM.getUniqueBasicBlockSectionNames()) {
1072if (!Name.ends_with("."))
1073Name +=".";
1074Name +=MBB.getSymbol()->getName();
1075 }else {
1076 UniqueID = NextUniqueID++;
1077 }
1078 }
1079 }else {
1080// If the original function has a custom non-dot-text section, then emit
1081// all basic block sections into that section too, each with a unique id.
1082Name = FunctionSectionName;
1083 UniqueID = NextUniqueID++;
1084 }
1085
1086unsigned Flags =ELF::SHF_ALLOC |ELF::SHF_EXECINSTR;
1087 std::string GroupName;
1088if (F.hasComdat()) {
1089 Flags |=ELF::SHF_GROUP;
1090 GroupName =F.getComdat()->getName().str();
1091 }
1092returngetContext().getELFSection(Name,ELF::SHT_PROGBITS, Flags,
1093 0/* Entry Size */, GroupName,
1094F.hasComdat(), UniqueID,nullptr);
1095}
1096
1097staticMCSectionELF *getStaticStructorSection(MCContext &Ctx,bool UseInitArray,
1098bool IsCtor,unsigned Priority,
1099constMCSymbol *KeySym) {
1100 std::stringName;
1101unsignedType;
1102unsigned Flags =ELF::SHF_ALLOC |ELF::SHF_WRITE;
1103StringRefComdat = KeySym ? KeySym->getName() :"";
1104
1105if (KeySym)
1106 Flags |=ELF::SHF_GROUP;
1107
1108if (UseInitArray) {
1109if (IsCtor) {
1110Type =ELF::SHT_INIT_ARRAY;
1111Name =".init_array";
1112 }else {
1113Type =ELF::SHT_FINI_ARRAY;
1114Name =".fini_array";
1115 }
1116if (Priority != 65535) {
1117Name +='.';
1118Name += utostr(Priority);
1119 }
1120 }else {
1121// The default scheme is .ctor / .dtor, so we have to invert the priority
1122// numbering.
1123if (IsCtor)
1124Name =".ctors";
1125else
1126Name =".dtors";
1127if (Priority != 65535)
1128raw_string_ostream(Name) <<format(".%05u", 65535 - Priority);
1129Type =ELF::SHT_PROGBITS;
1130 }
1131
1132return Ctx.getELFSection(Name,Type, Flags, 0,Comdat,/*IsComdat=*/true);
1133}
1134
1135MCSection *TargetLoweringObjectFileELF::getStaticCtorSection(
1136unsigned Priority,constMCSymbol *KeySym) const{
1137returngetStaticStructorSection(getContext(), UseInitArray,true, Priority,
1138 KeySym);
1139}
1140
1141MCSection *TargetLoweringObjectFileELF::getStaticDtorSection(
1142unsigned Priority,constMCSymbol *KeySym) const{
1143returngetStaticStructorSection(getContext(), UseInitArray,false, Priority,
1144 KeySym);
1145}
1146
1147constMCExpr *TargetLoweringObjectFileELF::lowerRelativeReference(
1148constGlobalValue *LHS,constGlobalValue *RHS,
1149constTargetMachine &TM) const{
1150// We may only use a PLT-relative relocation to refer to unnamed_addr
1151// functions.
1152if (!LHS->hasGlobalUnnamedAddr() || !LHS->getValueType()->isFunctionTy())
1153returnnullptr;
1154
1155// Basic correctness checks.
1156if (LHS->getType()->getPointerAddressSpace() != 0 ||
1157RHS->getType()->getPointerAddressSpace() != 0 ||LHS->isThreadLocal() ||
1158RHS->isThreadLocal())
1159returnnullptr;
1160
1161returnMCBinaryExpr::createSub(
1162MCSymbolRefExpr::create(TM.getSymbol(LHS),PLTRelativeVariantKind,
1163getContext()),
1164MCSymbolRefExpr::create(TM.getSymbol(RHS),getContext()),getContext());
1165}
1166
1167constMCExpr *TargetLoweringObjectFileELF::lowerDSOLocalEquivalent(
1168constDSOLocalEquivalent *Equiv,constTargetMachine &TM) const{
1169assert(supportDSOLocalEquivalentLowering());
1170
1171constauto *GV = Equiv->getGlobalValue();
1172
1173// A PLT entry is not needed for dso_local globals.
1174if (GV->isDSOLocal() || GV->isImplicitDSOLocal())
1175returnMCSymbolRefExpr::create(TM.getSymbol(GV),getContext());
1176
1177returnMCSymbolRefExpr::create(TM.getSymbol(GV),PLTRelativeVariantKind,
1178getContext());
1179}
1180
1181MCSection *TargetLoweringObjectFileELF::getSectionForCommandLines() const{
1182// Use ".GCC.command.line" since this feature is to support clang's
1183// -frecord-gcc-switches which in turn attempts to mimic GCC's switch of the
1184// same name.
1185returngetContext().getELFSection(".GCC.command.line",ELF::SHT_PROGBITS,
1186ELF::SHF_MERGE |ELF::SHF_STRINGS, 1);
1187}
1188
1189void
1190TargetLoweringObjectFileELF::InitializeELF(bool UseInitArray_) {
1191 UseInitArray = UseInitArray_;
1192MCContext &Ctx =getContext();
1193if (!UseInitArray) {
1194StaticCtorSection = Ctx.getELFSection(".ctors",ELF::SHT_PROGBITS,
1195ELF::SHF_ALLOC |ELF::SHF_WRITE);
1196
1197StaticDtorSection = Ctx.getELFSection(".dtors",ELF::SHT_PROGBITS,
1198ELF::SHF_ALLOC |ELF::SHF_WRITE);
1199return;
1200 }
1201
1202StaticCtorSection = Ctx.getELFSection(".init_array",ELF::SHT_INIT_ARRAY,
1203ELF::SHF_WRITE |ELF::SHF_ALLOC);
1204StaticDtorSection = Ctx.getELFSection(".fini_array",ELF::SHT_FINI_ARRAY,
1205ELF::SHF_WRITE |ELF::SHF_ALLOC);
1206}
1207
1208//===----------------------------------------------------------------------===//
1209// MachO
1210//===----------------------------------------------------------------------===//
1211
1212TargetLoweringObjectFileMachO::TargetLoweringObjectFileMachO() {
1213SupportIndirectSymViaGOTPCRel =true;
1214}
1215
1216voidTargetLoweringObjectFileMachO::Initialize(MCContext &Ctx,
1217constTargetMachine &TM) {
1218TargetLoweringObjectFile::Initialize(Ctx,TM);
1219if (TM.getRelocationModel() ==Reloc::Static) {
1220StaticCtorSection = Ctx.getMachOSection("__TEXT","__constructor", 0,
1221SectionKind::getData());
1222StaticDtorSection = Ctx.getMachOSection("__TEXT","__destructor", 0,
1223SectionKind::getData());
1224 }else {
1225StaticCtorSection = Ctx.getMachOSection("__DATA","__mod_init_func",
1226MachO::S_MOD_INIT_FUNC_POINTERS,
1227SectionKind::getData());
1228StaticDtorSection = Ctx.getMachOSection("__DATA","__mod_term_func",
1229MachO::S_MOD_TERM_FUNC_POINTERS,
1230SectionKind::getData());
1231 }
1232
1233PersonalityEncoding =
1234dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4;
1235LSDAEncoding =dwarf::DW_EH_PE_pcrel;
1236TTypeEncoding =
1237dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4;
1238}
1239
1240MCSection *TargetLoweringObjectFileMachO::getStaticDtorSection(
1241unsigned Priority,constMCSymbol *KeySym) const{
1242returnStaticDtorSection;
1243// In userspace, we lower global destructors via atexit(), but kernel/kext
1244// environments do not provide this function so we still need to support the
1245// legacy way here.
1246// See the -disable-atexit-based-global-dtor-lowering CodeGen flag for more
1247// context.
1248}
1249
1250voidTargetLoweringObjectFileMachO::emitModuleMetadata(MCStreamer &Streamer,
1251Module &M) const{
1252// Emit the linker options if present.
1253emitLinkerDirectives(Streamer, M);
1254
1255unsigned VersionVal = 0;
1256unsigned ImageInfoFlags = 0;
1257StringRef SectionVal;
1258
1259GetObjCImageInfo(M, VersionVal, ImageInfoFlags, SectionVal);
1260emitCGProfileMetadata(Streamer, M);
1261
1262// The section is mandatory. If we don't have it, then we don't have GC info.
1263if (SectionVal.empty())
1264return;
1265
1266StringRef Segment, Section;
1267unsigned TAA = 0, StubSize = 0;
1268bool TAAParsed;
1269if (Error E =MCSectionMachO::ParseSectionSpecifier(
1270 SectionVal, Segment, Section, TAA, TAAParsed, StubSize)) {
1271// If invalid, report the error with report_fatal_error.
1272report_fatal_error("Invalid section specifier '" + Section +
1273"': " +toString(std::move(E)) +".");
1274 }
1275
1276// Get the section.
1277MCSectionMachO *S =getContext().getMachOSection(
1278 Segment, Section, TAA, StubSize,SectionKind::getData());
1279 Streamer.switchSection(S);
1280 Streamer.emitLabel(getContext().
1281 getOrCreateSymbol(StringRef("L_OBJC_IMAGE_INFO")));
1282 Streamer.emitInt32(VersionVal);
1283 Streamer.emitInt32(ImageInfoFlags);
1284 Streamer.addBlankLine();
1285}
1286
1287voidTargetLoweringObjectFileMachO::emitLinkerDirectives(MCStreamer &Streamer,
1288Module &M) const{
1289if (auto *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
1290for (constauto *Option : LinkerOptions->operands()) {
1291SmallVector<std::string, 4> StrOptions;
1292for (constauto &Piece : cast<MDNode>(Option)->operands())
1293 StrOptions.push_back(std::string(cast<MDString>(Piece)->getString()));
1294 Streamer.emitLinkerOptions(StrOptions);
1295 }
1296 }
1297}
1298
1299staticvoidcheckMachOComdat(constGlobalValue *GV) {
1300constComdat *C = GV->getComdat();
1301if (!C)
1302return;
1303
1304report_fatal_error("MachO doesn't support COMDATs, '" +C->getName() +
1305"' cannot be lowered.");
1306}
1307
1308MCSection *TargetLoweringObjectFileMachO::getExplicitSectionGlobal(
1309constGlobalObject *GO,SectionKind Kind,constTargetMachine &TM) const{
1310
1311StringRefSectionName =handlePragmaClangSection(GO, Kind);
1312
1313// Parse the section specifier and create it if valid.
1314StringRef Segment, Section;
1315unsigned TAA = 0, StubSize = 0;
1316bool TAAParsed;
1317
1318checkMachOComdat(GO);
1319
1320if (Error E =MCSectionMachO::ParseSectionSpecifier(
1321SectionName, Segment, Section, TAA, TAAParsed, StubSize)) {
1322// If invalid, report the error with report_fatal_error.
1323report_fatal_error("Global variable '" + GO->getName() +
1324"' has an invalid section specifier '" +
1325 GO->getSection() +"': " +toString(std::move(E)) +".");
1326 }
1327
1328// Get the section.
1329MCSectionMachO *S =
1330getContext().getMachOSection(Segment, Section, TAA, StubSize, Kind);
1331
1332// If TAA wasn't set by ParseSectionSpecifier() above,
1333// use the value returned by getMachOSection() as a default.
1334if (!TAAParsed)
1335 TAA = S->getTypeAndAttributes();
1336
1337// Okay, now that we got the section, verify that the TAA & StubSize agree.
1338// If the user declared multiple globals with different section flags, we need
1339// to reject it here.
1340if (S->getTypeAndAttributes() != TAA || S->getStubSize() != StubSize) {
1341// If invalid, report the error with report_fatal_error.
1342report_fatal_error("Global variable '" + GO->getName() +
1343"' section type or attributes does not match previous"
1344" section specifier");
1345 }
1346
1347return S;
1348}
1349
1350MCSection *TargetLoweringObjectFileMachO::SelectSectionForGlobal(
1351constGlobalObject *GO,SectionKind Kind,constTargetMachine &TM) const{
1352checkMachOComdat(GO);
1353
1354// Handle thread local data.
1355if (Kind.isThreadBSS())returnTLSBSSSection;
1356if (Kind.isThreadData())returnTLSDataSection;
1357
1358if (Kind.isText())
1359return GO->isWeakForLinker() ?TextCoalSection :TextSection;
1360
1361// If this is weak/linkonce, put this in a coalescable section, either in text
1362// or data depending on if it is writable.
1363if (GO->isWeakForLinker()) {
1364if (Kind.isReadOnly())
1365returnConstTextCoalSection;
1366if (Kind.isReadOnlyWithRel())
1367returnConstDataCoalSection;
1368returnDataCoalSection;
1369 }
1370
1371// FIXME: Alignment check should be handled by section classifier.
1372if (Kind.isMergeable1ByteCString() &&
1373 GO->getDataLayout().getPreferredAlign(
1374 cast<GlobalVariable>(GO)) <Align(32))
1375returnCStringSection;
1376
1377// Do not put 16-bit arrays in the UString section if they have an
1378// externally visible label, this runs into issues with certain linker
1379// versions.
1380if (Kind.isMergeable2ByteCString() && !GO->hasExternalLinkage() &&
1381 GO->getDataLayout().getPreferredAlign(
1382 cast<GlobalVariable>(GO)) <Align(32))
1383returnUStringSection;
1384
1385// With MachO only variables whose corresponding symbol starts with 'l' or
1386// 'L' can be merged, so we only try merging GVs with private linkage.
1387if (GO->hasPrivateLinkage() && Kind.isMergeableConst()) {
1388if (Kind.isMergeableConst4())
1389returnFourByteConstantSection;
1390if (Kind.isMergeableConst8())
1391returnEightByteConstantSection;
1392if (Kind.isMergeableConst16())
1393returnSixteenByteConstantSection;
1394 }
1395
1396// Otherwise, if it is readonly, but not something we can specially optimize,
1397// just drop it in .const.
1398if (Kind.isReadOnly())
1399returnReadOnlySection;
1400
1401// If this is marked const, put it into a const section. But if the dynamic
1402// linker needs to write to it, put it in the data segment.
1403if (Kind.isReadOnlyWithRel())
1404returnConstDataSection;
1405
1406// Put zero initialized globals with strong external linkage in the
1407// DATA, __common section with the .zerofill directive.
1408if (Kind.isBSSExtern())
1409returnDataCommonSection;
1410
1411// Put zero initialized globals with local linkage in __DATA,__bss directive
1412// with the .zerofill directive (aka .lcomm).
1413if (Kind.isBSSLocal())
1414returnDataBSSSection;
1415
1416// Otherwise, just drop the variable in the normal data section.
1417returnDataSection;
1418}
1419
1420MCSection *TargetLoweringObjectFileMachO::getSectionForConstant(
1421constDataLayout &DL,SectionKind Kind,constConstant *C,
1422Align &Alignment) const{
1423// If this constant requires a relocation, we have to put it in the data
1424// segment, not in the text segment.
1425if (Kind.isData() || Kind.isReadOnlyWithRel())
1426returnConstDataSection;
1427
1428if (Kind.isMergeableConst4())
1429returnFourByteConstantSection;
1430if (Kind.isMergeableConst8())
1431returnEightByteConstantSection;
1432if (Kind.isMergeableConst16())
1433returnSixteenByteConstantSection;
1434returnReadOnlySection;// .const
1435}
1436
1437MCSection *TargetLoweringObjectFileMachO::getSectionForCommandLines() const{
1438returngetContext().getMachOSection("__TEXT","__command_line", 0,
1439SectionKind::getReadOnly());
1440}
1441
1442constMCExpr *TargetLoweringObjectFileMachO::getTTypeGlobalReference(
1443constGlobalValue *GV,unsigned Encoding,constTargetMachine &TM,
1444MachineModuleInfo *MMI,MCStreamer &Streamer) const{
1445// The mach-o version of this method defaults to returning a stub reference.
1446
1447if (Encoding &DW_EH_PE_indirect) {
1448MachineModuleInfoMachO &MachOMMI =
1449 MMI->getObjFileInfo<MachineModuleInfoMachO>();
1450
1451MCSymbol *SSym =getSymbolWithGlobalValueBase(GV,"$non_lazy_ptr",TM);
1452
1453// Add information about the stub reference to MachOMMI so that the stub
1454// gets emitted by the asmprinter.
1455MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
1456if (!StubSym.getPointer()) {
1457MCSymbol *Sym =TM.getSymbol(GV);
1458 StubSym =MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
1459 }
1460
1461returnTargetLoweringObjectFile::
1462 getTTypeReference(MCSymbolRefExpr::create(SSym,getContext()),
1463 Encoding & ~DW_EH_PE_indirect, Streamer);
1464 }
1465
1466returnTargetLoweringObjectFile::getTTypeGlobalReference(GV, Encoding,TM,
1467 MMI, Streamer);
1468}
1469
1470MCSymbol *TargetLoweringObjectFileMachO::getCFIPersonalitySymbol(
1471constGlobalValue *GV,constTargetMachine &TM,
1472MachineModuleInfo *MMI) const{
1473// The mach-o version of this method defaults to returning a stub reference.
1474MachineModuleInfoMachO &MachOMMI =
1475 MMI->getObjFileInfo<MachineModuleInfoMachO>();
1476
1477MCSymbol *SSym =getSymbolWithGlobalValueBase(GV,"$non_lazy_ptr",TM);
1478
1479// Add information about the stub reference to MachOMMI so that the stub
1480// gets emitted by the asmprinter.
1481MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
1482if (!StubSym.getPointer()) {
1483MCSymbol *Sym =TM.getSymbol(GV);
1484 StubSym =MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
1485 }
1486
1487return SSym;
1488}
1489
1490constMCExpr *TargetLoweringObjectFileMachO::getIndirectSymViaGOTPCRel(
1491constGlobalValue *GV,constMCSymbol *Sym,constMCValue &MV,
1492 int64_tOffset,MachineModuleInfo *MMI,MCStreamer &Streamer) const{
1493// Although MachO 32-bit targets do not explicitly have a GOTPCREL relocation
1494// as 64-bit do, we replace the GOT equivalent by accessing the final symbol
1495// through a non_lazy_ptr stub instead. One advantage is that it allows the
1496// computation of deltas to final external symbols. Example:
1497//
1498// _extgotequiv:
1499// .long _extfoo
1500//
1501// _delta:
1502// .long _extgotequiv-_delta
1503//
1504// is transformed to:
1505//
1506// _delta:
1507// .long L_extfoo$non_lazy_ptr-(_delta+0)
1508//
1509// .section __IMPORT,__pointers,non_lazy_symbol_pointers
1510// L_extfoo$non_lazy_ptr:
1511// .indirect_symbol _extfoo
1512// .long 0
1513//
1514// The indirect symbol table (and sections of non_lazy_symbol_pointers type)
1515// may point to both local (same translation unit) and global (other
1516// translation units) symbols. Example:
1517//
1518// .section __DATA,__pointers,non_lazy_symbol_pointers
1519// L1:
1520// .indirect_symbol _myGlobal
1521// .long 0
1522// L2:
1523// .indirect_symbol _myLocal
1524// .long _myLocal
1525//
1526// If the symbol is local, instead of the symbol's index, the assembler
1527// places the constant INDIRECT_SYMBOL_LOCAL into the indirect symbol table.
1528// Then the linker will notice the constant in the table and will look at the
1529// content of the symbol.
1530MachineModuleInfoMachO &MachOMMI =
1531 MMI->getObjFileInfo<MachineModuleInfoMachO>();
1532MCContext &Ctx =getContext();
1533
1534// The offset must consider the original displacement from the base symbol
1535// since 32-bit targets don't have a GOTPCREL to fold the PC displacement.
1536Offset = -MV.getConstant();
1537constMCSymbol *BaseSym = &MV.getSymB()->getSymbol();
1538
1539// Access the final symbol via sym$non_lazy_ptr and generate the appropriated
1540// non_lazy_ptr stubs.
1541SmallString<128>Name;
1542StringRef Suffix ="$non_lazy_ptr";
1543Name += MMI->getModule()->getDataLayout().getPrivateGlobalPrefix();
1544Name +=Sym->getName();
1545Name += Suffix;
1546MCSymbol *Stub = Ctx.getOrCreateSymbol(Name);
1547
1548MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(Stub);
1549
1550if (!StubSym.getPointer())
1551 StubSym =MachineModuleInfoImpl::StubValueTy(const_cast<MCSymbol *>(Sym),
1552 !GV->hasLocalLinkage());
1553
1554constMCExpr *BSymExpr =
1555MCSymbolRefExpr::create(BaseSym,MCSymbolRefExpr::VK_None, Ctx);
1556constMCExpr *LHS =
1557MCSymbolRefExpr::create(Stub,MCSymbolRefExpr::VK_None, Ctx);
1558
1559if (!Offset)
1560returnMCBinaryExpr::createSub(LHS, BSymExpr, Ctx);
1561
1562constMCExpr *RHS =
1563MCBinaryExpr::createAdd(BSymExpr,MCConstantExpr::create(Offset, Ctx), Ctx);
1564returnMCBinaryExpr::createSub(LHS,RHS, Ctx);
1565}
1566
1567staticboolcanUsePrivateLabel(constMCAsmInfo &AsmInfo,
1568constMCSection &Section) {
1569if (!MCAsmInfoDarwin::isSectionAtomizableBySymbols(Section))
1570returntrue;
1571
1572// FIXME: we should be able to use private labels for sections that can't be
1573// dead-stripped (there's no issue with blocking atomization there), but `ld
1574// -r` sometimes drops the no_dead_strip attribute from sections so for safety
1575// we don't allow it.
1576returnfalse;
1577}
1578
1579voidTargetLoweringObjectFileMachO::getNameWithPrefix(
1580SmallVectorImpl<char> &OutName,constGlobalValue *GV,
1581constTargetMachine &TM) const{
1582bool CannotUsePrivateLabel =true;
1583if (auto *GO = GV->getAliaseeObject()) {
1584SectionKind GOKind =TargetLoweringObjectFile::getKindForGlobal(GO,TM);
1585constMCSection *TheSection =SectionForGlobal(GO, GOKind,TM);
1586 CannotUsePrivateLabel =
1587 !canUsePrivateLabel(*TM.getMCAsmInfo(), *TheSection);
1588 }
1589getMangler().getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
1590}
1591
1592//===----------------------------------------------------------------------===//
1593// COFF
1594//===----------------------------------------------------------------------===//
1595
1596staticunsigned
1597getCOFFSectionFlags(SectionKind K,constTargetMachine &TM) {
1598unsigned Flags = 0;
1599boolisThumb = TM.getTargetTriple().getArch() ==Triple::thumb;
1600
1601if (K.isMetadata())
1602 Flags |=
1603COFF::IMAGE_SCN_MEM_DISCARDABLE;
1604elseif (K.isExclude())
1605 Flags |=
1606COFF::IMAGE_SCN_LNK_REMOVE |COFF::IMAGE_SCN_MEM_DISCARDABLE;
1607elseif (K.isText())
1608 Flags |=
1609COFF::IMAGE_SCN_MEM_EXECUTE |
1610COFF::IMAGE_SCN_MEM_READ |
1611COFF::IMAGE_SCN_CNT_CODE |
1612 (isThumb ?COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0);
1613elseif (K.isBSS())
1614 Flags |=
1615COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
1616COFF::IMAGE_SCN_MEM_READ |
1617COFF::IMAGE_SCN_MEM_WRITE;
1618elseif (K.isThreadLocal())
1619 Flags |=
1620COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1621COFF::IMAGE_SCN_MEM_READ |
1622COFF::IMAGE_SCN_MEM_WRITE;
1623elseif (K.isReadOnly() || K.isReadOnlyWithRel())
1624 Flags |=
1625COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1626COFF::IMAGE_SCN_MEM_READ;
1627elseif (K.isWriteable())
1628 Flags |=
1629COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1630COFF::IMAGE_SCN_MEM_READ |
1631COFF::IMAGE_SCN_MEM_WRITE;
1632
1633return Flags;
1634}
1635
1636staticconstGlobalValue *getComdatGVForCOFF(constGlobalValue *GV) {
1637constComdat *C = GV->getComdat();
1638assert(C &&"expected GV to have a Comdat!");
1639
1640StringRef ComdatGVName =C->getName();
1641constGlobalValue *ComdatGV = GV->getParent()->getNamedValue(ComdatGVName);
1642if (!ComdatGV)
1643report_fatal_error("Associative COMDAT symbol '" + ComdatGVName +
1644"' does not exist.");
1645
1646if (ComdatGV->getComdat() !=C)
1647report_fatal_error("Associative COMDAT symbol '" + ComdatGVName +
1648"' is not a key for its COMDAT.");
1649
1650return ComdatGV;
1651}
1652
1653staticintgetSelectionForCOFF(constGlobalValue *GV) {
1654if (constComdat *C = GV->getComdat()) {
1655constGlobalValue *ComdatKey =getComdatGVForCOFF(GV);
1656if (constauto *GA = dyn_cast<GlobalAlias>(ComdatKey))
1657 ComdatKey = GA->getAliaseeObject();
1658if (ComdatKey == GV) {
1659switch (C->getSelectionKind()) {
1660caseComdat::Any:
1661returnCOFF::IMAGE_COMDAT_SELECT_ANY;
1662caseComdat::ExactMatch:
1663returnCOFF::IMAGE_COMDAT_SELECT_EXACT_MATCH;
1664caseComdat::Largest:
1665returnCOFF::IMAGE_COMDAT_SELECT_LARGEST;
1666caseComdat::NoDeduplicate:
1667returnCOFF::IMAGE_COMDAT_SELECT_NODUPLICATES;
1668caseComdat::SameSize:
1669returnCOFF::IMAGE_COMDAT_SELECT_SAME_SIZE;
1670 }
1671 }else {
1672returnCOFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE;
1673 }
1674 }
1675return 0;
1676}
1677
1678MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal(
1679constGlobalObject *GO,SectionKind Kind,constTargetMachine &TM) const{
1680StringRefName =handlePragmaClangSection(GO, Kind);
1681if (Name ==getInstrProfSectionName(IPSK_covmap,Triple::COFF,
1682/*AddSegmentInfo=*/false) ||
1683Name ==getInstrProfSectionName(IPSK_covfun,Triple::COFF,
1684/*AddSegmentInfo=*/false) ||
1685Name ==getInstrProfSectionName(IPSK_covdata,Triple::COFF,
1686/*AddSegmentInfo=*/false) ||
1687Name ==getInstrProfSectionName(IPSK_covname,Triple::COFF,
1688/*AddSegmentInfo=*/false))
1689 Kind =SectionKind::getMetadata();
1690intSelection = 0;
1691unsignedCharacteristics =getCOFFSectionFlags(Kind, TM);
1692StringRef COMDATSymName ="";
1693if (GO->hasComdat()) {
1694Selection =getSelectionForCOFF(GO);
1695constGlobalValue *ComdatGV;
1696if (Selection ==COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE)
1697 ComdatGV =getComdatGVForCOFF(GO);
1698else
1699 ComdatGV = GO;
1700
1701if (!ComdatGV->hasPrivateLinkage()) {
1702MCSymbol *Sym = TM.getSymbol(ComdatGV);
1703 COMDATSymName =Sym->getName();
1704Characteristics |=COFF::IMAGE_SCN_LNK_COMDAT;
1705 }else {
1706Selection = 0;
1707 }
1708 }
1709
1710returngetContext().getCOFFSection(Name,Characteristics, COMDATSymName,
1711Selection);
1712}
1713
1714staticStringRefgetCOFFSectionNameForUniqueGlobal(SectionKind Kind) {
1715if (Kind.isText())
1716return".text";
1717if (Kind.isBSS())
1718return".bss";
1719if (Kind.isThreadLocal())
1720return".tls$";
1721if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
1722return".rdata";
1723return".data";
1724}
1725
1726MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
1727constGlobalObject *GO,SectionKind Kind,constTargetMachine &TM) const{
1728// If we have -ffunction-sections then we should emit the global value to a
1729// uniqued section specifically for it.
1730bool EmitUniquedSection;
1731if (Kind.isText())
1732 EmitUniquedSection = TM.getFunctionSections();
1733else
1734 EmitUniquedSection = TM.getDataSections();
1735
1736if ((EmitUniquedSection && !Kind.isCommon()) || GO->hasComdat()) {
1737SmallString<256>Name =getCOFFSectionNameForUniqueGlobal(Kind);
1738
1739unsignedCharacteristics =getCOFFSectionFlags(Kind, TM);
1740
1741Characteristics |=COFF::IMAGE_SCN_LNK_COMDAT;
1742intSelection =getSelectionForCOFF(GO);
1743if (!Selection)
1744Selection =COFF::IMAGE_COMDAT_SELECT_NODUPLICATES;
1745constGlobalValue *ComdatGV;
1746if (GO->hasComdat())
1747 ComdatGV =getComdatGVForCOFF(GO);
1748else
1749 ComdatGV = GO;
1750
1751unsigned UniqueID =MCContext::GenericSectionID;
1752if (EmitUniquedSection)
1753 UniqueID = NextUniqueID++;
1754
1755if (!ComdatGV->hasPrivateLinkage()) {
1756MCSymbol *Sym = TM.getSymbol(ComdatGV);
1757StringRef COMDATSymName =Sym->getName();
1758
1759if (constauto *F = dyn_cast<Function>(GO))
1760if (std::optional<StringRef> Prefix =F->getSectionPrefix())
1761raw_svector_ostream(Name) <<'$' << *Prefix;
1762
1763// Append "$symbol" to the section name *before* IR-level mangling is
1764// applied when targetting mingw. This is what GCC does, and the ld.bfd
1765// COFF linker will not properly handle comdats otherwise.
1766if (getContext().getTargetTriple().isWindowsGNUEnvironment())
1767raw_svector_ostream(Name) <<'$' << ComdatGV->getName();
1768
1769returngetContext().getCOFFSection(Name,Characteristics, COMDATSymName,
1770Selection, UniqueID);
1771 }else {
1772SmallString<256> TmpData;
1773getMangler().getNameWithPrefix(TmpData, GO,/*CannotUsePrivateLabel=*/true);
1774returngetContext().getCOFFSection(Name,Characteristics, TmpData,
1775Selection, UniqueID);
1776 }
1777 }
1778
1779if (Kind.isText())
1780returnTextSection;
1781
1782if (Kind.isThreadLocal())
1783returnTLSDataSection;
1784
1785if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
1786returnReadOnlySection;
1787
1788// Note: we claim that common symbols are put in BSSSection, but they are
1789// really emitted with the magic .comm directive, which creates a symbol table
1790// entry but not a section.
1791if (Kind.isBSS() || Kind.isCommon())
1792returnBSSSection;
1793
1794returnDataSection;
1795}
1796
1797voidTargetLoweringObjectFileCOFF::getNameWithPrefix(
1798SmallVectorImpl<char> &OutName,constGlobalValue *GV,
1799constTargetMachine &TM) const{
1800bool CannotUsePrivateLabel =false;
1801if (GV->hasPrivateLinkage() &&
1802 ((isa<Function>(GV) && TM.getFunctionSections()) ||
1803 (isa<GlobalVariable>(GV) && TM.getDataSections())))
1804 CannotUsePrivateLabel =true;
1805
1806getMangler().getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
1807}
1808
1809MCSection *TargetLoweringObjectFileCOFF::getSectionForJumpTable(
1810constFunction &F,constTargetMachine &TM) const{
1811// If the function can be removed, produce a unique section so that
1812// the table doesn't prevent the removal.
1813constComdat *C =F.getComdat();
1814bool EmitUniqueSection = TM.getFunctionSections() ||C;
1815if (!EmitUniqueSection)
1816returnReadOnlySection;
1817
1818// FIXME: we should produce a symbol for F instead.
1819if (F.hasPrivateLinkage())
1820returnReadOnlySection;
1821
1822MCSymbol *Sym = TM.getSymbol(&F);
1823StringRef COMDATSymName =Sym->getName();
1824
1825SectionKind Kind =SectionKind::getReadOnly();
1826StringRef SecName =getCOFFSectionNameForUniqueGlobal(Kind);
1827unsignedCharacteristics =getCOFFSectionFlags(Kind, TM);
1828Characteristics |=COFF::IMAGE_SCN_LNK_COMDAT;
1829unsigned UniqueID = NextUniqueID++;
1830
1831returngetContext().getCOFFSection(SecName,Characteristics, COMDATSymName,
1832COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE,
1833 UniqueID);
1834}
1835
1836boolTargetLoweringObjectFileCOFF::shouldPutJumpTableInFunctionSection(
1837bool UsesLabelDifference,constFunction &F) const{
1838if (TM->getTargetTriple().getArch() ==Triple::x86_64) {
1839if (!JumpTableInFunctionSection) {
1840// We can always create relative relocations, so use another section
1841// that can be marked non-executable.
1842returnfalse;
1843 }
1844 }
1845returnTargetLoweringObjectFile::shouldPutJumpTableInFunctionSection(
1846 UsesLabelDifference,F);
1847}
1848
1849voidTargetLoweringObjectFileCOFF::emitModuleMetadata(MCStreamer &Streamer,
1850Module &M) const{
1851emitLinkerDirectives(Streamer, M);
1852
1853unsignedVersion = 0;
1854unsigned Flags = 0;
1855StringRef Section;
1856
1857GetObjCImageInfo(M,Version, Flags, Section);
1858if (!Section.empty()) {
1859auto &C =getContext();
1860auto *S =C.getCOFFSection(Section,COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1861COFF::IMAGE_SCN_MEM_READ);
1862 Streamer.switchSection(S);
1863 Streamer.emitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
1864 Streamer.emitInt32(Version);
1865 Streamer.emitInt32(Flags);
1866 Streamer.addBlankLine();
1867 }
1868
1869emitCGProfileMetadata(Streamer, M);
1870}
1871
1872voidTargetLoweringObjectFileCOFF::emitLinkerDirectives(
1873MCStreamer &Streamer,Module &M) const{
1874if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
1875// Emit the linker options to the linker .drectve section. According to the
1876// spec, this section is a space-separated string containing flags for
1877// linker.
1878MCSection *Sec =getDrectveSection();
1879 Streamer.switchSection(Sec);
1880for (constauto *Option : LinkerOptions->operands()) {
1881for (constauto &Piece : cast<MDNode>(Option)->operands()) {
1882// Lead with a space for consistency with our dllexport implementation.
1883 std::stringDirective(" ");
1884Directive.append(std::string(cast<MDString>(Piece)->getString()));
1885 Streamer.emitBytes(Directive);
1886 }
1887 }
1888 }
1889
1890// Emit /EXPORT: flags for each exported global as necessary.
1891 std::string Flags;
1892for (constGlobalValue &GV : M.global_values()) {
1893raw_string_ostreamOS(Flags);
1894emitLinkerFlagsForGlobalCOFF(OS, &GV,getContext().getTargetTriple(),
1895getMangler());
1896OS.flush();
1897if (!Flags.empty()) {
1898 Streamer.switchSection(getDrectveSection());
1899 Streamer.emitBytes(Flags);
1900 }
1901 Flags.clear();
1902 }
1903
1904// Emit /INCLUDE: flags for each used global as necessary.
1905if (constauto *LU = M.getNamedGlobal("llvm.used")) {
1906assert(LU->hasInitializer() &&"expected llvm.used to have an initializer");
1907assert(isa<ArrayType>(LU->getValueType()) &&
1908"expected llvm.used to be an array type");
1909if (constauto *A = cast<ConstantArray>(LU->getInitializer())) {
1910for (constValue *Op :A->operands()) {
1911constauto *GV = cast<GlobalValue>(Op->stripPointerCasts());
1912// Global symbols with internal or private linkage are not visible to
1913// the linker, and thus would cause an error when the linker tried to
1914// preserve the symbol due to the `/include:` directive.
1915if (GV->hasLocalLinkage())
1916continue;
1917
1918raw_string_ostreamOS(Flags);
1919emitLinkerFlagsForUsedCOFF(OS, GV,getContext().getTargetTriple(),
1920getMangler());
1921OS.flush();
1922
1923if (!Flags.empty()) {
1924 Streamer.switchSection(getDrectveSection());
1925 Streamer.emitBytes(Flags);
1926 }
1927 Flags.clear();
1928 }
1929 }
1930 }
1931}
1932
1933voidTargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx,
1934constTargetMachine &TM) {
1935TargetLoweringObjectFile::Initialize(Ctx, TM);
1936 this->TM = &TM;
1937constTriple &T = TM.getTargetTriple();
1938if (T.isWindowsMSVCEnvironment() ||T.isWindowsItaniumEnvironment()) {
1939StaticCtorSection =
1940 Ctx.getCOFFSection(".CRT$XCU",COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1941COFF::IMAGE_SCN_MEM_READ);
1942StaticDtorSection =
1943 Ctx.getCOFFSection(".CRT$XTX",COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1944COFF::IMAGE_SCN_MEM_READ);
1945 }else {
1946StaticCtorSection = Ctx.getCOFFSection(
1947".ctors",COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1948COFF::IMAGE_SCN_MEM_READ |COFF::IMAGE_SCN_MEM_WRITE);
1949StaticDtorSection = Ctx.getCOFFSection(
1950".dtors",COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1951COFF::IMAGE_SCN_MEM_READ |COFF::IMAGE_SCN_MEM_WRITE);
1952 }
1953}
1954
1955staticMCSectionCOFF *getCOFFStaticStructorSection(MCContext &Ctx,
1956constTriple &T,bool IsCtor,
1957unsigned Priority,
1958constMCSymbol *KeySym,
1959MCSectionCOFF *Default) {
1960if (T.isWindowsMSVCEnvironment() ||T.isWindowsItaniumEnvironment()) {
1961// If the priority is the default, use .CRT$XCU, possibly associative.
1962if (Priority == 65535)
1963return Ctx.getAssociativeCOFFSection(Default, KeySym, 0);
1964
1965// Otherwise, we need to compute a new section name. Low priorities should
1966// run earlier. The linker will sort sections ASCII-betically, and we need a
1967// string that sorts between .CRT$XCA and .CRT$XCU. In the general case, we
1968// make a name like ".CRT$XCT12345", since that runs before .CRT$XCU. Really
1969// low priorities need to sort before 'L', since the CRT uses that
1970// internally, so we use ".CRT$XCA00001" for them. We have a contract with
1971// the frontend that "init_seg(compiler)" corresponds to priority 200 and
1972// "init_seg(lib)" corresponds to priority 400, and those respectively use
1973// 'C' and 'L' without the priority suffix. Priorities between 200 and 400
1974// use 'C' with the priority as a suffix.
1975SmallString<24>Name;
1976char LastLetter ='T';
1977bool AddPrioritySuffix = Priority != 200 && Priority != 400;
1978if (Priority < 200)
1979 LastLetter ='A';
1980elseif (Priority < 400)
1981 LastLetter ='C';
1982elseif (Priority == 400)
1983 LastLetter ='L';
1984raw_svector_ostreamOS(Name);
1985OS <<".CRT$X" << (IsCtor ?"C" :"T") << LastLetter;
1986if (AddPrioritySuffix)
1987OS <<format("%05u", Priority);
1988MCSectionCOFF *Sec = Ctx.getCOFFSection(
1989Name,COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |COFF::IMAGE_SCN_MEM_READ);
1990return Ctx.getAssociativeCOFFSection(Sec, KeySym, 0);
1991 }
1992
1993 std::stringName = IsCtor ?".ctors" :".dtors";
1994if (Priority != 65535)
1995raw_string_ostream(Name) <<format(".%05u", 65535 - Priority);
1996
1997return Ctx.getAssociativeCOFFSection(
1998 Ctx.getCOFFSection(Name,COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1999COFF::IMAGE_SCN_MEM_READ |
2000COFF::IMAGE_SCN_MEM_WRITE),
2001 KeySym, 0);
2002}
2003
2004MCSection *TargetLoweringObjectFileCOFF::getStaticCtorSection(
2005unsigned Priority,constMCSymbol *KeySym) const{
2006returngetCOFFStaticStructorSection(
2007getContext(),getContext().getTargetTriple(),true, Priority, KeySym,
2008 cast<MCSectionCOFF>(StaticCtorSection));
2009}
2010
2011MCSection *TargetLoweringObjectFileCOFF::getStaticDtorSection(
2012unsigned Priority,constMCSymbol *KeySym) const{
2013returngetCOFFStaticStructorSection(
2014getContext(),getContext().getTargetTriple(),false, Priority, KeySym,
2015 cast<MCSectionCOFF>(StaticDtorSection));
2016}
2017
2018constMCExpr *TargetLoweringObjectFileCOFF::lowerRelativeReference(
2019constGlobalValue *LHS,constGlobalValue *RHS,
2020constTargetMachine &TM) const{
2021constTriple &T = TM.getTargetTriple();
2022if (T.isOSCygMing())
2023returnnullptr;
2024
2025// Our symbols should exist in address space zero, cowardly no-op if
2026// otherwise.
2027if (LHS->getType()->getPointerAddressSpace() != 0 ||
2028RHS->getType()->getPointerAddressSpace() != 0)
2029returnnullptr;
2030
2031// Both ptrtoint instructions must wrap global objects:
2032// - Only global variables are eligible for image relative relocations.
2033// - The subtrahend refers to the special symbol __ImageBase, a GlobalVariable.
2034// We expect __ImageBase to be a global variable without a section, externally
2035// defined.
2036//
2037// It should look something like this: @__ImageBase = external constant i8
2038if (!isa<GlobalObject>(LHS) || !isa<GlobalVariable>(RHS) ||
2039LHS->isThreadLocal() ||RHS->isThreadLocal() ||
2040RHS->getName() !="__ImageBase" || !RHS->hasExternalLinkage() ||
2041 cast<GlobalVariable>(RHS)->hasInitializer() ||RHS->hasSection())
2042returnnullptr;
2043
2044returnMCSymbolRefExpr::create(TM.getSymbol(LHS),
2045MCSymbolRefExpr::VK_COFF_IMGREL32,
2046getContext());
2047}
2048
2049static std::stringAPIntToHexString(constAPInt &AI) {
2050unsigned Width = (AI.getBitWidth() / 8) * 2;
2051 std::string HexString =toString(AI, 16,/*Signed=*/false);
2052llvm::transform(HexString, HexString.begin(), tolower);
2053unsignedSize = HexString.size();
2054assert(Width >=Size &&"hex string is too large!");
2055 HexString.insert(HexString.begin(), Width -Size,'0');
2056
2057return HexString;
2058}
2059
2060static std::stringscalarConstantToHexString(constConstant *C) {
2061Type *Ty =C->getType();
2062if (isa<UndefValue>(C)) {
2063returnAPIntToHexString(APInt::getZero(Ty->getPrimitiveSizeInBits()));
2064 }elseif (constauto *CFP = dyn_cast<ConstantFP>(C)) {
2065returnAPIntToHexString(CFP->getValueAPF().bitcastToAPInt());
2066 }elseif (constauto *CI = dyn_cast<ConstantInt>(C)) {
2067returnAPIntToHexString(CI->getValue());
2068 }else {
2069unsigned NumElements;
2070if (auto *VTy = dyn_cast<VectorType>(Ty))
2071 NumElements = cast<FixedVectorType>(VTy)->getNumElements();
2072else
2073 NumElements = Ty->getArrayNumElements();
2074 std::string HexString;
2075for (intI = NumElements - 1, E = -1;I != E; --I)
2076 HexString +=scalarConstantToHexString(C->getAggregateElement(I));
2077return HexString;
2078 }
2079}
2080
2081MCSection *TargetLoweringObjectFileCOFF::getSectionForConstant(
2082constDataLayout &DL,SectionKind Kind,constConstant *C,
2083Align &Alignment) const{
2084if (Kind.isMergeableConst() &&C &&
2085getContext().getAsmInfo()->hasCOFFComdatConstants()) {
2086// This creates comdat sections with the given symbol name, but unless
2087// AsmPrinter::GetCPISymbol actually makes the symbol global, the symbol
2088// will be created with a null storage class, which makes GNU binutils
2089// error out.
2090constunsignedCharacteristics =COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
2091COFF::IMAGE_SCN_MEM_READ |
2092COFF::IMAGE_SCN_LNK_COMDAT;
2093 std::string COMDATSymName;
2094if (Kind.isMergeableConst4()) {
2095if (Alignment <= 4) {
2096 COMDATSymName ="__real@" +scalarConstantToHexString(C);
2097 Alignment =Align(4);
2098 }
2099 }elseif (Kind.isMergeableConst8()) {
2100if (Alignment <= 8) {
2101 COMDATSymName ="__real@" +scalarConstantToHexString(C);
2102 Alignment =Align(8);
2103 }
2104 }elseif (Kind.isMergeableConst16()) {
2105// FIXME: These may not be appropriate for non-x86 architectures.
2106if (Alignment <= 16) {
2107 COMDATSymName ="__xmm@" +scalarConstantToHexString(C);
2108 Alignment =Align(16);
2109 }
2110 }elseif (Kind.isMergeableConst32()) {
2111if (Alignment <= 32) {
2112 COMDATSymName ="__ymm@" +scalarConstantToHexString(C);
2113 Alignment =Align(32);
2114 }
2115 }
2116
2117if (!COMDATSymName.empty())
2118returngetContext().getCOFFSection(".rdata",Characteristics,
2119 COMDATSymName,
2120COFF::IMAGE_COMDAT_SELECT_ANY);
2121 }
2122
2123returnTargetLoweringObjectFile::getSectionForConstant(DL, Kind,C,
2124 Alignment);
2125}
2126
2127//===----------------------------------------------------------------------===//
2128// Wasm
2129//===----------------------------------------------------------------------===//
2130
2131staticconstComdat *getWasmComdat(constGlobalValue *GV) {
2132constComdat *C = GV->getComdat();
2133if (!C)
2134returnnullptr;
2135
2136if (C->getSelectionKind() !=Comdat::Any)
2137report_fatal_error("WebAssembly COMDATs only support "
2138"SelectionKind::Any, '" +C->getName() +"' cannot be "
2139"lowered.");
2140
2141returnC;
2142}
2143
2144staticunsignedgetWasmSectionFlags(SectionKind K,bool Retain) {
2145unsigned Flags = 0;
2146
2147if (K.isThreadLocal())
2148 Flags |=wasm::WASM_SEG_FLAG_TLS;
2149
2150if (K.isMergeableCString())
2151 Flags |=wasm::WASM_SEG_FLAG_STRINGS;
2152
2153if (Retain)
2154 Flags |=wasm::WASM_SEG_FLAG_RETAIN;
2155
2156// TODO(sbc): Add suport for K.isMergeableConst()
2157
2158return Flags;
2159}
2160
2161voidTargetLoweringObjectFileWasm::getModuleMetadata(Module &M) {
2162SmallVector<GlobalValue *, 4> Vec;
2163collectUsedGlobalVariables(M, Vec,false);
2164for (GlobalValue *GV : Vec)
2165if (auto *GO = dyn_cast<GlobalObject>(GV))
2166 Used.insert(GO);
2167}
2168
2169MCSection *TargetLoweringObjectFileWasm::getExplicitSectionGlobal(
2170constGlobalObject *GO,SectionKind Kind,constTargetMachine &TM) const{
2171// We don't support explict section names for functions in the wasm object
2172// format. Each function has to be in its own unique section.
2173if (isa<Function>(GO)) {
2174returnSelectSectionForGlobal(GO, Kind,TM);
2175 }
2176
2177StringRefName = GO->getSection();
2178
2179// Certain data sections we treat as named custom sections rather than
2180// segments within the data section.
2181// This could be avoided if all data segements (the wasm sense) were
2182// represented as their own sections (in the llvm sense).
2183// TODO(sbc): https://github.com/WebAssembly/tool-conventions/issues/138
2184if (Name ==getInstrProfSectionName(IPSK_covmap,Triple::Wasm,
2185/*AddSegmentInfo=*/false) ||
2186Name ==getInstrProfSectionName(IPSK_covfun,Triple::Wasm,
2187/*AddSegmentInfo=*/false) ||
2188Name ==".llvmbc" ||Name ==".llvmcmd")
2189 Kind =SectionKind::getMetadata();
2190
2191StringRef Group ="";
2192if (constComdat *C =getWasmComdat(GO)) {
2193 Group =C->getName();
2194 }
2195
2196unsigned Flags =getWasmSectionFlags(Kind, Used.count(GO));
2197MCSectionWasm *Section =getContext().getWasmSection(
2198Name, Kind, Flags, Group,MCContext::GenericSectionID);
2199
2200return Section;
2201}
2202
2203staticMCSectionWasm *
2204selectWasmSectionForGlobal(MCContext &Ctx,constGlobalObject *GO,
2205SectionKind Kind,Mangler &Mang,
2206constTargetMachine &TM,bool EmitUniqueSection,
2207unsigned *NextUniqueID,bool Retain) {
2208StringRef Group ="";
2209if (constComdat *C =getWasmComdat(GO)) {
2210 Group =C->getName();
2211 }
2212
2213bool UniqueSectionNames = TM.getUniqueSectionNames();
2214SmallString<128>Name =getSectionPrefixForGlobal(Kind,/*IsLarge=*/false);
2215
2216if (constauto *F = dyn_cast<Function>(GO)) {
2217constauto &OptionalPrefix =F->getSectionPrefix();
2218if (OptionalPrefix)
2219raw_svector_ostream(Name) <<'.' << *OptionalPrefix;
2220 }
2221
2222if (EmitUniqueSection && UniqueSectionNames) {
2223Name.push_back('.');
2224 TM.getNameWithPrefix(Name, GO, Mang,true);
2225 }
2226unsigned UniqueID =MCContext::GenericSectionID;
2227if (EmitUniqueSection && !UniqueSectionNames) {
2228 UniqueID = *NextUniqueID;
2229 (*NextUniqueID)++;
2230 }
2231
2232unsigned Flags =getWasmSectionFlags(Kind, Retain);
2233return Ctx.getWasmSection(Name, Kind, Flags, Group, UniqueID);
2234}
2235
2236MCSection *TargetLoweringObjectFileWasm::SelectSectionForGlobal(
2237constGlobalObject *GO,SectionKind Kind,constTargetMachine &TM) const{
2238
2239if (Kind.isCommon())
2240report_fatal_error("mergable sections not supported yet on wasm");
2241
2242// If we have -ffunction-section or -fdata-section then we should emit the
2243// global value to a uniqued section specifically for it.
2244bool EmitUniqueSection =false;
2245if (Kind.isText())
2246 EmitUniqueSection =TM.getFunctionSections();
2247else
2248 EmitUniqueSection =TM.getDataSections();
2249 EmitUniqueSection |= GO->hasComdat();
2250bool Retain = Used.count(GO);
2251 EmitUniqueSection |= Retain;
2252
2253returnselectWasmSectionForGlobal(getContext(), GO, Kind,getMangler(),TM,
2254 EmitUniqueSection, &NextUniqueID, Retain);
2255}
2256
2257boolTargetLoweringObjectFileWasm::shouldPutJumpTableInFunctionSection(
2258bool UsesLabelDifference,constFunction &F) const{
2259// We can always create relative relocations, so use another section
2260// that can be marked non-executable.
2261returnfalse;
2262}
2263
2264constMCExpr *TargetLoweringObjectFileWasm::lowerRelativeReference(
2265constGlobalValue *LHS,constGlobalValue *RHS,
2266constTargetMachine &TM) const{
2267// We may only use a PLT-relative relocation to refer to unnamed_addr
2268// functions.
2269if (!LHS->hasGlobalUnnamedAddr() || !LHS->getValueType()->isFunctionTy())
2270returnnullptr;
2271
2272// Basic correctness checks.
2273if (LHS->getType()->getPointerAddressSpace() != 0 ||
2274RHS->getType()->getPointerAddressSpace() != 0 ||LHS->isThreadLocal() ||
2275RHS->isThreadLocal())
2276returnnullptr;
2277
2278returnMCBinaryExpr::createSub(
2279MCSymbolRefExpr::create(TM.getSymbol(LHS),MCSymbolRefExpr::VK_None,
2280getContext()),
2281MCSymbolRefExpr::create(TM.getSymbol(RHS),getContext()),getContext());
2282}
2283
2284voidTargetLoweringObjectFileWasm::InitializeWasm() {
2285StaticCtorSection =
2286getContext().getWasmSection(".init_array",SectionKind::getData());
2287
2288// We don't use PersonalityEncoding and LSDAEncoding because we don't emit
2289// .cfi directives. We use TTypeEncoding to encode typeinfo global variables.
2290TTypeEncoding =dwarf::DW_EH_PE_absptr;
2291}
2292
2293MCSection *TargetLoweringObjectFileWasm::getStaticCtorSection(
2294unsigned Priority,constMCSymbol *KeySym) const{
2295return Priority == UINT16_MAX ?
2296StaticCtorSection :
2297getContext().getWasmSection(".init_array." + utostr(Priority),
2298SectionKind::getData());
2299}
2300
2301MCSection *TargetLoweringObjectFileWasm::getStaticDtorSection(
2302unsigned Priority,constMCSymbol *KeySym) const{
2303report_fatal_error("@llvm.global_dtors should have been lowered already");
2304}
2305
2306//===----------------------------------------------------------------------===//
2307// XCOFF
2308//===----------------------------------------------------------------------===//
2309boolTargetLoweringObjectFileXCOFF::ShouldEmitEHBlock(
2310constMachineFunction *MF) {
2311if (!MF->getLandingPads().empty())
2312returntrue;
2313
2314constFunction &F = MF->getFunction();
2315if (!F.hasPersonalityFn() || !F.needsUnwindTableEntry())
2316returnfalse;
2317
2318constGlobalValue *Per =
2319 dyn_cast<GlobalValue>(F.getPersonalityFn()->stripPointerCasts());
2320assert(Per &&"Personality routine is not a GlobalValue type.");
2321if (isNoOpWithoutInvoke(classifyEHPersonality(Per)))
2322returnfalse;
2323
2324returntrue;
2325}
2326
2327boolTargetLoweringObjectFileXCOFF::ShouldSetSSPCanaryBitInTB(
2328constMachineFunction *MF) {
2329constFunction &F = MF->getFunction();
2330if (!F.hasStackProtectorFnAttr())
2331returnfalse;
2332// FIXME: check presence of canary word
2333// There are cases that the stack protectors are not really inserted even if
2334// the attributes are on.
2335returntrue;
2336}
2337
2338MCSymbol *
2339TargetLoweringObjectFileXCOFF::getEHInfoTableSymbol(constMachineFunction *MF) {
2340MCSymbol *EHInfoSym = MF->getContext().getOrCreateSymbol(
2341"__ehinfo." +Twine(MF->getFunctionNumber()));
2342 cast<MCSymbolXCOFF>(EHInfoSym)->setEHInfo();
2343return EHInfoSym;
2344}
2345
2346MCSymbol *
2347TargetLoweringObjectFileXCOFF::getTargetSymbol(constGlobalValue *GV,
2348constTargetMachine &TM) const{
2349// We always use a qualname symbol for a GV that represents
2350// a declaration, a function descriptor, or a common symbol.
2351// If a GV represents a GlobalVariable and -fdata-sections is enabled, we
2352// also return a qualname so that a label symbol could be avoided.
2353// It is inherently ambiguous when the GO represents the address of a
2354// function, as the GO could either represent a function descriptor or a
2355// function entry point. We choose to always return a function descriptor
2356// here.
2357if (constGlobalObject *GO = dyn_cast<GlobalObject>(GV)) {
2358if (GO->isDeclarationForLinker())
2359return cast<MCSectionXCOFF>(getSectionForExternalReference(GO,TM))
2360 ->getQualNameSymbol();
2361
2362if (constGlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
2363if (GVar->hasAttribute("toc-data"))
2364return cast<MCSectionXCOFF>(
2365SectionForGlobal(GVar,SectionKind::getData(),TM))
2366 ->getQualNameSymbol();
2367
2368SectionKind GOKind =getKindForGlobal(GO,TM);
2369if (GOKind.isText())
2370return cast<MCSectionXCOFF>(
2371getSectionForFunctionDescriptor(cast<Function>(GO),TM))
2372 ->getQualNameSymbol();
2373if ((TM.getDataSections() && !GO->hasSection()) || GO->hasCommonLinkage() ||
2374 GOKind.isBSSLocal() || GOKind.isThreadBSSLocal())
2375return cast<MCSectionXCOFF>(SectionForGlobal(GO, GOKind,TM))
2376 ->getQualNameSymbol();
2377 }
2378
2379// For all other cases, fall back to getSymbol to return the unqualified name.
2380returnnullptr;
2381}
2382
2383MCSection *TargetLoweringObjectFileXCOFF::getExplicitSectionGlobal(
2384constGlobalObject *GO,SectionKind Kind,constTargetMachine &TM) const{
2385if (!GO->hasSection())
2386report_fatal_error("#pragma clang section is not yet supported");
2387
2388StringRefSectionName = GO->getSection();
2389
2390// Handle the XCOFF::TD case first, then deal with the rest.
2391if (constGlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
2392if (GVar->hasAttribute("toc-data"))
2393returngetContext().getXCOFFSection(
2394SectionName, Kind,
2395XCOFF::CsectProperties(/*MappingClass*/XCOFF::XMC_TD,XCOFF::XTY_SD),
2396/* MultiSymbolsAllowed*/true);
2397
2398XCOFF::StorageMappingClass MappingClass;
2399if (Kind.isText())
2400 MappingClass =XCOFF::XMC_PR;
2401elseif (Kind.isData() || Kind.isBSS())
2402 MappingClass =XCOFF::XMC_RW;
2403elseif (Kind.isReadOnlyWithRel())
2404 MappingClass =
2405TM.Options.XCOFFReadOnlyPointers ?XCOFF::XMC_RO :XCOFF::XMC_RW;
2406elseif (Kind.isReadOnly())
2407 MappingClass =XCOFF::XMC_RO;
2408else
2409report_fatal_error("XCOFF other section types not yet implemented.");
2410
2411returngetContext().getXCOFFSection(
2412SectionName, Kind,XCOFF::CsectProperties(MappingClass,XCOFF::XTY_SD),
2413/* MultiSymbolsAllowed*/true);
2414}
2415
2416MCSection *TargetLoweringObjectFileXCOFF::getSectionForExternalReference(
2417constGlobalObject *GO,constTargetMachine &TM) const{
2418assert(GO->isDeclarationForLinker() &&
2419"Tried to get ER section for a defined global.");
2420
2421SmallString<128>Name;
2422getNameWithPrefix(Name, GO,TM);
2423
2424// AIX TLS local-dynamic does not need the external reference for the
2425// "_$TLSML" symbol.
2426if (GO->getThreadLocalMode() ==GlobalVariable::LocalDynamicTLSModel &&
2427 GO->hasName() && GO->getName() =="_$TLSML") {
2428returngetContext().getXCOFFSection(
2429Name,SectionKind::getData(),
2430XCOFF::CsectProperties(XCOFF::XMC_TC,XCOFF::XTY_SD));
2431 }
2432
2433XCOFF::StorageMappingClass SMC =
2434 isa<Function>(GO) ?XCOFF::XMC_DS :XCOFF::XMC_UA;
2435if (GO->isThreadLocal())
2436 SMC =XCOFF::XMC_UL;
2437
2438if (constGlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
2439if (GVar->hasAttribute("toc-data"))
2440 SMC =XCOFF::XMC_TD;
2441
2442// Externals go into a csect of type ER.
2443returngetContext().getXCOFFSection(
2444Name,SectionKind::getMetadata(),
2445XCOFF::CsectProperties(SMC,XCOFF::XTY_ER));
2446}
2447
2448MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
2449constGlobalObject *GO,SectionKind Kind,constTargetMachine &TM) const{
2450// Handle the XCOFF::TD case first, then deal with the rest.
2451if (constGlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
2452if (GVar->hasAttribute("toc-data")) {
2453SmallString<128>Name;
2454getNameWithPrefix(Name, GO,TM);
2455XCOFF::SymbolType symType =
2456 GO->hasCommonLinkage() ?XCOFF::XTY_CM :XCOFF::XTY_SD;
2457returngetContext().getXCOFFSection(
2458Name, Kind,XCOFF::CsectProperties(XCOFF::XMC_TD, symType),
2459/* MultiSymbolsAllowed*/true);
2460 }
2461
2462// Common symbols go into a csect with matching name which will get mapped
2463// into the .bss section.
2464// Zero-initialized local TLS symbols go into a csect with matching name which
2465// will get mapped into the .tbss section.
2466if (Kind.isBSSLocal() || GO->hasCommonLinkage() || Kind.isThreadBSSLocal()) {
2467SmallString<128>Name;
2468getNameWithPrefix(Name, GO,TM);
2469XCOFF::StorageMappingClass SMC = Kind.isBSSLocal() ?XCOFF::XMC_BS
2470 : Kind.isCommon() ?XCOFF::XMC_RW
2471 :XCOFF::XMC_UL;
2472returngetContext().getXCOFFSection(
2473Name, Kind,XCOFF::CsectProperties(SMC,XCOFF::XTY_CM));
2474 }
2475
2476if (Kind.isText()) {
2477if (TM.getFunctionSections()) {
2478return cast<MCSymbolXCOFF>(getFunctionEntryPointSymbol(GO,TM))
2479 ->getRepresentedCsect();
2480 }
2481returnTextSection;
2482 }
2483
2484if (TM.Options.XCOFFReadOnlyPointers && Kind.isReadOnlyWithRel()) {
2485if (!TM.getDataSections())
2486report_fatal_error(
2487"ReadOnlyPointers is supported only if data sections is turned on");
2488
2489SmallString<128>Name;
2490getNameWithPrefix(Name, GO,TM);
2491returngetContext().getXCOFFSection(
2492Name,SectionKind::getReadOnly(),
2493XCOFF::CsectProperties(XCOFF::XMC_RO,XCOFF::XTY_SD));
2494 }
2495
2496// For BSS kind, zero initialized data must be emitted to the .data section
2497// because external linkage control sections that get mapped to the .bss
2498// section will be linked as tentative defintions, which is only appropriate
2499// for SectionKind::Common.
2500if (Kind.isData() || Kind.isReadOnlyWithRel() || Kind.isBSS()) {
2501if (TM.getDataSections()) {
2502SmallString<128>Name;
2503getNameWithPrefix(Name, GO,TM);
2504returngetContext().getXCOFFSection(
2505Name,SectionKind::getData(),
2506XCOFF::CsectProperties(XCOFF::XMC_RW,XCOFF::XTY_SD));
2507 }
2508returnDataSection;
2509 }
2510
2511if (Kind.isReadOnly()) {
2512if (TM.getDataSections()) {
2513SmallString<128>Name;
2514getNameWithPrefix(Name, GO,TM);
2515returngetContext().getXCOFFSection(
2516Name,SectionKind::getReadOnly(),
2517XCOFF::CsectProperties(XCOFF::XMC_RO,XCOFF::XTY_SD));
2518 }
2519returnReadOnlySection;
2520 }
2521
2522// External/weak TLS data and initialized local TLS data are not eligible
2523// to be put into common csect. If data sections are enabled, thread
2524// data are emitted into separate sections. Otherwise, thread data
2525// are emitted into the .tdata section.
2526if (Kind.isThreadLocal()) {
2527if (TM.getDataSections()) {
2528SmallString<128>Name;
2529getNameWithPrefix(Name, GO,TM);
2530returngetContext().getXCOFFSection(
2531Name, Kind,XCOFF::CsectProperties(XCOFF::XMC_TL,XCOFF::XTY_SD));
2532 }
2533returnTLSDataSection;
2534 }
2535
2536report_fatal_error("XCOFF other section types not yet implemented.");
2537}
2538
2539MCSection *TargetLoweringObjectFileXCOFF::getSectionForJumpTable(
2540constFunction &F,constTargetMachine &TM) const{
2541assert (!F.getComdat() &&"Comdat not supported on XCOFF.");
2542
2543if (!TM.getFunctionSections())
2544returnReadOnlySection;
2545
2546// If the function can be removed, produce a unique section so that
2547// the table doesn't prevent the removal.
2548SmallString<128> NameStr(".rodata.jmp..");
2549getNameWithPrefix(NameStr, &F,TM);
2550returngetContext().getXCOFFSection(
2551 NameStr,SectionKind::getReadOnly(),
2552XCOFF::CsectProperties(XCOFF::XMC_RO,XCOFF::XTY_SD));
2553}
2554
2555boolTargetLoweringObjectFileXCOFF::shouldPutJumpTableInFunctionSection(
2556bool UsesLabelDifference,constFunction &F) const{
2557returnfalse;
2558}
2559
2560/// Given a mergeable constant with the specified size and relocation
2561/// information, return a section that it should be placed in.
2562MCSection *TargetLoweringObjectFileXCOFF::getSectionForConstant(
2563constDataLayout &DL,SectionKind Kind,constConstant *C,
2564Align &Alignment) const{
2565// TODO: Enable emiting constant pool to unique sections when we support it.
2566if (Alignment >Align(16))
2567report_fatal_error("Alignments greater than 16 not yet supported.");
2568
2569if (Alignment ==Align(8)) {
2570assert(ReadOnly8Section &&"Section should always be initialized.");
2571returnReadOnly8Section;
2572 }
2573
2574if (Alignment ==Align(16)) {
2575assert(ReadOnly16Section &&"Section should always be initialized.");
2576returnReadOnly16Section;
2577 }
2578
2579returnReadOnlySection;
2580}
2581
2582voidTargetLoweringObjectFileXCOFF::Initialize(MCContext &Ctx,
2583constTargetMachine &TgtM) {
2584TargetLoweringObjectFile::Initialize(Ctx, TgtM);
2585TTypeEncoding =
2586dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_datarel |
2587 (TgtM.getTargetTriple().isArch32Bit() ?dwarf::DW_EH_PE_sdata4
2588 :dwarf::DW_EH_PE_sdata8);
2589PersonalityEncoding = 0;
2590LSDAEncoding = 0;
2591CallSiteEncoding =dwarf::DW_EH_PE_udata4;
2592
2593// AIX debug for thread local location is not ready. And for integrated as
2594// mode, the relocatable address for the thread local variable will cause
2595// linker error. So disable the location attribute generation for thread local
2596// variables for now.
2597// FIXME: when TLS debug on AIX is ready, remove this setting.
2598SupportDebugThreadLocalLocation =false;
2599}
2600
2601MCSection *TargetLoweringObjectFileXCOFF::getStaticCtorSection(
2602unsigned Priority,constMCSymbol *KeySym) const{
2603report_fatal_error("no static constructor section on AIX");
2604}
2605
2606MCSection *TargetLoweringObjectFileXCOFF::getStaticDtorSection(
2607unsigned Priority,constMCSymbol *KeySym) const{
2608report_fatal_error("no static destructor section on AIX");
2609}
2610
2611constMCExpr *TargetLoweringObjectFileXCOFF::lowerRelativeReference(
2612constGlobalValue *LHS,constGlobalValue *RHS,
2613constTargetMachine &TM) const{
2614/* Not implemented yet, but don't crash, return nullptr. */
2615returnnullptr;
2616}
2617
2618XCOFF::StorageClass
2619TargetLoweringObjectFileXCOFF::getStorageClassForGlobal(constGlobalValue *GV) {
2620assert(!isa<GlobalIFunc>(GV) &&"GlobalIFunc is not supported on AIX.");
2621
2622switch (GV->getLinkage()) {
2623caseGlobalValue::InternalLinkage:
2624caseGlobalValue::PrivateLinkage:
2625returnXCOFF::C_HIDEXT;
2626caseGlobalValue::ExternalLinkage:
2627caseGlobalValue::CommonLinkage:
2628caseGlobalValue::AvailableExternallyLinkage:
2629returnXCOFF::C_EXT;
2630caseGlobalValue::ExternalWeakLinkage:
2631caseGlobalValue::LinkOnceAnyLinkage:
2632caseGlobalValue::LinkOnceODRLinkage:
2633caseGlobalValue::WeakAnyLinkage:
2634caseGlobalValue::WeakODRLinkage:
2635returnXCOFF::C_WEAKEXT;
2636caseGlobalValue::AppendingLinkage:
2637report_fatal_error(
2638"There is no mapping that implements AppendingLinkage for XCOFF.");
2639 }
2640llvm_unreachable("Unknown linkage type!");
2641}
2642
2643MCSymbol *TargetLoweringObjectFileXCOFF::getFunctionEntryPointSymbol(
2644constGlobalValue *Func,constTargetMachine &TM) const{
2645assert((isa<Function>(Func) ||
2646 (isa<GlobalAlias>(Func) &&
2647 isa_and_nonnull<Function>(
2648 cast<GlobalAlias>(Func)->getAliaseeObject()))) &&
2649"Func must be a function or an alias which has a function as base "
2650"object.");
2651
2652SmallString<128> NameStr;
2653 NameStr.push_back('.');
2654getNameWithPrefix(NameStr, Func,TM);
2655
2656// When -function-sections is enabled and explicit section is not specified,
2657// it's not necessary to emit function entry point label any more. We will use
2658// function entry point csect instead. And for function delcarations, the
2659// undefined symbols gets treated as csect with XTY_ER property.
2660if (((TM.getFunctionSections() && !Func->hasSection()) ||
2661 Func->isDeclarationForLinker()) &&
2662 isa<Function>(Func)) {
2663returngetContext()
2664 .getXCOFFSection(
2665 NameStr,SectionKind::getText(),
2666XCOFF::CsectProperties(XCOFF::XMC_PR, Func->isDeclarationForLinker()
2667 ?XCOFF::XTY_ER
2668 :XCOFF::XTY_SD))
2669 ->getQualNameSymbol();
2670 }
2671
2672returngetContext().getOrCreateSymbol(NameStr);
2673}
2674
2675MCSection *TargetLoweringObjectFileXCOFF::getSectionForFunctionDescriptor(
2676constFunction *F,constTargetMachine &TM) const{
2677SmallString<128> NameStr;
2678getNameWithPrefix(NameStr,F,TM);
2679returngetContext().getXCOFFSection(
2680 NameStr,SectionKind::getData(),
2681XCOFF::CsectProperties(XCOFF::XMC_DS,XCOFF::XTY_SD));
2682}
2683
2684MCSection *TargetLoweringObjectFileXCOFF::getSectionForTOCEntry(
2685constMCSymbol *Sym,constTargetMachine &TM) const{
2686constXCOFF::StorageMappingClass SMC = [](constMCSymbol *Sym,
2687constTargetMachine &TM) {
2688constMCSymbolXCOFF *XSym = cast<MCSymbolXCOFF>(Sym);
2689
2690// The "_$TLSML" symbol for TLS local-dynamic mode requires XMC_TC,
2691// otherwise the AIX assembler will complain.
2692if (XSym->getSymbolTableName() =="_$TLSML")
2693returnXCOFF::XMC_TC;
2694
2695// Use large code model toc entries for ehinfo symbols as they are
2696// never referenced directly. The runtime loads their TOC entry
2697// addresses from the trace-back table.
2698if (XSym->isEHInfo())
2699returnXCOFF::XMC_TE;
2700
2701// If the symbol does not have a code model specified use the module value.
2702if (!XSym->hasPerSymbolCodeModel())
2703returnTM.getCodeModel() ==CodeModel::Large ?XCOFF::XMC_TE
2704 :XCOFF::XMC_TC;
2705
2706return XSym->getPerSymbolCodeModel() ==MCSymbolXCOFF::CM_Large
2707 ?XCOFF::XMC_TE
2708 :XCOFF::XMC_TC;
2709 }(Sym,TM);
2710
2711returngetContext().getXCOFFSection(
2712 cast<MCSymbolXCOFF>(Sym)->getSymbolTableName(),SectionKind::getData(),
2713XCOFF::CsectProperties(SMC,XCOFF::XTY_SD));
2714}
2715
2716MCSection *TargetLoweringObjectFileXCOFF::getSectionForLSDA(
2717constFunction &F,constMCSymbol &FnSym,constTargetMachine &TM) const{
2718auto *LSDA = cast<MCSectionXCOFF>(LSDASection);
2719if (TM.getFunctionSections()) {
2720// If option -ffunction-sections is on, append the function name to the
2721// name of the LSDA csect so that each function has its own LSDA csect.
2722// This helps the linker to garbage-collect EH info of unused functions.
2723SmallString<128> NameStr = LSDA->getName();
2724raw_svector_ostream(NameStr) <<'.' <<F.getName();
2725 LSDA =getContext().getXCOFFSection(NameStr, LSDA->getKind(),
2726 LSDA->getCsectProp());
2727 }
2728return LSDA;
2729}
2730//===----------------------------------------------------------------------===//
2731// GOFF
2732//===----------------------------------------------------------------------===//
2733TargetLoweringObjectFileGOFF::TargetLoweringObjectFileGOFF() =default;
2734
2735MCSection *TargetLoweringObjectFileGOFF::getExplicitSectionGlobal(
2736constGlobalObject *GO,SectionKind Kind,constTargetMachine &TM) const{
2737returnSelectSectionForGlobal(GO, Kind,TM);
2738}
2739
2740MCSection *TargetLoweringObjectFileGOFF::getSectionForLSDA(
2741constFunction &F,constMCSymbol &FnSym,constTargetMachine &TM) const{
2742 std::stringName =".gcc_exception_table." +F.getName().str();
2743returngetContext().getGOFFSection(Name,SectionKind::getData(),nullptr, 0);
2744}
2745
2746MCSection *TargetLoweringObjectFileGOFF::SelectSectionForGlobal(
2747constGlobalObject *GO,SectionKind Kind,constTargetMachine &TM) const{
2748auto *Symbol =TM.getSymbol(GO);
2749if (Kind.isBSS())
2750returngetContext().getGOFFSection(Symbol->getName(),SectionKind::getBSS(),
2751nullptr, 0);
2752
2753returngetContext().getObjectFileInfo()->getTextSection();
2754}
Selection
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
Definition:AMDGPUISelDAGToDAG.cpp:110
isThumb
static bool isThumb(const MCSubtargetInfo &STI)
Definition:ARMAsmPrinter.cpp:483
MBB
MachineBasicBlock & MBB
Definition:ARMSLSHardening.cpp:71
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition:ARMSLSHardening.cpp:73
print
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
Definition:ArchiveWriter.cpp:205
Base64.h
BasicBlockSectionUtils.h
COFF.h
ELF.h
MachO.h
Wasm.h
A
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Characteristics
COFFYAML::WeakExternalCharacteristics Characteristics
Definition:COFFYAML.cpp:350
Casting.h
CodeGen.h
Constants.h
This file contains the declarations for the subclasses of Constant, which represent the different fla...
DataLayout.h
DerivedTypes.h
DiagnosticInfo.h
DiagnosticPrinter.h
Dwarf.h
This file contains constants used for implementing Dwarf debug support.
Name
std::string Name
Definition:ELFObjHandler.cpp:77
Size
uint64_t Size
Definition:ELFObjHandler.cpp:81
Sym
Symbol * Sym
Definition:ELF_riscv.cpp:479
Format.h
GlobalAlias.h
GlobalObject.h
GlobalValue.h
GlobalVariable.h
Function.h
Module.h
Module.h This file contains the declarations for the Module class.
Type.h
InstrProf.h
MCAsmInfoDarwin.h
MCAsmInfo.h
MCContext.h
MCExpr.h
MCSectionCOFF.h
MCSectionELF.h
MCSectionGOFF.h
This file declares the MCSectionGOFF class, which contains all of the necessary machine code sections...
MCSectionMachO.h
MCSectionWasm.h
MCSectionXCOFF.h
MCStreamer.h
MCSymbolELF.h
MCSymbol.h
MCValue.h
F
#define F(x, y, z)
Definition:MD5.cpp:55
I
#define I(x, y, z)
Definition:MD5.cpp:58
MachineBasicBlock.h
MachineFunction.h
MachineModuleInfoImpls.h
MachineModuleInfo.h
Mangler.h
Metadata.h
This file contains the declarations for metadata subclasses.
PseudoProbe.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OS
raw_pwrite_stream & OS
Definition:SampleProfWriter.cpp:51
SectionKind.h
SmallString.h
This file defines the SmallString class.
SmallVector.h
This file defines the SmallVector class.
StringExtras.h
This file contains some functions that are useful when dealing with strings.
StringRef.h
canUsePrivateLabel
static bool canUsePrivateLabel(const MCAsmInfo &AsmInfo, const MCSection &Section)
Definition:TargetLoweringObjectFileImpl.cpp:1567
selectExplicitSectionGlobal
static MCSection * selectExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM, MCContext &Ctx, Mangler &Mang, unsigned &NextUniqueID, bool Retain, bool ForceUnique)
Definition:TargetLoweringObjectFileImpl.cpp:818
getSelectionForCOFF
static int getSelectionForCOFF(const GlobalValue *GV)
Definition:TargetLoweringObjectFileImpl.cpp:1653
getCOFFStaticStructorSection
static MCSectionCOFF * getCOFFStaticStructorSection(MCContext &Ctx, const Triple &T, bool IsCtor, unsigned Priority, const MCSymbol *KeySym, MCSectionCOFF *Default)
Definition:TargetLoweringObjectFileImpl.cpp:1955
getEntrySizeForKind
static unsigned getEntrySizeForKind(SectionKind Kind)
Definition:TargetLoweringObjectFileImpl.cpp:604
GetObjCImageInfo
static void GetObjCImageInfo(Module &M, unsigned &Version, unsigned &Flags, StringRef &Section)
Definition:TargetLoweringObjectFileImpl.cpp:79
getComdatGVForCOFF
static const GlobalValue * getComdatGVForCOFF(const GlobalValue *GV)
Definition:TargetLoweringObjectFileImpl.cpp:1636
getCOFFSectionFlags
static unsigned getCOFFSectionFlags(SectionKind K, const TargetMachine &TM)
Definition:TargetLoweringObjectFileImpl.cpp:1597
handlePragmaClangSection
static StringRef handlePragmaClangSection(const GlobalObject *GO, SectionKind Kind)
Definition:TargetLoweringObjectFileImpl.cpp:797
getELFSectionType
static unsigned getELFSectionType(StringRef Name, SectionKind K)
Definition:TargetLoweringObjectFileImpl.cpp:522
hasPrefix
static bool hasPrefix(StringRef SectionName, StringRef Prefix)
Definition:TargetLoweringObjectFileImpl.cpp:517
selectWasmSectionForGlobal
static MCSectionWasm * selectWasmSectionForGlobal(MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, bool EmitUniqueSection, unsigned *NextUniqueID, bool Retain)
Definition:TargetLoweringObjectFileImpl.cpp:2204
getLinkedToSymbol
static const MCSymbolELF * getLinkedToSymbol(const GlobalObject *GO, const TargetMachine &TM)
Definition:TargetLoweringObjectFileImpl.cpp:593
calcUniqueIDUpdateFlagsAndSize
static unsigned calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName, SectionKind Kind, const TargetMachine &TM, MCContext &Ctx, Mangler &Mang, unsigned &Flags, unsigned &EntrySize, unsigned &NextUniqueID, const bool Retain, const bool ForceUnique)
Calculate an appropriate unique ID for a section, and update Flags, EntrySize and NextUniqueID where ...
Definition:TargetLoweringObjectFileImpl.cpp:703
getELFKindForNamedSection
static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K)
Definition:TargetLoweringObjectFileImpl.cpp:475
getWasmComdat
static const Comdat * getWasmComdat(const GlobalValue *GV)
Definition:TargetLoweringObjectFileImpl.cpp:2131
getStaticStructorSection
static MCSectionELF * getStaticStructorSection(MCContext &Ctx, bool UseInitArray, bool IsCtor, unsigned Priority, const MCSymbol *KeySym)
Definition:TargetLoweringObjectFileImpl.cpp:1097
getWasmSectionFlags
static unsigned getWasmSectionFlags(SectionKind K, bool Retain)
Definition:TargetLoweringObjectFileImpl.cpp:2144
checkMachOComdat
static void checkMachOComdat(const GlobalValue *GV)
Definition:TargetLoweringObjectFileImpl.cpp:1299
APIntToHexString
static std::string APIntToHexString(const APInt &AI)
Definition:TargetLoweringObjectFileImpl.cpp:2049
JumpTableInFunctionSection
static cl::opt< bool > JumpTableInFunctionSection("jumptable-in-function-section", cl::Hidden, cl::init(false), cl::desc("Putting Jump Table in function section"))
getSectionPrefixForGlobal
static StringRef getSectionPrefixForGlobal(SectionKind Kind, bool IsLarge)
Return the section prefix name used by options FunctionsSections and DataSections.
Definition:TargetLoweringObjectFileImpl.cpp:630
selectELFSectionForGlobal
static MCSectionELF * selectELFSectionForGlobal(MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags, unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol)
Definition:TargetLoweringObjectFileImpl.cpp:874
getELFSectionNameForGlobal
static SmallString< 128 > getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, unsigned EntrySize, bool UniqueSectionName)
Definition:TargetLoweringObjectFileImpl.cpp:649
scalarConstantToHexString
static std::string scalarConstantToHexString(const Constant *C)
Definition:TargetLoweringObjectFileImpl.cpp:2060
getCOFFSectionNameForUniqueGlobal
static StringRef getCOFFSectionNameForUniqueGlobal(SectionKind Kind)
Definition:TargetLoweringObjectFileImpl.cpp:1714
getELFComdat
static const Comdat * getELFComdat(const GlobalValue *GV)
Definition:TargetLoweringObjectFileImpl.cpp:579
getGlobalObjectInfo
static std::tuple< StringRef, bool, unsigned > getGlobalObjectInfo(const GlobalObject *GO, const TargetMachine &TM)
Definition:TargetLoweringObjectFileImpl.cpp:783
getELFSectionFlags
static unsigned getELFSectionFlags(SectionKind K)
Definition:TargetLoweringObjectFileImpl.cpp:549
TargetLoweringObjectFileImpl.h
Triple.h
RHS
Value * RHS
Definition:X86PartialReduction.cpp:74
LHS
Value * LHS
Definition:X86PartialReduction.cpp:73
T
llvm::APInt
Class for arbitrary precision integers.
Definition:APInt.h:78
llvm::APInt::getBitWidth
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition:APInt.h:1468
llvm::APInt::getZero
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition:APInt.h:200
llvm::Comdat
Definition:Comdat.h:33
llvm::Comdat::Largest
@ Largest
The linker will choose the largest COMDAT.
Definition:Comdat.h:38
llvm::Comdat::SameSize
@ SameSize
The data referenced by the COMDAT must be the same size.
Definition:Comdat.h:40
llvm::Comdat::Any
@ Any
The linker may choose any COMDAT.
Definition:Comdat.h:36
llvm::Comdat::NoDeduplicate
@ NoDeduplicate
No deduplication is performed.
Definition:Comdat.h:39
llvm::Comdat::ExactMatch
@ ExactMatch
The data referenced by the COMDAT must be the same.
Definition:Comdat.h:37
llvm::Constant
This is an important base class in LLVM.
Definition:Constant.h:42
llvm::DSOLocalEquivalent
Wrapper for a function that represents a value that functionally represents the original function.
Definition:Constants.h:941
llvm::DSOLocalEquivalent::getGlobalValue
GlobalValue * getGlobalValue() const
Definition:Constants.h:962
llvm::DWARFExpression::Operation
This class represents an Operation in the Expression.
Definition:DWARFExpression.h:32
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition:DataLayout.h:63
llvm::DataLayout::getPreferredAlign
Align getPreferredAlign(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
Definition:DataLayout.cpp:988
llvm::DataLayout::getPrivateGlobalPrefix
StringRef getPrivateGlobalPrefix() const
Definition:DataLayout.h:285
llvm::DiagnosticInfo
This is the base abstract class for diagnostic reporting in the backend.
Definition:DiagnosticInfo.h:112
llvm::DiagnosticPrinter
Interface for custom diagnostic printing.
Definition:DiagnosticPrinter.h:31
llvm::Directive
Definition:DirectiveEmitter.h:134
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition:Error.h:160
llvm::Function
Definition:Function.h:63
llvm::GlobalObject
Definition:GlobalObject.h:27
llvm::GlobalObject::getSection
StringRef getSection() const
Get the custom section of this global if it has one.
Definition:GlobalObject.h:117
llvm::GlobalObject::hasComdat
bool hasComdat() const
Definition:GlobalObject.h:127
llvm::GlobalObject::hasSection
bool hasSection() const
Check if this global has a custom object file section.
Definition:GlobalObject.h:109
llvm::GlobalObject::getMetadata
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Definition:Value.h:565
llvm::GlobalValue
Definition:GlobalValue.h:48
llvm::GlobalValue::LocalDynamicTLSModel
@ LocalDynamicTLSModel
Definition:GlobalValue.h:199
llvm::GlobalValue::hasExternalLinkage
bool hasExternalLinkage() const
Definition:GlobalValue.h:512
llvm::GlobalValue::isThreadLocal
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
Definition:GlobalValue.h:264
llvm::GlobalValue::getLinkage
LinkageTypes getLinkage() const
Definition:GlobalValue.h:547
llvm::GlobalValue::hasLocalLinkage
bool hasLocalLinkage() const
Definition:GlobalValue.h:529
llvm::GlobalValue::hasPrivateLinkage
bool hasPrivateLinkage() const
Definition:GlobalValue.h:528
llvm::GlobalValue::getComdat
const Comdat * getComdat() const
Definition:Globals.cpp:199
llvm::GlobalValue::getThreadLocalMode
ThreadLocalMode getThreadLocalMode() const
Definition:GlobalValue.h:272
llvm::GlobalValue::isDeclarationForLinker
bool isDeclarationForLinker() const
Definition:GlobalValue.h:619
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition:GlobalValue.h:657
llvm::GlobalValue::getAliaseeObject
const GlobalObject * getAliaseeObject() const
Definition:Globals.cpp:400
llvm::GlobalValue::getDataLayout
const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
Definition:Globals.cpp:130
llvm::GlobalValue::hasCommonLinkage
bool hasCommonLinkage() const
Definition:GlobalValue.h:533
llvm::GlobalValue::isWeakForLinker
static bool isWeakForLinker(LinkageTypes Linkage)
Whether the definition of this global may be replaced at link time.
Definition:GlobalValue.h:459
llvm::GlobalValue::PrivateLinkage
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition:GlobalValue.h:60
llvm::GlobalValue::CommonLinkage
@ CommonLinkage
Tentative definitions.
Definition:GlobalValue.h:62
llvm::GlobalValue::InternalLinkage
@ InternalLinkage
Rename collisions when linking (static functions).
Definition:GlobalValue.h:59
llvm::GlobalValue::LinkOnceAnyLinkage
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
Definition:GlobalValue.h:54
llvm::GlobalValue::WeakODRLinkage
@ WeakODRLinkage
Same, but only replaced by something equivalent.
Definition:GlobalValue.h:57
llvm::GlobalValue::ExternalLinkage
@ ExternalLinkage
Externally visible function.
Definition:GlobalValue.h:52
llvm::GlobalValue::WeakAnyLinkage
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
Definition:GlobalValue.h:56
llvm::GlobalValue::AppendingLinkage
@ AppendingLinkage
Special purpose, only applies to global arrays.
Definition:GlobalValue.h:58
llvm::GlobalValue::AvailableExternallyLinkage
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition:GlobalValue.h:53
llvm::GlobalValue::ExternalWeakLinkage
@ ExternalWeakLinkage
ExternalWeak linkage description.
Definition:GlobalValue.h:61
llvm::GlobalValue::LinkOnceODRLinkage
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Definition:GlobalValue.h:55
llvm::GlobalVariable
Definition:GlobalVariable.h:39
llvm::GlobalVariable::getAttributes
AttributeSet getAttributes() const
Return the attribute set for this global.
Definition:GlobalVariable.h:243
llvm::GlobalVariable::hasImplicitSection
bool hasImplicitSection() const
Check if section name is present.
Definition:GlobalVariable.h:263
llvm::LLVMContext::diagnose
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
Definition:LLVMContext.cpp:245
llvm::MCAsmInfoDarwin::isSectionAtomizableBySymbols
static bool isSectionAtomizableBySymbols(const MCSection &Section)
True if the section is atomized using the symbols in it.
Definition:MCAsmInfoDarwin.cpp:21
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition:MCAsmInfo.h:56
llvm::MCAsmInfo::useIntegratedAssembler
bool useIntegratedAssembler() const
Return true if assembly (inline or otherwise) should be parsed.
Definition:MCAsmInfo.h:698
llvm::MCAsmInfo::binutilsIsAtLeast
bool binutilsIsAtLeast(int Major, int Minor) const
Definition:MCAsmInfo.h:705
llvm::MCAsmInfo::getExceptionHandlingType
ExceptionHandling getExceptionHandlingType() const
Definition:MCAsmInfo.h:642
llvm::MCBinaryExpr::createAdd
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition:MCExpr.h:537
llvm::MCBinaryExpr::createSub
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition:MCExpr.h:622
llvm::MCConstantExpr::create
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition:MCExpr.cpp:222
llvm::MCContext
Context object for machine code objects.
Definition:MCContext.h:83
llvm::MCContext::getObjectFileInfo
const MCObjectFileInfo * getObjectFileInfo() const
Definition:MCContext.h:416
llvm::MCContext::getMachOSection
MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, unsigned Reserved2, SectionKind K, const char *BeginSymName=nullptr)
Return the MCSection for the specified mach-o section.
Definition:MCContext.cpp:488
llvm::MCContext::getWasmSection
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K, unsigned Flags=0)
Definition:MCContext.h:628
llvm::MCContext::getELFNamedSection
MCSectionELF * getELFNamedSection(const Twine &Prefix, const Twine &Suffix, unsigned Type, unsigned Flags, unsigned EntrySize=0)
Get a section with the provided group identifier.
Definition:MCContext.cpp:551
llvm::MCContext::getELFSection
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition:MCContext.h:551
llvm::MCContext::getXCOFFSection
MCSectionXCOFF * getXCOFFSection(StringRef Section, SectionKind K, std::optional< XCOFF::CsectProperties > CsectProp=std::nullopt, bool MultiSymbolsAllowed=false, std::optional< XCOFF::DwarfSectionSubtypeFlags > DwarfSubtypeFlags=std::nullopt)
Definition:MCContext.cpp:805
llvm::MCContext::getCOFFSection
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID)
Definition:MCContext.cpp:692
llvm::MCContext::getGOFFSection
MCSectionGOFF * getGOFFSection(StringRef Section, SectionKind Kind, MCSection *Parent, uint32_t Subsection=0)
Definition:MCContext.cpp:674
llvm::MCContext::isELFGenericMergeableSection
bool isELFGenericMergeableSection(StringRef Name)
Definition:MCContext.cpp:661
llvm::MCContext::getELFUniqueIDForEntsize
std::optional< unsigned > getELFUniqueIDForEntsize(StringRef SectionName, unsigned Flags, unsigned EntrySize)
Return the unique ID of the section with the given name, flags and entry size, if it exists.
Definition:MCContext.cpp:667
llvm::MCContext::getAsmInfo
const MCAsmInfo * getAsmInfo() const
Definition:MCContext.h:412
llvm::MCContext::getOrCreateSymbol
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition:MCContext.cpp:212
llvm::MCContext::isELFImplicitMergeableSectionNamePrefix
bool isELFImplicitMergeableSectionNamePrefix(StringRef Name)
Definition:MCContext.cpp:656
llvm::MCContext::getAssociativeCOFFSection
MCSectionCOFF * getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym, unsigned UniqueID=GenericSectionID)
Gets or creates a section equivalent to Sec that is associated with the section containing KeySym.
Definition:MCContext.cpp:733
llvm::MCContext::GenericSectionID
@ GenericSectionID
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
Definition:MCContext.h:534
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition:MCExpr.h:34
llvm::MCObjectFileInfo::TLSBSSSection
MCSection * TLSBSSSection
Section directive for Thread Local uninitialized data.
Definition:MCObjectFileInfo.h:160
llvm::MCObjectFileInfo::MergeableConst16Section
MCSection * MergeableConst16Section
Definition:MCObjectFileInfo.h:190
llvm::MCObjectFileInfo::MergeableConst4Section
MCSection * MergeableConst4Section
Definition:MCObjectFileInfo.h:188
llvm::MCObjectFileInfo::TextSection
MCSection * TextSection
Section directive for standard text.
Definition:MCObjectFileInfo.h:53
llvm::MCObjectFileInfo::ConstDataCoalSection
MCSection * ConstDataCoalSection
Definition:MCObjectFileInfo.h:211
llvm::MCObjectFileInfo::ConstTextCoalSection
MCSection * ConstTextCoalSection
Definition:MCObjectFileInfo.h:208
llvm::MCObjectFileInfo::TLSDataSection
MCSection * TLSDataSection
Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
Definition:MCObjectFileInfo.h:155
llvm::MCObjectFileInfo::MergeableConst8Section
MCSection * MergeableConst8Section
Definition:MCObjectFileInfo.h:189
llvm::MCObjectFileInfo::LSDASection
MCSection * LSDASection
If exception handling is supported by the target, this is the section the Language Specific Data Area...
Definition:MCObjectFileInfo.h:69
llvm::MCObjectFileInfo::ReadOnly16Section
MCSection * ReadOnly16Section
Definition:MCObjectFileInfo.h:242
llvm::MCObjectFileInfo::FourByteConstantSection
MCSection * FourByteConstantSection
Definition:MCObjectFileInfo.h:214
llvm::MCObjectFileInfo::ReadOnly8Section
MCSection * ReadOnly8Section
Definition:MCObjectFileInfo.h:241
llvm::MCObjectFileInfo::DataBSSSection
MCSection * DataBSSSection
Definition:MCObjectFileInfo.h:213
llvm::MCObjectFileInfo::getDrectveSection
MCSection * getDrectveSection() const
Definition:MCObjectFileInfo.h:431
llvm::MCObjectFileInfo::TextCoalSection
MCSection * TextCoalSection
Definition:MCObjectFileInfo.h:207
llvm::MCObjectFileInfo::DataRelROSection
MCSection * DataRelROSection
Definition:MCObjectFileInfo.h:187
llvm::MCObjectFileInfo::CStringSection
MCSection * CStringSection
Definition:MCObjectFileInfo.h:205
llvm::MCObjectFileInfo::isPositionIndependent
bool isPositionIndependent() const
Definition:MCObjectFileInfo.h:452
llvm::MCObjectFileInfo::DataCoalSection
MCSection * DataCoalSection
Definition:MCObjectFileInfo.h:210
llvm::MCObjectFileInfo::UStringSection
MCSection * UStringSection
Definition:MCObjectFileInfo.h:206
llvm::MCObjectFileInfo::MergeableConst32Section
MCSection * MergeableConst32Section
Definition:MCObjectFileInfo.h:191
llvm::MCObjectFileInfo::SixteenByteConstantSection
MCSection * SixteenByteConstantSection
Definition:MCObjectFileInfo.h:216
llvm::MCObjectFileInfo::DataCommonSection
MCSection * DataCommonSection
Definition:MCObjectFileInfo.h:212
llvm::MCObjectFileInfo::ReadOnlySection
MCSection * ReadOnlySection
Section that is readonly and can contain arbitrary initialized data.
Definition:MCObjectFileInfo.h:65
llvm::MCObjectFileInfo::BSSSection
MCSection * BSSSection
Section that is default initialized to zero.
Definition:MCObjectFileInfo.h:59
llvm::MCObjectFileInfo::EightByteConstantSection
MCSection * EightByteConstantSection
Definition:MCObjectFileInfo.h:215
llvm::MCObjectFileInfo::getTextSection
MCSection * getTextSection() const
Definition:MCObjectFileInfo.h:271
llvm::MCObjectFileInfo::ConstDataSection
MCSection * ConstDataSection
Definition:MCObjectFileInfo.h:209
llvm::MCObjectFileInfo::getContext
MCContext & getContext() const
Definition:MCObjectFileInfo.h:252
llvm::MCObjectFileInfo::DataSection
MCSection * DataSection
Section directive for standard data.
Definition:MCObjectFileInfo.h:56
llvm::MCSectionCOFF
This represents a section on Windows.
Definition:MCSectionCOFF.h:27
llvm::MCSectionELF
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition:MCSectionELF.h:27
llvm::MCSectionMachO
This represents a section on a Mach-O system (used by Mac OS X).
Definition:MCSectionMachO.h:24
llvm::MCSectionMachO::ParseSectionSpecifier
static Error ParseSectionSpecifier(StringRef Spec, StringRef &Segment, StringRef &Section, unsigned &TAA, bool &TAAParsed, unsigned &StubSize)
Parse the section specifier indicated by "Spec".
Definition:MCSectionMachO.cpp:181
llvm::MCSectionMachO::getTypeAndAttributes
unsigned getTypeAndAttributes() const
Definition:MCSectionMachO.h:54
llvm::MCSectionMachO::getStubSize
unsigned getStubSize() const
Definition:MCSectionMachO.h:55
llvm::MCSectionWasm
This represents a section on wasm.
Definition:MCSectionWasm.h:26
llvm::MCSectionXCOFF::getQualNameSymbol
MCSymbolXCOFF * getQualNameSymbol() const
Definition:MCSectionXCOFF.h:116
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition:MCSection.h:36
llvm::MCSection::NonUniqueID
static constexpr unsigned NonUniqueID
Definition:MCSection.h:40
llvm::MCSection::getName
StringRef getName() const
Definition:MCSection.h:130
llvm::MCStreamer
Streaming machine code generation interface.
Definition:MCStreamer.h:213
llvm::MCStreamer::addBlankLine
virtual void addBlankLine()
Emit a blank line to a .s file to pretty it up.
Definition:MCStreamer.h:387
llvm::MCStreamer::emitSymbolAttribute
virtual bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
llvm::MCStreamer::emitELFSize
virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value)
Emit an ELF .size directive.
Definition:MCStreamer.cpp:1255
llvm::MCStreamer::emitSymbolValue
void emitSymbolValue(const MCSymbol *Sym, unsigned Size, bool IsSectionRelative=false)
Special case of EmitValue that avoids the client having to pass in a MCExpr for MCSymbols.
Definition:MCStreamer.cpp:183
llvm::MCStreamer::emitLabel
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition:MCStreamer.cpp:420
llvm::MCStreamer::emitValueToAlignment
virtual void emitValueToAlignment(Align Alignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0)
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
Definition:MCStreamer.cpp:1276
llvm::MCStreamer::emitULEB128IntValue
unsigned emitULEB128IntValue(uint64_t Value, unsigned PadTo=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
Definition:MCStreamer.cpp:161
llvm::MCStreamer::emitLinkerOptions
virtual void emitLinkerOptions(ArrayRef< std::string > Kind)
Emit the given list Options of strings as linker options into the output.
Definition:MCStreamer.h:467
llvm::MCStreamer::emitInt64
void emitInt64(uint64_t Value)
Definition:MCStreamer.h:730
llvm::MCStreamer::switchSection
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
Definition:MCStreamer.cpp:1303
llvm::MCStreamer::emitInt32
void emitInt32(uint64_t Value)
Definition:MCStreamer.h:729
llvm::MCStreamer::emitInt8
void emitInt8(uint64_t Value)
Definition:MCStreamer.h:727
llvm::MCStreamer::emitBytes
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
Definition:MCStreamer.cpp:1266
llvm::MCSymbolELF
Definition:MCSymbolELF.h:15
llvm::MCSymbolRefExpr::getSymbol
const MCSymbol & getSymbol() const
Definition:MCExpr.h:411
llvm::MCSymbolRefExpr::VK_None
@ VK_None
Definition:MCExpr.h:195
llvm::MCSymbolRefExpr::VK_COFF_IMGREL32
@ VK_COFF_IMGREL32
Definition:MCExpr.h:327
llvm::MCSymbolRefExpr::create
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition:MCExpr.h:398
llvm::MCSymbolXCOFF
Definition:MCSymbolXCOFF.h:20
llvm::MCSymbolXCOFF::getSymbolTableName
StringRef getSymbolTableName() const
Definition:MCSymbolXCOFF.h:68
llvm::MCSymbolXCOFF::hasPerSymbolCodeModel
bool hasPerSymbolCodeModel() const
Definition:MCSymbolXCOFF.h:78
llvm::MCSymbolXCOFF::getPerSymbolCodeModel
CodeModel getPerSymbolCodeModel() const
Definition:MCSymbolXCOFF.h:80
llvm::MCSymbolXCOFF::CM_Large
@ CM_Large
Definition:MCSymbolXCOFF.h:30
llvm::MCSymbolXCOFF::isEHInfo
bool isEHInfo() const
Definition:MCSymbolXCOFF.h:74
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition:MCSymbol.h:41
llvm::MCSymbol::getName
StringRef getName() const
getName - Get the symbol name.
Definition:MCSymbol.h:205
llvm::MCValue
This represents an "assembler immediate".
Definition:MCValue.h:36
llvm::MCValue::getConstant
int64_t getConstant() const
Definition:MCValue.h:43
llvm::MCValue::getSymB
const MCSymbolRefExpr * getSymB() const
Definition:MCValue.h:45
llvm::MDNode
Metadata node.
Definition:Metadata.h:1073
llvm::MDNode::getOperand
const MDOperand & getOperand(unsigned I) const
Definition:Metadata.h:1434
llvm::MDOperand::get
Metadata * get() const
Definition:Metadata.h:924
llvm::MachineBasicBlock
Definition:MachineBasicBlock.h:125
llvm::MachineBasicBlock::getSymbol
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
Definition:MachineBasicBlock.cpp:63
llvm::MachineBasicBlock::getSectionID
MBBSectionID getSectionID() const
Returns the section ID of this basic block.
Definition:MachineBasicBlock.h:684
llvm::MachineBasicBlock::getParent
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
Definition:MachineBasicBlock.h:311
llvm::MachineBasicBlock::isBeginSection
bool isBeginSection() const
Returns true if this block begins any section.
Definition:MachineBasicBlock.h:672
llvm::MachineFunction
Definition:MachineFunction.h:267
llvm::MachineFunction::getFunctionNumber
unsigned getFunctionNumber() const
getFunctionNumber - Return a unique ID for the current function.
Definition:MachineFunction.h:713
llvm::MachineFunction::getName
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Definition:MachineFunction.cpp:645
llvm::MachineFunction::getContext
MCContext & getContext() const
Definition:MachineFunction.h:690
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition:MachineFunction.h:704
llvm::MachineFunction::getLandingPads
const std::vector< LandingPadInfo > & getLandingPads() const
Return a reference to the landing pad info for the current function.
Definition:MachineFunction.h:1250
llvm::MachineFunction::getSection
MCSection * getSection() const
Returns the Section this function belongs to.
Definition:MachineFunction.h:693
llvm::MachineModuleInfoELF
MachineModuleInfoELF - This is a MachineModuleInfoImpl implementation for ELF targets.
Definition:MachineModuleInfoImpls.h:77
llvm::MachineModuleInfoELF::getGVStubEntry
StubValueTy & getGVStubEntry(MCSymbol *Sym)
Definition:MachineModuleInfoImpls.h:95
llvm::MachineModuleInfoImpl::StubValueTy
PointerIntPair< MCSymbol *, 1, bool > StubValueTy
Definition:MachineModuleInfo.h:58
llvm::MachineModuleInfoMachO
MachineModuleInfoMachO - This is a MachineModuleInfoImpl implementation for MachO targets.
Definition:MachineModuleInfoImpls.h:28
llvm::MachineModuleInfoMachO::getGVStubEntry
StubValueTy & getGVStubEntry(MCSymbol *Sym)
Definition:MachineModuleInfoImpls.h:49
llvm::MachineModuleInfo
This class contains meta information specific to a module.
Definition:MachineModuleInfo.h:82
llvm::MachineModuleInfo::getModule
const Module * getModule() const
Definition:MachineModuleInfo.h:132
llvm::MachineModuleInfo::getObjFileInfo
Ty & getObjFileInfo()
Keep track of various per-module pieces of information for backends that would like to do so.
Definition:MachineModuleInfo.h:156
llvm::Mangler
Definition:Mangler.h:28
llvm::Mangler::getNameWithPrefix
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
Definition:Mangler.cpp:121
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition:Module.h:65
llvm::Module::Require
@ Require
Adds a requirement that another module flag be present and have a specified value after linking is pe...
Definition:Module.h:131
llvm::Module::getSourceFileName
const std::string & getSourceFileName() const
Get the module's original source file name.
Definition:Module.h:279
llvm::Module::getNamedValue
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type.
Definition:Module.cpp:170
llvm::Module::getDataLayout
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition:Module.h:294
llvm::NamedMDNode
A tuple of MDNodes.
Definition:Metadata.h:1737
llvm::PointerIntPair
PointerIntPair - This class implements a pair of a pointer and small integer.
Definition:PointerIntPair.h:80
llvm::PointerIntPair::getPointer
PointerTy getPointer() const
Definition:PointerIntPair.h:94
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition:SectionKind.h:22
llvm::SectionKind::getThreadData
static SectionKind getThreadData()
Definition:SectionKind.h:207
llvm::SectionKind::getMetadata
static SectionKind getMetadata()
Definition:SectionKind.h:188
llvm::SectionKind::isThreadBSSLocal
bool isThreadBSSLocal() const
Definition:SectionKind.h:163
llvm::SectionKind::getText
static SectionKind getText()
Definition:SectionKind.h:190
llvm::SectionKind::isBSSLocal
bool isBSSLocal() const
Definition:SectionKind.h:170
llvm::SectionKind::getData
static SectionKind getData()
Definition:SectionKind.h:213
llvm::SectionKind::isText
bool isText() const
Definition:SectionKind.h:127
llvm::SectionKind::getBSS
static SectionKind getBSS()
Definition:SectionKind.h:209
llvm::SectionKind::getThreadBSS
static SectionKind getThreadBSS()
Definition:SectionKind.h:206
llvm::SectionKind::getReadOnly
static SectionKind getReadOnly()
Definition:SectionKind.h:192
llvm::SmallString
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition:SmallString.h:26
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition:SmallVector.h:573
llvm::SmallVectorTemplateBase::push_back
void push_back(const T &Elt)
Definition:SmallVector.h:413
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::StringRef::starts_with
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition:StringRef.h:265
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition:StringRef.h:147
llvm::TargetLoweringObjectFileCOFF::lowerRelativeReference
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:2018
llvm::TargetLoweringObjectFileCOFF::getExplicitSectionGlobal
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
Definition:TargetLoweringObjectFileImpl.cpp:1678
llvm::TargetLoweringObjectFileCOFF::getSectionForConstant
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a mergeable constant with the specified size and relocation information, return a section that ...
Definition:TargetLoweringObjectFileImpl.cpp:2081
llvm::TargetLoweringObjectFileCOFF::Initialize
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
Definition:TargetLoweringObjectFileImpl.cpp:1933
llvm::TargetLoweringObjectFileCOFF::emitModuleMetadata
void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override
Emit Obj-C garbage collection and linker options.
Definition:TargetLoweringObjectFileImpl.cpp:1849
llvm::TargetLoweringObjectFileCOFF::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:1726
llvm::TargetLoweringObjectFileCOFF::getStaticCtorSection
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition:TargetLoweringObjectFileImpl.cpp:2004
llvm::TargetLoweringObjectFileCOFF::emitLinkerDirectives
void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const override
Process linker options metadata and emit platform-specific bits.
Definition:TargetLoweringObjectFileImpl.cpp:1872
llvm::TargetLoweringObjectFileCOFF::shouldPutJumpTableInFunctionSection
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
Definition:TargetLoweringObjectFileImpl.cpp:1836
llvm::TargetLoweringObjectFileCOFF::getNameWithPrefix
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:1797
llvm::TargetLoweringObjectFileCOFF::getStaticDtorSection
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition:TargetLoweringObjectFileImpl.cpp:2011
llvm::TargetLoweringObjectFileCOFF::getSectionForJumpTable
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:1809
llvm::TargetLoweringObjectFileELF::getUniqueSectionForFunction
MCSection * getUniqueSectionForFunction(const Function &F, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:952
llvm::TargetLoweringObjectFileELF::Initialize
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
Definition:TargetLoweringObjectFileImpl.cpp:121
llvm::TargetLoweringObjectFileELF::getSectionForConstant
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a constant with the SectionKind, return a section that it should be placed in.
Definition:TargetLoweringObjectFileImpl.cpp:1027
llvm::TargetLoweringObjectFileELF::getStaticCtorSection
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition:TargetLoweringObjectFileImpl.cpp:1135
llvm::TargetLoweringObjectFileELF::getSectionForJumpTable
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:968
llvm::TargetLoweringObjectFileELF::emitModuleMetadata
void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override
Emit Obj-C garbage collection and linker options.
Definition:TargetLoweringObjectFileImpl.cpp:305
llvm::TargetLoweringObjectFileELF::emitLinkerDirectives
void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const override
Process linker options metadata and emit platform-specific bits.
Definition:TargetLoweringObjectFileImpl.cpp:389
llvm::TargetLoweringObjectFileELF::getCFIPersonalitySymbol
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
Definition:TargetLoweringObjectFileImpl.cpp:409
llvm::TargetLoweringObjectFileELF::TargetLoweringObjectFileELF
TargetLoweringObjectFileELF()
Definition:TargetLoweringObjectFileImpl.cpp:117
llvm::TargetLoweringObjectFileELF::getStaticDtorSection
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition:TargetLoweringObjectFileImpl.cpp:1141
llvm::TargetLoweringObjectFileELF::emitPersonalityValue
void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym, const MachineModuleInfo *MMI) const override
Definition:TargetLoweringObjectFileImpl.cpp:421
llvm::TargetLoweringObjectFileELF::getTTypeGlobalReference
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Return an MCExpr to use for a reference to the specified type info global variable from exception han...
Definition:TargetLoweringObjectFileImpl.cpp:450
llvm::TargetLoweringObjectFileELF::getModuleMetadata
void getModuleMetadata(Module &M) override
Get the module-level metadata that the platform cares about.
Definition:TargetLoweringObjectFileImpl.cpp:297
llvm::TargetLoweringObjectFileELF::lowerRelativeReference
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:1147
llvm::TargetLoweringObjectFileELF::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:933
llvm::TargetLoweringObjectFileELF::lowerDSOLocalEquivalent
const MCExpr * lowerDSOLocalEquivalent(const DSOLocalEquivalent *Equiv, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:1167
llvm::TargetLoweringObjectFileELF::getSectionForCommandLines
MCSection * getSectionForCommandLines() const override
If supported, return the section to use for the llvm.commandline metadata.
Definition:TargetLoweringObjectFileImpl.cpp:1181
llvm::TargetLoweringObjectFileELF::getSectionForLSDA
MCSection * getSectionForLSDA(const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:983
llvm::TargetLoweringObjectFileELF::emitPersonalityValueImpl
virtual void emitPersonalityValueImpl(MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym, const MachineModuleInfo *MMI) const
Definition:TargetLoweringObjectFileImpl.cpp:444
llvm::TargetLoweringObjectFileELF::shouldPutJumpTableInFunctionSection
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
Definition:TargetLoweringObjectFileImpl.cpp:1018
llvm::TargetLoweringObjectFileELF::InitializeELF
void InitializeELF(bool UseInitArray_)
Definition:TargetLoweringObjectFileImpl.cpp:1190
llvm::TargetLoweringObjectFileELF::getSectionForMachineBasicBlock
MCSection * getSectionForMachineBasicBlock(const Function &F, const MachineBasicBlock &MBB, const TargetMachine &TM) const override
Returns a unique section for the given machine basic block.
Definition:TargetLoweringObjectFileImpl.cpp:1046
llvm::TargetLoweringObjectFileELF::PLTRelativeVariantKind
MCSymbolRefExpr::VariantKind PLTRelativeVariantKind
Definition:TargetLoweringObjectFileImpl.h:40
llvm::TargetLoweringObjectFileELF::getExplicitSectionGlobal
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
Definition:TargetLoweringObjectFileImpl.cpp:867
llvm::TargetLoweringObjectFileGOFF::getExplicitSectionGlobal
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
Definition:TargetLoweringObjectFileImpl.cpp:2735
llvm::TargetLoweringObjectFileGOFF::getSectionForLSDA
MCSection * getSectionForLSDA(const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:2740
llvm::TargetLoweringObjectFileGOFF::TargetLoweringObjectFileGOFF
TargetLoweringObjectFileGOFF()
llvm::TargetLoweringObjectFileGOFF::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:2746
llvm::TargetLoweringObjectFileMachO::getSectionForConstant
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a constant with the SectionKind, return a section that it should be placed in.
Definition:TargetLoweringObjectFileImpl.cpp:1420
llvm::TargetLoweringObjectFileMachO::getNameWithPrefix
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:1579
llvm::TargetLoweringObjectFileMachO::getCFIPersonalitySymbol
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
Definition:TargetLoweringObjectFileImpl.cpp:1470
llvm::TargetLoweringObjectFileMachO::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:1350
llvm::TargetLoweringObjectFileMachO::emitLinkerDirectives
void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const override
Process linker options metadata and emit platform-specific bits.
Definition:TargetLoweringObjectFileImpl.cpp:1287
llvm::TargetLoweringObjectFileMachO::getExplicitSectionGlobal
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
Definition:TargetLoweringObjectFileImpl.cpp:1308
llvm::TargetLoweringObjectFileMachO::getIndirectSymViaGOTPCRel
const MCExpr * getIndirectSymViaGOTPCRel(const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV, int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Get MachO PC relative GOT entry relocation.
Definition:TargetLoweringObjectFileImpl.cpp:1490
llvm::TargetLoweringObjectFileMachO::emitModuleMetadata
void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override
Emit the module flags that specify the garbage collection information.
Definition:TargetLoweringObjectFileImpl.cpp:1250
llvm::TargetLoweringObjectFileMachO::Initialize
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
Definition:TargetLoweringObjectFileImpl.cpp:1216
llvm::TargetLoweringObjectFileMachO::getSectionForCommandLines
MCSection * getSectionForCommandLines() const override
If supported, return the section to use for the llvm.commandline metadata.
Definition:TargetLoweringObjectFileImpl.cpp:1437
llvm::TargetLoweringObjectFileMachO::getStaticDtorSection
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition:TargetLoweringObjectFileImpl.cpp:1240
llvm::TargetLoweringObjectFileMachO::TargetLoweringObjectFileMachO
TargetLoweringObjectFileMachO()
Definition:TargetLoweringObjectFileImpl.cpp:1212
llvm::TargetLoweringObjectFileMachO::getTTypeGlobalReference
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
The mach-o version of this method defaults to returning a stub reference.
Definition:TargetLoweringObjectFileImpl.cpp:1442
llvm::TargetLoweringObjectFileWasm::getModuleMetadata
void getModuleMetadata(Module &M) override
Get the module-level metadata that the platform cares about.
Definition:TargetLoweringObjectFileImpl.cpp:2161
llvm::TargetLoweringObjectFileWasm::lowerRelativeReference
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:2264
llvm::TargetLoweringObjectFileWasm::InitializeWasm
void InitializeWasm()
Definition:TargetLoweringObjectFileImpl.cpp:2284
llvm::TargetLoweringObjectFileWasm::getStaticCtorSection
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition:TargetLoweringObjectFileImpl.cpp:2293
llvm::TargetLoweringObjectFileWasm::shouldPutJumpTableInFunctionSection
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
Definition:TargetLoweringObjectFileImpl.cpp:2257
llvm::TargetLoweringObjectFileWasm::getStaticDtorSection
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition:TargetLoweringObjectFileImpl.cpp:2301
llvm::TargetLoweringObjectFileWasm::getExplicitSectionGlobal
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
Definition:TargetLoweringObjectFileImpl.cpp:2169
llvm::TargetLoweringObjectFileWasm::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:2236
llvm::TargetLoweringObjectFileXCOFF::ShouldSetSSPCanaryBitInTB
static bool ShouldSetSSPCanaryBitInTB(const MachineFunction *MF)
Definition:TargetLoweringObjectFileImpl.cpp:2327
llvm::TargetLoweringObjectFileXCOFF::Initialize
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
Definition:TargetLoweringObjectFileImpl.cpp:2582
llvm::TargetLoweringObjectFileXCOFF::getSectionForTOCEntry
MCSection * getSectionForTOCEntry(const MCSymbol *Sym, const TargetMachine &TM) const override
On targets that support TOC entries, return a section for the entry given the symbol it refers to.
Definition:TargetLoweringObjectFileImpl.cpp:2684
llvm::TargetLoweringObjectFileXCOFF::getSectionForExternalReference
MCSection * getSectionForExternalReference(const GlobalObject *GO, const TargetMachine &TM) const override
For external functions, this will always return a function descriptor csect.
Definition:TargetLoweringObjectFileImpl.cpp:2416
llvm::TargetLoweringObjectFileXCOFF::getFunctionEntryPointSymbol
MCSymbol * getFunctionEntryPointSymbol(const GlobalValue *Func, const TargetMachine &TM) const override
If supported, return the function entry point symbol.
Definition:TargetLoweringObjectFileImpl.cpp:2643
llvm::TargetLoweringObjectFileXCOFF::shouldPutJumpTableInFunctionSection
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
Definition:TargetLoweringObjectFileImpl.cpp:2555
llvm::TargetLoweringObjectFileXCOFF::lowerRelativeReference
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:2611
llvm::TargetLoweringObjectFileXCOFF::getSectionForJumpTable
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:2539
llvm::TargetLoweringObjectFileXCOFF::getEHInfoTableSymbol
static MCSymbol * getEHInfoTableSymbol(const MachineFunction *MF)
Definition:TargetLoweringObjectFileImpl.cpp:2339
llvm::TargetLoweringObjectFileXCOFF::getExplicitSectionGlobal
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
Definition:TargetLoweringObjectFileImpl.cpp:2383
llvm::TargetLoweringObjectFileXCOFF::getStaticCtorSection
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition:TargetLoweringObjectFileImpl.cpp:2601
llvm::TargetLoweringObjectFileXCOFF::getStorageClassForGlobal
static XCOFF::StorageClass getStorageClassForGlobal(const GlobalValue *GV)
Definition:TargetLoweringObjectFileImpl.cpp:2619
llvm::TargetLoweringObjectFileXCOFF::getSectionForConstant
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a constant with the SectionKind, return a section that it should be placed in.
Definition:TargetLoweringObjectFileImpl.cpp:2562
llvm::TargetLoweringObjectFileXCOFF::getTargetSymbol
MCSymbol * getTargetSymbol(const GlobalValue *GV, const TargetMachine &TM) const override
For functions, this will always return a function descriptor symbol.
Definition:TargetLoweringObjectFileImpl.cpp:2347
llvm::TargetLoweringObjectFileXCOFF::getSectionForFunctionDescriptor
MCSection * getSectionForFunctionDescriptor(const Function *F, const TargetMachine &TM) const override
On targets that use separate function descriptor symbols, return a section for the descriptor given i...
Definition:TargetLoweringObjectFileImpl.cpp:2675
llvm::TargetLoweringObjectFileXCOFF::ShouldEmitEHBlock
static bool ShouldEmitEHBlock(const MachineFunction *MF)
Definition:TargetLoweringObjectFileImpl.cpp:2309
llvm::TargetLoweringObjectFileXCOFF::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition:TargetLoweringObjectFileImpl.cpp:2448
llvm::TargetLoweringObjectFileXCOFF::getStaticDtorSection
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Definition:TargetLoweringObjectFileImpl.cpp:2606
llvm::TargetLoweringObjectFileXCOFF::getSectionForLSDA
MCSection * getSectionForLSDA(const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const override
For functions, this will return the LSDA section.
Definition:TargetLoweringObjectFileImpl.cpp:2716
llvm::TargetLoweringObjectFile::emitCGProfileMetadata
void emitCGProfileMetadata(MCStreamer &Streamer, Module &M) const
Emit Call Graph Profile metadata.
Definition:TargetLoweringObjectFile.cpp:148
llvm::TargetLoweringObjectFile::getNameWithPrefix
virtual void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const
Definition:TargetLoweringObjectFile.cpp:432
llvm::TargetLoweringObjectFile::StaticDtorSection
MCSection * StaticDtorSection
This section contains the static destructor pointer list.
Definition:TargetLoweringObjectFile.h:66
llvm::TargetLoweringObjectFile::PersonalityEncoding
unsigned PersonalityEncoding
PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values for EH.
Definition:TargetLoweringObjectFile.h:57
llvm::TargetLoweringObjectFile::getMangler
Mangler & getMangler() const
Definition:TargetLoweringObjectFile.h:77
llvm::TargetLoweringObjectFile::SupportIndirectSymViaGOTPCRel
bool SupportIndirectSymViaGOTPCRel
Definition:TargetLoweringObjectFile.h:50
llvm::TargetLoweringObjectFile::getKindForGlobal
static SectionKind getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
Definition:TargetLoweringObjectFile.cpp:199
llvm::TargetLoweringObjectFile::shouldPutJumpTableInFunctionSection
virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const
Definition:TargetLoweringObjectFile.cpp:357
llvm::TargetLoweringObjectFile::SupportDebugThreadLocalLocation
bool SupportDebugThreadLocalLocation
Definition:TargetLoweringObjectFile.h:52
llvm::TargetLoweringObjectFile::TM
const TargetMachine * TM
Definition:TargetLoweringObjectFile.h:68
llvm::TargetLoweringObjectFile::LSDAEncoding
unsigned LSDAEncoding
Definition:TargetLoweringObjectFile.h:58
llvm::TargetLoweringObjectFile::supportDSOLocalEquivalentLowering
bool supportDSOLocalEquivalentLowering() const
Target supports a native lowering of a dso_local_equivalent constant without needing to replace it wi...
Definition:TargetLoweringObjectFile.h:202
llvm::TargetLoweringObjectFile::Initialize
virtual void Initialize(MCContext &ctx, const TargetMachine &TM)
This method must be called before any actual lowering is done.
Definition:TargetLoweringObjectFile.cpp:40
llvm::TargetLoweringObjectFile::getPersonalityEncoding
unsigned getPersonalityEncoding() const
Definition:TargetLoweringObjectFile.h:172
llvm::TargetLoweringObjectFile::StaticCtorSection
MCSection * StaticCtorSection
This section contains the static constructor pointer list.
Definition:TargetLoweringObjectFile.h:63
llvm::TargetLoweringObjectFile::SupportDSOLocalEquivalentLowering
bool SupportDSOLocalEquivalentLowering
Definition:TargetLoweringObjectFile.h:53
llvm::TargetLoweringObjectFile::getSectionForConstant
virtual MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const
Given a constant with the SectionKind, return a section that it should be placed in.
Definition:TargetLoweringObjectFile.cpp:374
llvm::TargetLoweringObjectFile::getSymbolWithGlobalValueBase
MCSymbol * getSymbolWithGlobalValueBase(const GlobalValue *GV, StringRef Suffix, const TargetMachine &TM) const
Return the MCSymbol for a private symbol with global value name as its base, with the specified suffi...
Definition:TargetLoweringObjectFile.cpp:127
llvm::TargetLoweringObjectFile::getTTypeGlobalReference
virtual const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const
Return an MCExpr to use for a reference to the specified global variable from exception handling info...
Definition:TargetLoweringObjectFile.cpp:397
llvm::TargetLoweringObjectFile::TTypeEncoding
unsigned TTypeEncoding
Definition:TargetLoweringObjectFile.h:59
llvm::TargetLoweringObjectFile::CallSiteEncoding
unsigned CallSiteEncoding
Definition:TargetLoweringObjectFile.h:60
llvm::TargetLoweringObjectFile::getTTypeReference
const MCExpr * getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition:TargetLoweringObjectFile.cpp:407
llvm::TargetLoweringObjectFile::SectionForGlobal
MCSection * SectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const
This method computes the appropriate section to emit the specified global variable or function defini...
Definition:TargetLoweringObjectFile.cpp:320
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition:TargetMachine.h:77
llvm::TargetMachine::getTargetTriple
const Triple & getTargetTriple() const
Definition:TargetMachine.h:126
llvm::TargetMachine::getUniqueBasicBlockSectionNames
bool getUniqueBasicBlockSectionNames() const
Return true if unique basic block section names must be generated.
Definition:TargetMachine.h:288
llvm::TargetMachine::getUniqueSectionNames
bool getUniqueSectionNames() const
Definition:TargetMachine.h:285
llvm::TargetMachine::getRelocationModel
Reloc::Model getRelocationModel() const
Returns the code generation relocation model.
Definition:TargetMachine.cpp:144
llvm::TargetMachine::Options
TargetOptions Options
Definition:TargetMachine.h:118
llvm::TargetMachine::getSymbol
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition:TargetMachine.cpp:283
llvm::TargetMachine::getDataSections
bool getDataSections() const
Return true if data objects should be emitted into their own section, corresponds to -fdata-sections.
Definition:TargetMachine.h:298
llvm::TargetMachine::getCodeModel
CodeModel::Model getCodeModel() const
Returns the code model.
Definition:TargetMachine.h:232
llvm::TargetMachine::getFunctionSections
bool getFunctionSections() const
Return true if functions should be emitted into their own section, corresponding to -ffunction-sectio...
Definition:TargetMachine.h:304
llvm::TargetMachine::getMCAsmInfo
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
Definition:TargetMachine.h:212
llvm::TargetOptions::XCOFFReadOnlyPointers
unsigned XCOFFReadOnlyPointers
When set to true, const objects with relocatable address values are put into the RO data section.
Definition:TargetOptions.h:380
llvm::TargetOptions::UseInitArray
unsigned UseInitArray
UseInitArray - Use .init_array instead of .ctors for static constructors.
Definition:TargetOptions.h:261
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition:Triple.h:44
llvm::Triple::GNUILP32
@ GNUILP32
Definition:Triple.h:259
llvm::Triple::thumbeb
@ thumbeb
Definition:Triple.h:84
llvm::Triple::sparcel
@ sparcel
Definition:Triple.h:79
llvm::Triple::loongarch32
@ loongarch32
Definition:Triple.h:61
llvm::Triple::x86
@ x86
Definition:Triple.h:85
llvm::Triple::x86_64
@ x86_64
Definition:Triple.h:86
llvm::Triple::sparcv9
@ sparcv9
Definition:Triple.h:78
llvm::Triple::ppcle
@ ppcle
Definition:Triple.h:70
llvm::Triple::ppc64le
@ ppc64le
Definition:Triple.h:72
llvm::Triple::hexagon
@ hexagon
Definition:Triple.h:60
llvm::Triple::mipsel
@ mipsel
Definition:Triple.h:65
llvm::Triple::aarch64_be
@ aarch64_be
Definition:Triple.h:52
llvm::Triple::loongarch64
@ loongarch64
Definition:Triple.h:62
llvm::Triple::mips
@ mips
Definition:Triple.h:64
llvm::Triple::arm
@ arm
Definition:Triple.h:49
llvm::Triple::lanai
@ lanai
Definition:Triple.h:102
llvm::Triple::sparc
@ sparc
Definition:Triple.h:77
llvm::Triple::mips64
@ mips64
Definition:Triple.h:66
llvm::Triple::ppc64
@ ppc64
Definition:Triple.h:71
llvm::Triple::ppc
@ ppc
Definition:Triple.h:69
llvm::Triple::thumb
@ thumb
Definition:Triple.h:83
llvm::Triple::riscv64
@ riscv64
Definition:Triple.h:76
llvm::Triple::mips64el
@ mips64el
Definition:Triple.h:67
llvm::Triple::riscv32
@ riscv32
Definition:Triple.h:75
llvm::Triple::aarch64
@ aarch64
Definition:Triple.h:51
llvm::Triple::systemz
@ systemz
Definition:Triple.h:80
llvm::Triple::aarch64_32
@ aarch64_32
Definition:Triple.h:53
llvm::Triple::armeb
@ armeb
Definition:Triple.h:50
llvm::Triple::getArch
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition:Triple.h:395
llvm::Triple::getEnvironment
EnvironmentType getEnvironment() const
Get the parsed environment type of this triple.
Definition:Triple.h:412
llvm::Triple::ELF
@ ELF
Definition:Triple.h:312
llvm::Triple::Wasm
@ Wasm
Definition:Triple.h:316
llvm::Triple::COFF
@ COFF
Definition:Triple.h:310
llvm::Triple::isOSFreeBSD
bool isOSFreeBSD() const
Definition:Triple.h:614
llvm::Triple::isArch32Bit
bool isArch32Bit() const
Test whether the architecture is 32-bit.
Definition:Triple.cpp:1738
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition:Twine.h:81
llvm::Twine::str
std::string str() const
Return the twine contents as a std::string.
Definition:Twine.cpp:17
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition:Type.h:45
llvm::Type::getPointerAddressSpace
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
llvm::Type::getArrayNumElements
uint64_t getArrayNumElements() const
llvm::Type::getPrimitiveSizeInBits
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
llvm::Value
LLVM Value Representation.
Definition:Value.h:74
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition:Value.h:255
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition:Value.cpp:1075
llvm::Value::hasName
bool hasName() const
Definition:Value.h:261
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition:Value.cpp:309
llvm::cl::opt
Definition:CommandLine.h:1423
llvm::raw_ostream::flush
void flush()
Definition:raw_ostream.h:198
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition:raw_ostream.h:661
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition:raw_ostream.h:691
Comdat.h
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
ErrorHandling.h
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
TargetMachine.h
llvm::COFF::SectionCharacteristics
SectionCharacteristics
Definition:COFF.h:297
llvm::COFF::IMAGE_SCN_LNK_REMOVE
@ IMAGE_SCN_LNK_REMOVE
Definition:COFF.h:307
llvm::COFF::IMAGE_SCN_CNT_CODE
@ IMAGE_SCN_CNT_CODE
Definition:COFF.h:302
llvm::COFF::IMAGE_SCN_MEM_READ
@ IMAGE_SCN_MEM_READ
Definition:COFF.h:335
llvm::COFF::IMAGE_SCN_MEM_EXECUTE
@ IMAGE_SCN_MEM_EXECUTE
Definition:COFF.h:334
llvm::COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA
@ IMAGE_SCN_CNT_UNINITIALIZED_DATA
Definition:COFF.h:304
llvm::COFF::IMAGE_SCN_MEM_DISCARDABLE
@ IMAGE_SCN_MEM_DISCARDABLE
Definition:COFF.h:330
llvm::COFF::IMAGE_SCN_MEM_16BIT
@ IMAGE_SCN_MEM_16BIT
Definition:COFF.h:311
llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
@ IMAGE_SCN_CNT_INITIALIZED_DATA
Definition:COFF.h:303
llvm::COFF::IMAGE_SCN_LNK_COMDAT
@ IMAGE_SCN_LNK_COMDAT
Definition:COFF.h:308
llvm::COFF::IMAGE_SCN_MEM_WRITE
@ IMAGE_SCN_MEM_WRITE
Definition:COFF.h:336
llvm::COFF::IMAGE_COMDAT_SELECT_NODUPLICATES
@ IMAGE_COMDAT_SELECT_NODUPLICATES
Definition:COFF.h:454
llvm::COFF::IMAGE_COMDAT_SELECT_LARGEST
@ IMAGE_COMDAT_SELECT_LARGEST
Definition:COFF.h:459
llvm::COFF::IMAGE_COMDAT_SELECT_SAME_SIZE
@ IMAGE_COMDAT_SELECT_SAME_SIZE
Definition:COFF.h:456
llvm::COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
Definition:COFF.h:458
llvm::COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH
@ IMAGE_COMDAT_SELECT_EXACT_MATCH
Definition:COFF.h:457
llvm::COFF::IMAGE_COMDAT_SELECT_ANY
@ IMAGE_COMDAT_SELECT_ANY
Definition:COFF.h:455
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm::CodeModel::Model
Model
Definition:CodeGen.h:31
llvm::CodeModel::Medium
@ Medium
Definition:CodeGen.h:31
llvm::CodeModel::Large
@ Large
Definition:CodeGen.h:31
llvm::CodeModel::Small
@ Small
Definition:CodeGen.h:31
llvm::ELF::SHT_LLVM_DEPENDENT_LIBRARIES
@ SHT_LLVM_DEPENDENT_LIBRARIES
Definition:ELF.h:1129
llvm::ELF::SHT_PROGBITS
@ SHT_PROGBITS
Definition:ELF.h:1098
llvm::ELF::SHT_LLVM_LINKER_OPTIONS
@ SHT_LLVM_LINKER_OPTIONS
Definition:ELF.h:1126
llvm::ELF::SHT_NOBITS
@ SHT_NOBITS
Definition:ELF.h:1105
llvm::ELF::SHT_LLVM_OFFLOADING
@ SHT_LLVM_OFFLOADING
Definition:ELF.h:1139
llvm::ELF::SHT_LLVM_LTO
@ SHT_LLVM_LTO
Definition:ELF.h:1140
llvm::ELF::SHT_PREINIT_ARRAY
@ SHT_PREINIT_ARRAY
Definition:ELF.h:1111
llvm::ELF::SHT_INIT_ARRAY
@ SHT_INIT_ARRAY
Definition:ELF.h:1109
llvm::ELF::SHT_NOTE
@ SHT_NOTE
Definition:ELF.h:1104
llvm::ELF::SHT_FINI_ARRAY
@ SHT_FINI_ARRAY
Definition:ELF.h:1110
llvm::ELF::SHF_MERGE
@ SHF_MERGE
Definition:ELF.h:1204
llvm::ELF::SHF_STRINGS
@ SHF_STRINGS
Definition:ELF.h:1207
llvm::ELF::SHF_EXCLUDE
@ SHF_EXCLUDE
Definition:ELF.h:1232
llvm::ELF::SHF_ALLOC
@ SHF_ALLOC
Definition:ELF.h:1198
llvm::ELF::SHF_LINK_ORDER
@ SHF_LINK_ORDER
Definition:ELF.h:1213
llvm::ELF::SHF_GROUP
@ SHF_GROUP
Definition:ELF.h:1220
llvm::ELF::SHF_SUNW_NODISCARD
@ SHF_SUNW_NODISCARD
Definition:ELF.h:1239
llvm::ELF::SHF_X86_64_LARGE
@ SHF_X86_64_LARGE
Definition:ELF.h:1261
llvm::ELF::SHF_GNU_RETAIN
@ SHF_GNU_RETAIN
Definition:ELF.h:1229
llvm::ELF::SHF_WRITE
@ SHF_WRITE
Definition:ELF.h:1195
llvm::ELF::SHF_TLS
@ SHF_TLS
Definition:ELF.h:1223
llvm::ELF::SHF_ARM_PURECODE
@ SHF_ARM_PURECODE
Definition:ELF.h:1293
llvm::ELF::SHF_EXECINSTR
@ SHF_EXECINSTR
Definition:ELF.h:1201
llvm::MachO::S_MOD_TERM_FUNC_POINTERS
@ S_MOD_TERM_FUNC_POINTERS
S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for termination.
Definition:MachO.h:150
llvm::MachO::S_MOD_INIT_FUNC_POINTERS
@ S_MOD_INIT_FUNC_POINTERS
S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for initialization.
Definition:MachO.h:147
llvm::Reloc::Static
@ Static
Definition:CodeGen.h:25
llvm::XCOFF::StorageClass
StorageClass
Definition:XCOFF.h:170
llvm::XCOFF::C_EXT
@ C_EXT
Definition:XCOFF.h:198
llvm::XCOFF::C_WEAKEXT
@ C_WEAKEXT
Definition:XCOFF.h:199
llvm::XCOFF::C_HIDEXT
@ C_HIDEXT
Definition:XCOFF.h:206
llvm::XCOFF::StorageMappingClass
StorageMappingClass
Storage Mapping Class definitions.
Definition:XCOFF.h:103
llvm::XCOFF::XMC_TE
@ XMC_TE
Symbol mapped at the end of TOC.
Definition:XCOFF.h:128
llvm::XCOFF::XMC_DS
@ XMC_DS
Descriptor csect.
Definition:XCOFF.h:121
llvm::XCOFF::XMC_RW
@ XMC_RW
Read Write Data.
Definition:XCOFF.h:117
llvm::XCOFF::XMC_TL
@ XMC_TL
Initialized thread-local variable.
Definition:XCOFF.h:126
llvm::XCOFF::XMC_RO
@ XMC_RO
Read Only Constant.
Definition:XCOFF.h:106
llvm::XCOFF::XMC_UA
@ XMC_UA
Unclassified - Treated as Read Write.
Definition:XCOFF.h:122
llvm::XCOFF::XMC_TD
@ XMC_TD
Scalar data item in the TOC.
Definition:XCOFF.h:120
llvm::XCOFF::XMC_UL
@ XMC_UL
Uninitialized thread-local variable.
Definition:XCOFF.h:127
llvm::XCOFF::XMC_PR
@ XMC_PR
Program Code.
Definition:XCOFF.h:105
llvm::XCOFF::XMC_BS
@ XMC_BS
BSS class (uninitialized static internal)
Definition:XCOFF.h:123
llvm::XCOFF::XMC_TC
@ XMC_TC
General TOC item.
Definition:XCOFF.h:119
llvm::XCOFF::SymbolType
SymbolType
Definition:XCOFF.h:240
llvm::XCOFF::XTY_CM
@ XTY_CM
Common csect definition. For uninitialized storage.
Definition:XCOFF.h:245
llvm::XCOFF::XTY_SD
@ XTY_SD
Csect definition for initialized storage.
Definition:XCOFF.h:242
llvm::XCOFF::XTY_ER
@ XTY_ER
External reference.
Definition:XCOFF.h:241
llvm::cl::Hidden
@ Hidden
Definition:CommandLine.h:137
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition:CommandLine.h:443
llvm::dwarf::DW_EH_PE_datarel
@ DW_EH_PE_datarel
Definition:Dwarf.h:860
llvm::dwarf::DW_EH_PE_pcrel
@ DW_EH_PE_pcrel
Definition:Dwarf.h:858
llvm::dwarf::DW_EH_PE_sdata4
@ DW_EH_PE_sdata4
Definition:Dwarf.h:855
llvm::dwarf::DW_EH_PE_sdata8
@ DW_EH_PE_sdata8
Definition:Dwarf.h:856
llvm::dwarf::DW_EH_PE_absptr
@ DW_EH_PE_absptr
Definition:Dwarf.h:847
llvm::dwarf::DW_EH_PE_udata4
@ DW_EH_PE_udata4
Definition:Dwarf.h:851
llvm::dwarf::DW_EH_PE_udata8
@ DW_EH_PE_udata8
Definition:Dwarf.h:852
llvm::dwarf::DW_EH_PE_indirect
@ DW_EH_PE_indirect
Definition:Dwarf.h:863
llvm::wasm::WASM_SEG_FLAG_RETAIN
@ WASM_SEG_FLAG_RETAIN
Definition:Wasm.h:227
llvm::wasm::WASM_SEG_FLAG_TLS
@ WASM_SEG_FLAG_TLS
Definition:Wasm.h:226
llvm::wasm::WASM_SEG_FLAG_STRINGS
@ WASM_SEG_FLAG_STRINGS
Definition:Wasm.h:225
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::Offset
@ Offset
Definition:DWP.cpp:480
llvm::ExceptionHandling::ARM
@ ARM
ARM EHABI.
llvm::getInstrProfSectionName
std::string getInstrProfSectionName(InstrProfSectKind IPSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
Return the name of the profile section corresponding to IPSK.
Definition:InstrProf.cpp:236
llvm::DK_Lowering
@ DK_Lowering
Definition:DiagnosticInfo.h:68
llvm::isNoOpWithoutInvoke
bool isNoOpWithoutInvoke(EHPersonality Pers)
Return true if this personality may be safely removed if there are no invoke instructions remaining i...
Definition:EHPersonalities.h:96
llvm::transform
OutputIt transform(R &&Range, OutputIt d_first, UnaryFunction F)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere.
Definition:STLExtras.h:1952
llvm::encodeBase64
std::string encodeBase64(InputBytes const &Bytes)
Definition:Base64.h:23
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition:Error.cpp:167
llvm::classifyEHPersonality
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
Definition:EHPersonalities.cpp:23
llvm::emitLinkerFlagsForUsedCOFF
void emitLinkerFlagsForUsedCOFF(raw_ostream &OS, const GlobalValue *GV, const Triple &T, Mangler &M)
Definition:Mangler.cpp:280
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition:Format.h:125
llvm::DiagnosticSeverity
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
Definition:DiagnosticInfo.h:49
llvm::DS_Error
@ DS_Error
Definition:DiagnosticInfo.h:50
llvm::emitLinkerFlagsForGlobalCOFF
void emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV, const Triple &TT, Mangler &Mangler)
Definition:Mangler.cpp:214
llvm::toString
const char * toString(DWARFSectionKind Kind)
Definition:DWARFUnitIndex.h:67
llvm::BBSectionsColdTextPrefix
cl::opt< std::string > BBSectionsColdTextPrefix
llvm::InstructionUniformity::Default
@ Default
The result values are uniform if and only if all operands are uniform.
llvm::Version
@ Version
Definition:PGOCtxProfWriter.h:22
llvm::MCSA_Weak
@ MCSA_Weak
.weak
Definition:MCDirectives.h:45
llvm::MCSA_ELF_TypeObject
@ MCSA_ELF_TypeObject
.type _foo, STT_OBJECT # aka @object
Definition:MCDirectives.h:25
llvm::MCSA_Hidden
@ MCSA_Hidden
.hidden (ELF)
Definition:MCDirectives.h:33
llvm::collectUsedGlobalVariables
GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallVectorImpl< GlobalValue * > &Vec, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
Definition:Module.cpp:865
llvm::PseudoProbeDescMetadataName
constexpr const char * PseudoProbeDescMetadataName
Definition:PseudoProbe.h:25
raw_ostream.h
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition:Alignment.h:39
llvm::Align::value
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition:Alignment.h:85
llvm::MBBSectionID::ExceptionSectionID
static const MBBSectionID ExceptionSectionID
Definition:MachineBasicBlock.h:68
llvm::MBBSectionID::ColdSectionID
static const MBBSectionID ColdSectionID
Definition:MachineBasicBlock.h:67
llvm::SectionName
Definition:DWARFSection.h:21
llvm::XCOFF::CsectProperties
Definition:XCOFF.h:497
llvm::cl::desc
Definition:CommandLine.h:409

Generated on Fri Jul 18 2025 11:04:25 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp