llvm.org GIT mirror llvm / 88a23b6
Move the Mangler from the AsmPrinter down to TLOF and clean up the TLOF API accordingly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281708 91177308-0d34-0410-b5e6-96231b3b80d8 Eric Christopher 3 years ago
35 changed file(s) with 213 addition(s) and 278 deletion(s). Raw diff Collapse all Expand all
5353 unsigned &Align) const override;
5454
5555 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
56 Mangler &Mang,
5756 const TargetMachine &TM) const override;
5857
5958 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
60 Mangler &Mang,
6159 const TargetMachine &TM) const override;
6260
63 MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
61 MCSection *getSectionForJumpTable(const Function &F,
6462 const TargetMachine &TM) const override;
6563
6664 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
6866
6967 /// Return an MCExpr to use for a reference to the specified type info global
7068 /// variable from exception handling information.
71 const MCExpr *
72 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
73 Mangler &Mang, const TargetMachine &TM,
74 MachineModuleInfo *MMI,
75 MCStreamer &Streamer) const override;
69 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
70 unsigned Encoding,
71 const TargetMachine &TM,
72 MachineModuleInfo *MMI,
73 MCStreamer &Streamer) const override;
7674
7775 // The symbol that gets passed to .cfi_personality.
78 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
76 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
7977 const TargetMachine &TM,
8078 MachineModuleInfo *MMI) const override;
8179
8684 const MCSymbol *KeySym) const override;
8785
8886 const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
89 const GlobalValue *RHS, Mangler &Mang,
87 const GlobalValue *RHS,
9088 const TargetMachine &TM) const override;
9189 };
9290
102100 /// Emit the module flags that specify the garbage collection information.
103101 void emitModuleFlags(MCStreamer &Streamer,
104102 ArrayRef ModuleFlags,
105 Mangler &Mang, const TargetMachine &TM) const override;
103 const TargetMachine &TM) const override;
106104
107105 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
108 Mangler &Mang,
109106 const TargetMachine &TM) const override;
110107
111108 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
112 Mangler &Mang,
113109 const TargetMachine &TM) const override;
114110
115111 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
117113 unsigned &Align) const override;
118114
119115 /// The mach-o version of this method defaults to returning a stub reference.
120 const MCExpr *
121 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
122 Mangler &Mang, const TargetMachine &TM,
123 MachineModuleInfo *MMI,
124 MCStreamer &Streamer) const override;
116 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
117 unsigned Encoding,
118 const TargetMachine &TM,
119 MachineModuleInfo *MMI,
120 MCStreamer &Streamer) const override;
125121
126122 // The symbol that gets passed to .cfi_personality.
127 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
123 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
128124 const TargetMachine &TM,
129125 MachineModuleInfo *MMI) const override;
130126
135131 MCStreamer &Streamer) const override;
136132
137133 void getNameWithPrefix(SmallVectorImpl &OutName, const GlobalValue *GV,
138 Mangler &Mang, const TargetMachine &TM) const override;
134 const TargetMachine &TM) const override;
139135 };
140136
141137
148144
149145 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
150146 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
151 Mangler &Mang,
152147 const TargetMachine &TM) const override;
153148
154149 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
155 Mangler &Mang,
156150 const TargetMachine &TM) const override;
157151
158152 void getNameWithPrefix(SmallVectorImpl &OutName, const GlobalValue *GV,
159 Mangler &Mang, const TargetMachine &TM) const override;
153 const TargetMachine &TM) const override;
160154
161 MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
155 MCSection *getSectionForJumpTable(const Function &F,
162156 const TargetMachine &TM) const override;
163157
164158 /// Emit Obj-C garbage collection and linker options. Only linker option
165159 /// emission is implemented for COFF.
166160 void emitModuleFlags(MCStreamer &Streamer,
167161 ArrayRef ModuleFlags,
168 Mangler &Mang, const TargetMachine &TM) const override;
162 const TargetMachine &TM) const override;
169163
170164 MCSection *getStaticCtorSection(unsigned Priority,
171165 const MCSymbol *KeySym) const override;
172166 MCSection *getStaticDtorSection(unsigned Priority,
173167 const MCSymbol *KeySym) const override;
174168
175 void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV,
176 const Mangler &Mang) const override;
169 void emitLinkerFlagsForGlobal(raw_ostream &OS,
170 const GlobalValue *GV) const override;
177171 };
178172
179173 } // end namespace llvm
3636 class TargetLoweringObjectFile : public MCObjectFileInfo {
3737 MCContext *Ctx;
3838
39 /// Name-mangler for global names.
40 Mangler *Mang;
41
3942 TargetLoweringObjectFile(
4043 const TargetLoweringObjectFile&) = delete;
4144 void operator=(const TargetLoweringObjectFile&) = delete;
5255
5356 public:
5457 MCContext &getContext() const { return *Ctx; }
58 Mangler &getMangler() const { return *Mang; }
5559
5660 TargetLoweringObjectFile()
57 : MCObjectFileInfo(), Ctx(nullptr), SupportIndirectSymViaGOTPCRel(false),
58 SupportGOTPCRelWithOffset(true) {}
61 : MCObjectFileInfo(), Ctx(nullptr), Mang(nullptr),
62 SupportIndirectSymViaGOTPCRel(false), SupportGOTPCRelWithOffset(true) {}
5963
6064 virtual ~TargetLoweringObjectFile();
6165
7074 /// Emit the module flags that the platform cares about.
7175 virtual void emitModuleFlags(MCStreamer &Streamer,
7276 ArrayRef Flags,
73 Mangler &Mang, const TargetMachine &TM) const {}
77 const TargetMachine &TM) const {}
7478
7579 /// Given a constant with the SectionKind, return a section that it should be
7680 /// placed in.
8892 /// variable or function definition. This should not be passed external (or
8993 /// available externally) globals.
9094 MCSection *SectionForGlobal(const GlobalValue *GV, SectionKind Kind,
91 Mangler &Mang, const TargetMachine &TM) const;
95 const TargetMachine &TM) const;
9296
9397 /// This method computes the appropriate section to emit the specified global
9498 /// variable or function definition. This should not be passed external (or
9599 /// available externally) globals.
96 MCSection *SectionForGlobal(const GlobalValue *GV, Mangler &Mang,
100 MCSection *SectionForGlobal(const GlobalValue *GV,
97101 const TargetMachine &TM) const {
98 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
102 return SectionForGlobal(GV, getKindForGlobal(GV, TM), TM);
99103 }
100104
101105 virtual void getNameWithPrefix(SmallVectorImpl &OutName,
102 const GlobalValue *GV, Mangler &Mang,
106 const GlobalValue *GV,
103107 const TargetMachine &TM) const;
104108
105 virtual MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
109 virtual MCSection *getSectionForJumpTable(const Function &F,
106110 const TargetMachine &TM) const;
107111
108112 virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
113117 /// assume that GV->hasSection() is true.
114118 virtual MCSection *
115119 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
116 Mangler &Mang, const TargetMachine &TM) const = 0;
120 const TargetMachine &TM) const = 0;
117121
118122 /// Allow the target to completely override section assignment of a global.
119 virtual const MCSection *getSpecialCasedSectionGlobals(const GlobalValue *GV,
120 SectionKind Kind,
121 Mangler &Mang) const {
123 virtual const MCSection *
124 getSpecialCasedSectionGlobals(const GlobalValue *GV, SectionKind Kind) const {
122125 return nullptr;
123126 }
124127
125128 /// Return an MCExpr to use for a reference to the specified global variable
126129 /// from exception handling information.
127 virtual const MCExpr *
128 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
129 Mangler &Mang, const TargetMachine &TM,
130 MachineModuleInfo *MMI, MCStreamer &Streamer) const;
130 virtual const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
131 unsigned Encoding,
132 const TargetMachine &TM,
133 MachineModuleInfo *MMI,
134 MCStreamer &Streamer) const;
131135
132136 /// Return the MCSymbol for a private symbol with global value name as its
133137 /// base, with the specified suffix.
134138 MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
135 StringRef Suffix, Mangler &Mang,
139 StringRef Suffix,
136140 const TargetMachine &TM) const;
137141
138142 // The symbol that gets passed to .cfi_personality.
139143 virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
140 Mangler &Mang,
141144 const TargetMachine &TM,
142145 MachineModuleInfo *MMI) const;
143146
144 const MCExpr *
145 getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
146 MCStreamer &Streamer) const;
147 const MCExpr *getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
148 MCStreamer &Streamer) const;
147149
148150 virtual MCSection *getStaticCtorSection(unsigned Priority,
149151 const MCSymbol *KeySym) const {
159161 /// emitting the address in debug info.
160162 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
161163
162 virtual const MCExpr *
163 lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS,
164 Mangler &Mang, const TargetMachine &TM) const {
164 virtual const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
165 const GlobalValue *RHS,
166 const TargetMachine &TM) const {
165167 return nullptr;
166168 }
167169
186188 return nullptr;
187189 }
188190
189 virtual void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV,
190 const Mangler &Mang) const {}
191 virtual void emitLinkerFlagsForGlobal(raw_ostream &OS,
192 const GlobalValue *GV) const {}
191193
192194 protected:
193195 virtual MCSection *SelectSectionForGlobal(const GlobalValue *GV,
194 SectionKind Kind, Mangler &Mang,
196 SectionKind Kind,
195197 const TargetMachine &TM) const = 0;
196198 };
197199
183183
184184 OutStreamer->InitSections(false);
185185
186 Mang = new Mangler();
187
188186 // Emit the version-min deplyment target directive if needed.
189187 //
190188 // FIXME: If we end up with a collection of these sorts of Darwin-specific
339337
340338 void AsmPrinter::getNameWithPrefix(SmallVectorImpl &Name,
341339 const GlobalValue *GV) const {
342 TM.getNameWithPrefix(Name, GV, *Mang);
340 TM.getNameWithPrefix(Name, GV, getObjFileLowering().getMangler());
343341 }
344342
345343 MCSymbol *AsmPrinter::getSymbol(const GlobalValue *GV) const {
346 return TM.getSymbol(GV, *Mang);
344 return TM.getSymbol(GV, getObjFileLowering().getMangler());
347345 }
348346
349347 /// EmitGlobalVariable - Emit the specified global variable to the .s file.
423421 }
424422
425423 // Determine to which section this global should be emitted.
426 MCSection *TheSection =
427 getObjFileLowering().SectionForGlobal(GV, GVKind, *Mang, TM);
424 MCSection *TheSection = getObjFileLowering().SectionForGlobal(GV, GVKind, TM);
428425
429426 // If we have a bss global going to a section that supports the
430427 // zerofill directive, do so here.
482479 if (GVKind.isThreadLocal() && MAI->hasMachoTBSSDirective()) {
483480 // Emit the .tbss symbol
484481 MCSymbol *MangSym =
485 OutContext.getOrCreateSymbol(GVSym->getName() + Twine("$tlv$init"));
482 OutContext.getOrCreateSymbol(GVSym->getName() + Twine("$tlv$init"));
486483
487484 if (GVKind.isThreadBSS()) {
488485 TheSection = getObjFileLowering().getTLSBSSSection();
549546 // Print the 'header' of function.
550547 const Function *F = MF->getFunction();
551548
552 OutStreamer->SwitchSection(
553 getObjFileLowering().SectionForGlobal(F, *Mang, TM));
549 OutStreamer->SwitchSection(getObjFileLowering().SectionForGlobal(F, TM));
554550 EmitVisibility(CurrentFnSym, F->getVisibility());
555551
556552 EmitLinkage(F, CurrentFnSym);
11421138 SmallVector ModuleFlags;
11431139 M.getModuleFlagsMetadata(ModuleFlags);
11441140 if (!ModuleFlags.empty())
1145 TLOF.emitModuleFlags(*OutStreamer, ModuleFlags, *Mang, TM);
1141 TLOF.emitModuleFlags(*OutStreamer, ModuleFlags, TM);
11461142
11471143 if (TM.getTargetTriple().isOSBinFormatELF()) {
11481144 MachineModuleInfoELF &MMIELF = MMI->getObjFileInfo();
12451241 // after everything else has gone out.
12461242 EmitEndOfAsmFile(M);
12471243
1248 delete Mang; Mang = nullptr;
12491244 MMI = nullptr;
12501245
12511246 OutStreamer->Finish();
13911386 *F);
13921387 if (JTInDiffSection) {
13931388 // Drop it in the readonly section.
1394 MCSection *ReadOnlySection = TLOF.getSectionForJumpTable(*F, *Mang, TM);
1389 MCSection *ReadOnlySection = TLOF.getSectionForJumpTable(*F, TM);
13951390 OutStreamer->SwitchSection(ReadOnlySection);
13961391 }
13971392
18301825 APInt RHSOffset;
18311826 if (IsConstantOffsetFromGlobal(CE->getOperand(1), RHSGV, RHSOffset,
18321827 getDataLayout())) {
1833 const MCExpr *RelocExpr = getObjFileLowering().lowerRelativeReference(
1834 LHSGV, RHSGV, *Mang, TM);
1828 const MCExpr *RelocExpr =
1829 getObjFileLowering().lowerRelativeReference(LHSGV, RHSGV, TM);
18351830 if (!RelocExpr)
18361831 RelocExpr = MCBinaryExpr::createSub(
18371832 MCSymbolRefExpr::create(getSymbol(LHSGV), Ctx),
23722367
23732368 MCSymbol *AsmPrinter::getSymbolWithGlobalValueBase(const GlobalValue *GV,
23742369 StringRef Suffix) const {
2375 return getObjFileLowering().getSymbolWithGlobalValueBase(GV, Suffix, *Mang,
2376 TM);
2370 return getObjFileLowering().getSymbolWithGlobalValueBase(GV, Suffix, TM);
23772371 }
23782372
23792373 /// Return the MCSymbol for the specified ExternalSymbol.
137137 const TargetLoweringObjectFile &TLOF = getObjFileLowering();
138138
139139 const MCExpr *Exp =
140 TLOF.getTTypeGlobalReference(GV, Encoding, *Mang, TM, MMI,
141 *OutStreamer);
140 TLOF.getTTypeGlobalReference(GV, Encoding, TM, MMI, *OutStreamer);
142141 OutStreamer->EmitValue(Exp, GetSizeOfEncodedValue(Encoding));
143142 } else
144143 OutStreamer->EmitIntValue(0, GetSizeOfEncodedValue(Encoding));
159159
160160 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
161161 unsigned PerEncoding = TLOF.getPersonalityEncoding();
162 const MCSymbol *Sym =
163 TLOF.getCFIPersonalitySymbol(P, *Asm->Mang, Asm->TM, MMI);
162 const MCSymbol *Sym = TLOF.getCFIPersonalitySymbol(P, Asm->TM, MMI);
164163 Asm->OutStreamer->EmitCFIPersonality(Sym, PerEncoding);
165164
166165 // Provide LSDA information.
203203 if (F->hasPersonalityFn())
204204 PerFn = dyn_cast(F->getPersonalityFn()->stripPointerCasts());
205205 const MCSymbol *PersHandlerSym =
206 TLOF.getCFIPersonalitySymbol(PerFn, *Asm->Mang, Asm->TM, MMI);
206 TLOF.getCFIPersonalitySymbol(PerFn, Asm->TM, MMI);
207207
208208 // Classify the personality routine so that we may reason about it.
209209 EHPersonality Per = EHPersonality::Unknown;
4949 //===----------------------------------------------------------------------===//
5050
5151 MCSymbol *TargetLoweringObjectFileELF::getCFIPersonalitySymbol(
52 const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
52 const GlobalValue *GV, const TargetMachine &TM,
5353 MachineModuleInfo *MMI) const {
5454 unsigned Encoding = getPersonalityEncoding();
5555 if ((Encoding & 0x80) == dwarf::DW_EH_PE_indirect)
5656 return getContext().getOrCreateSymbol(StringRef("DW.ref.") +
57 TM.getSymbol(GV, Mang)->getName());
57 TM.getSymbol(GV, getMangler())->getName());
5858 if ((Encoding & 0x70) == dwarf::DW_EH_PE_absptr)
59 return TM.getSymbol(GV, Mang);
59 return TM.getSymbol(GV, getMangler());
6060 report_fatal_error("We do not support this DWARF encoding yet!");
6161 }
6262
8383 }
8484
8585 const MCExpr *TargetLoweringObjectFileELF::getTTypeGlobalReference(
86 const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
87 const TargetMachine &TM, MachineModuleInfo *MMI,
88 MCStreamer &Streamer) const {
86 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
87 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
8988
9089 if (Encoding & dwarf::DW_EH_PE_indirect) {
9190 MachineModuleInfoELF &ELFMMI = MMI->getObjFileInfo();
9291
93 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, ".DW.stub", Mang, TM);
92 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, ".DW.stub", TM);
9493
9594 // Add information about the stub reference to ELFMMI so that the stub
9695 // gets emitted by the asmprinter.
9796 MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym);
9897 if (!StubSym.getPointer()) {
99 MCSymbol *Sym = TM.getSymbol(GV, Mang);
98 MCSymbol *Sym = TM.getSymbol(GV, getMangler());
10099 StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
101100 }
102101
105104 Encoding & ~dwarf::DW_EH_PE_indirect, Streamer);
106105 }
107106
108 return TargetLoweringObjectFile::
109 getTTypeGlobalReference(GV, Encoding, Mang, TM, MMI, Streamer);
107 return TargetLoweringObjectFile::getTTypeGlobalReference(GV, Encoding, TM,
108 MMI, Streamer);
110109 }
111110
112111 static SectionKind
204203 }
205204
206205 MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
207 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
208 const TargetMachine &TM) const {
206 const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
209207 StringRef SectionName = GV->getSection();
210208
211209 // Infer section flags from the section name if we can.
309307 }
310308
311309 MCSection *TargetLoweringObjectFileELF::SelectSectionForGlobal(
312 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
313 const TargetMachine &TM) const {
310 const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
314311 unsigned Flags = getELFSectionFlags(Kind);
315312
316313 // If we have -ffunction-section or -fdata-section then we should emit the
324321 }
325322 EmitUniqueSection |= GV->hasComdat();
326323
327 return selectELFSectionForGlobal(getContext(), GV, Kind, Mang, TM,
324 return selectELFSectionForGlobal(getContext(), GV, Kind, getMangler(), TM,
328325 EmitUniqueSection, Flags, &NextUniqueID);
329326 }
330327
331328 MCSection *TargetLoweringObjectFileELF::getSectionForJumpTable(
332 const Function &F, Mangler &Mang, const TargetMachine &TM) const {
329 const Function &F, const TargetMachine &TM) const {
333330 // If the function can be removed, produce a unique section so that
334331 // the table doesn't prevent the removal.
335332 const Comdat *C = F.getComdat();
338335 return ReadOnlySection;
339336
340337 return selectELFSectionForGlobal(getContext(), &F, SectionKind::getReadOnly(),
341 Mang, TM, EmitUniqueSection, ELF::SHF_ALLOC,
338 getMangler(), TM, EmitUniqueSection, ELF::SHF_ALLOC,
342339 &NextUniqueID);
343340 }
344341
422419 }
423420
424421 const MCExpr *TargetLoweringObjectFileELF::lowerRelativeReference(
425 const GlobalValue *LHS, const GlobalValue *RHS, Mangler &Mang,
422 const GlobalValue *LHS, const GlobalValue *RHS,
426423 const TargetMachine &TM) const {
427424 // We may only use a PLT-relative relocation to refer to unnamed_addr
428425 // functions.
436433 return nullptr;
437434
438435 return MCBinaryExpr::createSub(
439 MCSymbolRefExpr::create(TM.getSymbol(LHS, Mang), PLTRelativeVariantKind,
436 MCSymbolRefExpr::create(TM.getSymbol(LHS, getMangler()), PLTRelativeVariantKind,
440437 getContext()),
441 MCSymbolRefExpr::create(TM.getSymbol(RHS, Mang), getContext()),
438 MCSymbolRefExpr::create(TM.getSymbol(RHS, getMangler()), getContext()),
442439 getContext());
443440 }
444441
489486 }
490487
491488 /// emitModuleFlags - Perform code emission for module flags.
492 void TargetLoweringObjectFileMachO::
493 emitModuleFlags(MCStreamer &Streamer,
494 ArrayRef ModuleFlags,
495 Mangler &Mang, const TargetMachine &TM) const {
489 void TargetLoweringObjectFileMachO::emitModuleFlags(
490 MCStreamer &Streamer, ArrayRef ModuleFlags,
491 const TargetMachine &TM) const {
496492 unsigned VersionVal = 0;
497493 unsigned ImageInfoFlags = 0;
498494 MDNode *LinkerOptions = nullptr;
566562 }
567563
568564 MCSection *TargetLoweringObjectFileMachO::getExplicitSectionGlobal(
569 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
570 const TargetMachine &TM) const {
565 const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
571566 // Parse the section specifier and create it if valid.
572567 StringRef Segment, Section;
573568 unsigned TAA = 0, StubSize = 0;
608603 }
609604
610605 MCSection *TargetLoweringObjectFileMachO::SelectSectionForGlobal(
611 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
612 const TargetMachine &TM) const {
606 const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
613607 checkMachOComdat(GV);
614608
615609 // Handle thread local data.
694688 }
695689
696690 const MCExpr *TargetLoweringObjectFileMachO::getTTypeGlobalReference(
697 const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
698 const TargetMachine &TM, MachineModuleInfo *MMI,
699 MCStreamer &Streamer) const {
691 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
692 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
700693 // The mach-o version of this method defaults to returning a stub reference.
701694
702695 if (Encoding & DW_EH_PE_indirect) {
703696 MachineModuleInfoMachO &MachOMMI =
704697 MMI->getObjFileInfo();
705698
706 MCSymbol *SSym =
707 getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", Mang, TM);
699 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", TM);
708700
709701 // Add information about the stub reference to MachOMMI so that the stub
710702 // gets emitted by the asmprinter.
711703 MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
712704 if (!StubSym.getPointer()) {
713 MCSymbol *Sym = TM.getSymbol(GV, Mang);
705 MCSymbol *Sym = TM.getSymbol(GV, getMangler());
714706 StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
715707 }
716708
719711 Encoding & ~dwarf::DW_EH_PE_indirect, Streamer);
720712 }
721713
722 return TargetLoweringObjectFile::getTTypeGlobalReference(GV, Encoding, Mang,
723 TM, MMI, Streamer);
714 return TargetLoweringObjectFile::getTTypeGlobalReference(GV, Encoding, TM,
715 MMI, Streamer);
724716 }
725717
726718 MCSymbol *TargetLoweringObjectFileMachO::getCFIPersonalitySymbol(
727 const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
719 const GlobalValue *GV, const TargetMachine &TM,
728720 MachineModuleInfo *MMI) const {
729721 // The mach-o version of this method defaults to returning a stub reference.
730722 MachineModuleInfoMachO &MachOMMI =
731723 MMI->getObjFileInfo();
732724
733 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", Mang, TM);
725 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", TM);
734726
735727 // Add information about the stub reference to MachOMMI so that the stub
736728 // gets emitted by the asmprinter.
737729 MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
738730 if (!StubSym.getPointer()) {
739 MCSymbol *Sym = TM.getSymbol(GV, Mang);
731 MCSymbol *Sym = TM.getSymbol(GV, getMangler());
740732 StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
741733 }
742734
817809 }
818810
819811 void TargetLoweringObjectFileMachO::getNameWithPrefix(
820 SmallVectorImpl &OutName, const GlobalValue *GV, Mangler &Mang,
812 SmallVectorImpl &OutName, const GlobalValue *GV,
821813 const TargetMachine &TM) const {
822814 SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM);
823 const MCSection *TheSection = SectionForGlobal(GV, GVKind, Mang, TM);
815 const MCSection *TheSection = SectionForGlobal(GV, GVKind, TM);
824816 bool CannotUsePrivateLabel =
825817 !canUsePrivateLabel(*TM.getMCAsmInfo(), *TheSection);
826 Mang.getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
818 getMangler().getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
827819 }
828820
829821 //===----------------------------------------------------------------------===//
910902 }
911903
912904 MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal(
913 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
914 const TargetMachine &TM) const {
905 const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
915906 int Selection = 0;
916907 unsigned Characteristics = getCOFFSectionFlags(Kind, TM);
917908 StringRef Name = GV->getSection();
925916 ComdatGV = GV;
926917
927918 if (!ComdatGV->hasPrivateLinkage()) {
928 MCSymbol *Sym = TM.getSymbol(ComdatGV, Mang);
919 MCSymbol *Sym = TM.getSymbol(ComdatGV, getMangler());
929920 COMDATSymName = Sym->getName();
930921 Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
931922 } else {
950941 }
951942
952943 MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
953 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
954 const TargetMachine &TM) const {
944 const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
955945 // If we have -ffunction-sections then we should emit the global value to a
956946 // uniqued section specifically for it.
957947 bool EmitUniquedSection;
979969 UniqueID = NextUniqueID++;
980970
981971 if (!ComdatGV->hasPrivateLinkage()) {
982 MCSymbol *Sym = TM.getSymbol(ComdatGV, Mang);
972 MCSymbol *Sym = TM.getSymbol(ComdatGV, getMangler());
983973 StringRef COMDATSymName = Sym->getName();
984974 return getContext().getCOFFSection(Name, Characteristics, Kind,
985975 COMDATSymName, Selection, UniqueID);
986976 } else {
987977 SmallString<256> TmpData;
988 Mang.getNameWithPrefix(TmpData, GV, /*CannotUsePrivateLabel=*/true);
978 getMangler().getNameWithPrefix(TmpData, GV, /*CannotUsePrivateLabel=*/true);
989979 return getContext().getCOFFSection(Name, Characteristics, Kind, TmpData,
990980 Selection, UniqueID);
991981 }
10101000 }
10111001
10121002 void TargetLoweringObjectFileCOFF::getNameWithPrefix(
1013 SmallVectorImpl &OutName, const GlobalValue *GV, Mangler &Mang,
1003 SmallVectorImpl &OutName, const GlobalValue *GV,
10141004 const TargetMachine &TM) const {
10151005 bool CannotUsePrivateLabel = false;
10161006 if (GV->hasPrivateLinkage() &&
10181008 (isa(GV) && TM.getDataSections())))
10191009 CannotUsePrivateLabel = true;
10201010
1021 Mang.getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
1011 getMangler().getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
10221012 }
10231013
10241014 MCSection *TargetLoweringObjectFileCOFF::getSectionForJumpTable(
1025 const Function &F, Mangler &Mang, const TargetMachine &TM) const {
1015 const Function &F, const TargetMachine &TM) const {
10261016 // If the function can be removed, produce a unique section so that
10271017 // the table doesn't prevent the removal.
10281018 const Comdat *C = F.getComdat();
10341024 if (F.hasPrivateLinkage())
10351025 return ReadOnlySection;
10361026
1037 MCSymbol *Sym = TM.getSymbol(&F, Mang);
1027 MCSymbol *Sym = TM.getSymbol(&F, getMangler());
10381028 StringRef COMDATSymName = Sym->getName();
10391029
10401030 SectionKind Kind = SectionKind::getReadOnly();
10471037 COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE, UniqueID);
10481038 }
10491039
1050 void TargetLoweringObjectFileCOFF::
1051 emitModuleFlags(MCStreamer &Streamer,
1052 ArrayRef ModuleFlags,
1053 Mangler &Mang, const TargetMachine &TM) const {
1040 void TargetLoweringObjectFileCOFF::emitModuleFlags(
1041 MCStreamer &Streamer, ArrayRef ModuleFlags,
1042 const TargetMachine &TM) const {
10541043 MDNode *LinkerOptions = nullptr;
10551044
10561045 for (const auto &MFE : ModuleFlags) {
11141103 }
11151104
11161105 void TargetLoweringObjectFileCOFF::emitLinkerFlagsForGlobal(
1117 raw_ostream &OS, const GlobalValue *GV, const Mangler &Mang) const {
1106 raw_ostream &OS, const GlobalValue *GV) const {
11181107 if (!GV->hasDLLExportStorageClass() || GV->isDeclaration())
11191108 return;
11201109
11281117 if (TT.isWindowsGNUEnvironment() || TT.isWindowsCygwinEnvironment()) {
11291118 std::string Flag;
11301119 raw_string_ostream FlagOS(Flag);
1131 Mang.getNameWithPrefix(FlagOS, GV, false);
1120 getMangler().getNameWithPrefix(FlagOS, GV, false);
11321121 FlagOS.flush();
11331122 if (Flag[0] == GV->getParent()->getDataLayout().getGlobalPrefix())
11341123 OS << Flag.substr(1);
11351124 else
11361125 OS << Flag;
11371126 } else {
1138 Mang.getNameWithPrefix(OS, GV, false);
1127 getMangler().getNameWithPrefix(OS, GV, false);
11391128 }
11401129
11411130 if (!GV->getValueType()->isFunctionTy()) {
1818 #include "llvm/IR/Constants.h"
1919 #include "llvm/IR/DiagnosticPrinter.h"
2020 #include "llvm/IR/LLVMContext.h"
21 #include "llvm/IR/Mangler.h"
2221 #include "llvm/IR/Metadata.h"
2322 #include "llvm/IR/Module.h"
2423 #include "llvm/MC/MCExpr.h"
647646 }
648647
649648 // Globals
650 Mangler Mang;
651649 for (const NameAndAttributes &Sym : _symbols) {
652650 if (!Sym.symbol)
653651 continue;
654 _target->getObjFileLowering()->emitLinkerFlagsForGlobal(OS, Sym.symbol,
655 Mang);
652 _target->getObjFileLowering()->emitLinkerFlagsForGlobal(OS, Sym.symbol);
656653 }
657654
658655 // Add other interesting metadata here.
2929 }
3030
3131 const MCExpr *AArch64_MachoTargetObjectFile::getTTypeGlobalReference(
32 const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
33 const TargetMachine &TM, MachineModuleInfo *MMI,
34 MCStreamer &Streamer) const {
32 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
33 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
3534 // On Darwin, we can reference dwarf symbols with foo@GOT-., which
3635 // is an indirect pc-relative reference. The default implementation
3736 // won't reference using the GOT, so we need this target-specific
3837 // version.
3938 if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
40 const MCSymbol *Sym = TM.getSymbol(GV, Mang);
39 const MCSymbol *Sym = TM.getSymbol(GV, getMangler());
4140 const MCExpr *Res =
4241 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
4342 MCSymbol *PCSym = getContext().createTempSymbol();
4746 }
4847
4948 return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
50 GV, Encoding, Mang, TM, MMI, Streamer);
49 GV, Encoding, TM, MMI, Streamer);
5150 }
5251
5352 MCSymbol *AArch64_MachoTargetObjectFile::getCFIPersonalitySymbol(
54 const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
53 const GlobalValue *GV, const TargetMachine &TM,
5554 MachineModuleInfo *MMI) const {
56 return TM.getSymbol(GV, Mang);
55 return TM.getSymbol(GV, getMangler());
5756 }
5857
5958 const MCExpr *AArch64_MachoTargetObjectFile::getIndirectSymViaGOTPCRel(
2626 AArch64_MachoTargetObjectFile();
2727
2828 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
29 unsigned Encoding, Mangler &Mang,
29 unsigned Encoding,
3030 const TargetMachine &TM,
3131 MachineModuleInfo *MMI,
3232 MCStreamer &Streamer) const override;
3333
34 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
34 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
3535 const TargetMachine &TM,
3636 MachineModuleInfo *MMI) const override;
3737
1919 // Generic Object File
2020 //===----------------------------------------------------------------------===//
2121
22 MCSection *AMDGPUTargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV,
23 SectionKind Kind,
24 Mangler &Mang,
25 const TargetMachine &TM) const {
22 MCSection *AMDGPUTargetObjectFile::SelectSectionForGlobal(
23 const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
2624 if (Kind.isReadOnly() && AMDGPU::isReadOnlySegment(GV))
2725 return TextSection;
2826
29 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang, TM);
27 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM);
3028 }
2323 class AMDGPUTargetObjectFile : public TargetLoweringObjectFileELF {
2424 public:
2525 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
26 Mangler &Mang,
2726 const TargetMachine &TM) const override;
2827 };
2928
542542 raw_string_ostream OS(Flags);
543543
544544 for (const auto &Function : M)
545 TLOF.emitLinkerFlagsForGlobal(OS, &Function, *Mang);
545 TLOF.emitLinkerFlagsForGlobal(OS, &Function);
546546 for (const auto &Global : M.globals())
547 TLOF.emitLinkerFlagsForGlobal(OS, &Global, *Mang);
547 TLOF.emitLinkerFlagsForGlobal(OS, &Global);
548548 for (const auto &Alias : M.aliases())
549 TLOF.emitLinkerFlagsForGlobal(OS, &Alias, *Mang);
549 TLOF.emitLinkerFlagsForGlobal(OS, &Alias);
550550
551551 OS.flush();
552552
4040 }
4141
4242 const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(
43 const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
44 const TargetMachine &TM, MachineModuleInfo *MMI,
45 MCStreamer &Streamer) const {
43 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
44 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
4645 if (TM.getMCAsmInfo()->getExceptionHandlingType() != ExceptionHandling::ARM)
4746 return TargetLoweringObjectFileELF::getTTypeGlobalReference(
48 GV, Encoding, Mang, TM, MMI, Streamer);
47 GV, Encoding, TM, MMI, Streamer);
4948
5049 assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
5150
52 return MCSymbolRefExpr::create(TM.getSymbol(GV, Mang),
51 return MCSymbolRefExpr::create(TM.getSymbol(GV, getMangler()),
5352 MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
5453 }
5554
2727
2828 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
2929
30 const MCExpr *
31 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
32 Mangler &Mang, const TargetMachine &TM,
33 MachineModuleInfo *MMI,
34 MCStreamer &Streamer) const override;
30 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
31 unsigned Encoding,
32 const TargetMachine &TM,
33 MachineModuleInfo *MMI,
34 MCStreamer &Streamer) const override;
3535
3636 /// \brief Describe a TLS variable address within debug info.
3737 const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const override;
9999 ELF::SHF_HEX_GPREL);
100100 }
101101
102
103102 MCSection *HexagonTargetObjectFile::SelectSectionForGlobal(
104 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
105 const TargetMachine &TM) const {
103 const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
106104 TRACE("[SelectSectionForGlobal] GV(" << GV->getName() << ") ");
107105 TRACE("input section(" << GV->getSection() << ") ");
108106
117115 << (Kind.isBSSLocal() ? "kind_bss_local " : "" ));
118116
119117 if (isGlobalInSmallSection(GV, TM))
120 return selectSmallSectionForGlobal(GV, Kind, Mang, TM);
118 return selectSmallSectionForGlobal(GV, Kind, TM);
121119
122120 if (Kind.isCommon()) {
123121 // This is purely for LTO+Linker Script because commons don't really have a
129127
130128 TRACE("default_ELF_section\n");
131129 // Otherwise, we work the same as ELF.
132 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind,
133 Mang, TM);
134 }
135
130 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM);
131 }
136132
137133 MCSection *HexagonTargetObjectFile::getExplicitSectionGlobal(
138 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
139 const TargetMachine &TM) const {
134 const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
140135 TRACE("[getExplicitSectionGlobal] GV(" << GV->getName() << ") from("
141136 << GV->getSection() << ") ");
142137 TRACE((GV->hasPrivateLinkage() ? "private_linkage " : "")
160155 }
161156
162157 if (isGlobalInSmallSection(GV, TM))
163 return selectSmallSectionForGlobal(GV, Kind, Mang, TM);
158 return selectSmallSectionForGlobal(GV, Kind, TM);
164159
165160 // Otherwise, we work the same as ELF.
166161 TRACE("default_ELF_section\n");
167 return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GV, Kind,
168 Mang, TM);
162 return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GV, Kind, TM);
169163 }
170164
171165
301295 return 0;
302296 }
303297
304
305298 MCSection *HexagonTargetObjectFile::selectSmallSectionForGlobal(
306 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
307 const TargetMachine &TM) const {
299 const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
308300 const Type *GTy = GV->getType()->getElementType();
309301 unsigned Size = getSmallestAddressableSize(GTy, GV, TM);
310302
385377
386378 TRACE("default ELF section\n");
387379 // Otherwise, we work the same as ELF.
388 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind,
389 Mang, TM);
390 }
380 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM);
381 }
1919 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
2020
2121 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
22 Mangler &Mang, const TargetMachine &TM) const override;
22 const TargetMachine &TM) const override;
2323
2424 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
25 Mangler &Mang, const TargetMachine &TM) const override;
25 const TargetMachine &TM) const override;
2626
2727 bool isGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM)
2828 const;
3939 const TargetMachine &TM) const;
4040
4141 MCSection *selectSmallSectionForGlobal(const GlobalValue *GV,
42 SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const;
42 SectionKind Kind,
43 const TargetMachine &TM) const;
4344 };
4445
4546 } // namespace llvm
8989 GV->getParent()->getDataLayout().getTypeAllocSize(Ty));
9090 }
9191
92 MCSection *
93 LanaiTargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV,
94 SectionKind Kind, Mangler &Mang,
95 const TargetMachine &TM) const {
92 MCSection *LanaiTargetObjectFile::SelectSectionForGlobal(
93 const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
9694 // Handle Small Section classification here.
9795 if (Kind.isBSS() && isGlobalInSmallSection(GV, TM, Kind))
9896 return SmallBSSSection;
10098 return SmallDataSection;
10199
102100 // Otherwise, we work the same as ELF.
103 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang,
104 TM);
101 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM);
105102 }
106103
107104 /// Return true if this constant should be placed into small data section.
3030 const TargetMachine &TM) const;
3131
3232 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
33 Mangler &Mang,
3433 const TargetMachine &TM) const override;
3534
3635 /// Return true if this constant should be placed into small data section.
112112 GV->getParent()->getDataLayout().getTypeAllocSize(Ty));
113113 }
114114
115 MCSection *
116 MipsTargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV,
117 SectionKind Kind, Mangler &Mang,
118 const TargetMachine &TM) const {
115 MCSection *MipsTargetObjectFile::SelectSectionForGlobal(
116 const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
119117 // TODO: Could also support "weak" symbols as well with ".gnu.linkonce.s.*"
120118 // sections?
121119
126124 return SmallDataSection;
127125
128126 // Otherwise, we work the same as ELF.
129 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang,TM);
127 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM);
130128 }
131129
132130 /// Return true if this constant should be placed into small data section.
3131 const TargetMachine &TM) const;
3232
3333 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
34 Mangler &Mang,
3534 const TargetMachine &TM) const override;
3635
3736 /// Return true if this constant should be placed into small data section.
45754575 delete static_cast(DwarfMacinfoSection);
45764576 }
45774577
4578 MCSection *
4579 NVPTXTargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV,
4580 SectionKind Kind, Mangler &Mang,
4581 const TargetMachine &TM) const {
4578 MCSection *NVPTXTargetObjectFile::SelectSectionForGlobal(
4579 const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
45824580 return getDataSection();
45834581 }
9191 }
9292
9393 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
94 Mangler &Mang,
9594 const TargetMachine &TM) const override {
9695 return DataSection;
9796 }
9897
9998 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
100 Mangler &Mang,
10199 const TargetMachine &TM) const override;
102100 };
103101
2222 }
2323
2424 MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal(
25 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
26 const TargetMachine &TM) const {
25 const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
2726 // Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI
2827 // when we have a constant that contains global relocations. This is
2928 // necessary because of this ABI's handling of pointers to functions in
4544 Kind = SectionKind::getReadOnlyWithRel();
4645 }
4746
48 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind,
49 Mang, TM);
47 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM);
5048 }
5149
5250 const MCExpr *PPC64LinuxTargetObjectFile::
2222 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
2323
2424 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
25 Mangler &Mang,
2625 const TargetMachine &TM) const override;
2726
2827 /// \brief Describe a TLS variable address within debug info.
1515 using namespace llvm;
1616
1717 const MCExpr *SparcELFTargetObjectFile::getTTypeGlobalReference(
18 const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
19 const TargetMachine &TM, MachineModuleInfo *MMI,
20 MCStreamer &Streamer) const {
18 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
19 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
2120
2221 if (Encoding & dwarf::DW_EH_PE_pcrel) {
2322 MachineModuleInfoELF &ELFMMI = MMI->getObjFileInfo();
2423
25 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, ".DW.stub", Mang, TM);
24 MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, ".DW.stub", TM);
2625
2726 // Add information about the stub reference to ELFMMI so that the stub
2827 // gets emitted by the asmprinter.
2928 MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym);
3029 if (!StubSym.getPointer()) {
31 MCSymbol *Sym = TM.getSymbol(GV, Mang);
30 MCSymbol *Sym = TM.getSymbol(GV, getMangler());
3231 StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
3332 }
3433
3736 MCSymbolRefExpr::create(SSym, Ctx), Ctx);
3837 }
3938
40 return TargetLoweringObjectFileELF::getTTypeGlobalReference(
41 GV, Encoding, Mang, TM, MMI, Streamer);
39 return TargetLoweringObjectFileELF::getTTypeGlobalReference(GV, Encoding, TM,
40 MMI, Streamer);
4241 }
2222 TargetLoweringObjectFileELF()
2323 {}
2424
25 const MCExpr *
26 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
27 Mangler &Mang, const TargetMachine &TM,
28 MachineModuleInfo *MMI,
29 MCStreamer &Streamer) const override;
25 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
26 unsigned Encoding,
27 const TargetMachine &TM,
28 MachineModuleInfo *MMI,
29 MCStreamer &Streamer) const override;
3030 };
3131
3232 } // end namespace llvm
4242 void TargetLoweringObjectFile::Initialize(MCContext &ctx,
4343 const TargetMachine &TM) {
4444 Ctx = &ctx;
45 Mang = new Mangler();
4546 InitMCObjectFileInfo(TM.getTargetTriple(), TM.isPositionIndependent(),
4647 TM.getCodeModel(), *Ctx);
4748 }
4849
4950 TargetLoweringObjectFile::~TargetLoweringObjectFile() {
51 delete Mang;
5052 }
5153
5254 static bool isSuitableForBSS(const GlobalVariable *GV, bool NoZerosInBSS) {
100102 }
101103
102104 MCSymbol *TargetLoweringObjectFile::getSymbolWithGlobalValueBase(
103 const GlobalValue *GV, StringRef Suffix, Mangler &Mang,
104 const TargetMachine &TM) const {
105 const GlobalValue *GV, StringRef Suffix, const TargetMachine &TM) const {
105106 assert(!Suffix.empty());
106107
107108 SmallString<60> NameStr;
108109 NameStr += GV->getParent()->getDataLayout().getPrivateGlobalPrefix();
109 TM.getNameWithPrefix(NameStr, GV, Mang);
110 TM.getNameWithPrefix(NameStr, GV, *Mang);
110111 NameStr.append(Suffix.begin(), Suffix.end());
111112 return Ctx->getOrCreateSymbol(NameStr);
112113 }
113114
114115 MCSymbol *TargetLoweringObjectFile::getCFIPersonalitySymbol(
115 const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
116 const GlobalValue *GV, const TargetMachine &TM,
116117 MachineModuleInfo *MMI) const {
117 return TM.getSymbol(GV, Mang);
118 return TM.getSymbol(GV, *Mang);
118119 }
119120
120121 void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
229230 /// This method computes the appropriate section to emit the specified global
230231 /// variable or function definition. This should not be passed external (or
231232 /// available externally) globals.
232 MCSection *
233 TargetLoweringObjectFile::SectionForGlobal(const GlobalValue *GV,
234 SectionKind Kind, Mangler &Mang,
235 const TargetMachine &TM) const {
233 MCSection *TargetLoweringObjectFile::SectionForGlobal(
234 const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
236235 // Select section name.
237236 if (GV->hasSection())
238 return getExplicitSectionGlobal(GV, Kind, Mang, TM);
239
237 return getExplicitSectionGlobal(GV, Kind, TM);
240238
241239 // Use default section depending on the 'type' of global
242 return SelectSectionForGlobal(GV, Kind, Mang, TM);
240 return SelectSectionForGlobal(GV, Kind, TM);
243241 }
244242
245243 MCSection *TargetLoweringObjectFile::getSectionForJumpTable(
246 const Function &F, Mangler &Mang, const TargetMachine &TM) const {
244 const Function &F, const TargetMachine &TM) const {
247245 unsigned Align = 0;
248246 return getSectionForConstant(F.getParent()->getDataLayout(),
249247 SectionKind::getReadOnly(), /*C=*/nullptr,
283281 /// reference to the specified global variable from exception
284282 /// handling information.
285283 const MCExpr *TargetLoweringObjectFile::getTTypeGlobalReference(
286 const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
287 const TargetMachine &TM, MachineModuleInfo *MMI,
288 MCStreamer &Streamer) const {
284 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
285 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
289286 const MCSymbolRefExpr *Ref =
290 MCSymbolRefExpr::create(TM.getSymbol(GV, Mang), getContext());
287 MCSymbolRefExpr::create(TM.getSymbol(GV, *Mang), getContext());
291288
292289 return getTTypeReference(Ref, Encoding, Streamer);
293290 }
319316 }
320317
321318 void TargetLoweringObjectFile::getNameWithPrefix(
322 SmallVectorImpl &OutName, const GlobalValue *GV, Mangler &Mang,
319 SmallVectorImpl &OutName, const GlobalValue *GV,
323320 const TargetMachine &TM) const {
324 Mang.getNameWithPrefix(OutName, GV, /*CannotUsePrivateLabel=*/false);
325 }
321 Mang->getNameWithPrefix(OutName, GV, /*CannotUsePrivateLabel=*/false);
322 }
207207 return;
208208 }
209209 const TargetLoweringObjectFile *TLOF = getObjFileLowering();
210 TLOF->getNameWithPrefix(Name, GV, Mang, *this);
210 TLOF->getNameWithPrefix(Name, GV, *this);
211211 }
212212
213213 MCSymbol *TargetMachine::getSymbol(const GlobalValue *GV, Mangler &Mang) const {
626626 raw_string_ostream FlagsOS(Flags);
627627
628628 for (const auto &Function : M)
629 TLOFCOFF.emitLinkerFlagsForGlobal(FlagsOS, &Function, *Mang);
629 TLOFCOFF.emitLinkerFlagsForGlobal(FlagsOS, &Function);
630630 for (const auto &Global : M.globals())
631 TLOFCOFF.emitLinkerFlagsForGlobal(FlagsOS, &Global, *Mang);
631 TLOFCOFF.emitLinkerFlagsForGlobal(FlagsOS, &Global);
632632 for (const auto &Alias : M.aliases())
633 TLOFCOFF.emitLinkerFlagsForGlobal(FlagsOS, &Alias, *Mang);
633 TLOFCOFF.emitLinkerFlagsForGlobal(FlagsOS, &Alias);
634634
635635 FlagsOS.flush();
636636
2323 using namespace dwarf;
2424
2525 const MCExpr *X86_64MachoTargetObjectFile::getTTypeGlobalReference(
26 const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
27 const TargetMachine &TM, MachineModuleInfo *MMI,
28 MCStreamer &Streamer) const {
26 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
27 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
2928
3029 // On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
3130 // is an indirect pc-relative reference.
3231 if ((Encoding & DW_EH_PE_indirect) && (Encoding & DW_EH_PE_pcrel)) {
33 const MCSymbol *Sym = TM.getSymbol(GV, Mang);
32 const MCSymbol *Sym = TM.getSymbol(GV, getMangler());
3433 const MCExpr *Res =
3534 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
3635 const MCExpr *Four = MCConstantExpr::create(4, getContext());
3837 }
3938
4039 return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
41 GV, Encoding, Mang, TM, MMI, Streamer);
40 GV, Encoding, TM, MMI, Streamer);
4241 }
4342
4443 MCSymbol *X86_64MachoTargetObjectFile::getCFIPersonalitySymbol(
45 const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
44 const GlobalValue *GV, const TargetMachine &TM,
4645 MachineModuleInfo *MMI) const {
47 return TM.getSymbol(GV, Mang);
46 return TM.getSymbol(GV, getMangler());
4847 }
4948
5049 const MCExpr *X86_64MachoTargetObjectFile::getIndirectSymViaGOTPCRel(
7372 }
7473
7574 const MCExpr *X86WindowsTargetObjectFile::lowerRelativeReference(
76 const GlobalValue *LHS, const GlobalValue *RHS, Mangler &Mang,
75 const GlobalValue *LHS, const GlobalValue *RHS,
7776 const TargetMachine &TM) const {
7877 // Our symbols should exist in address space zero, cowardly no-op if
7978 // otherwise.
9493 cast(RHS)->hasInitializer() || RHS->hasSection())
9594 return nullptr;
9695
97 return MCSymbolRefExpr::create(
98 TM.getSymbol(LHS, Mang), MCSymbolRefExpr::VK_COFF_IMGREL32, getContext());
96 return MCSymbolRefExpr::create(TM.getSymbol(LHS, getMangler()),
97 MCSymbolRefExpr::VK_COFF_IMGREL32,
98 getContext());
9999 }
100100
101101 static std::string APIntToHexString(const APInt &AI) {
1818 /// x86-64.
1919 class X86_64MachoTargetObjectFile : public TargetLoweringObjectFileMachO {
2020 public:
21 const MCExpr *
22 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
23 Mangler &Mang, const TargetMachine &TM,
24 MachineModuleInfo *MMI,
25 MCStreamer &Streamer) const override;
21 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
22 unsigned Encoding,
23 const TargetMachine &TM,
24 MachineModuleInfo *MMI,
25 MCStreamer &Streamer) const override;
2626
2727 // getCFIPersonalitySymbol - The symbol that gets passed to
2828 // .cfi_personality.
29 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
29 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
3030 const TargetMachine &TM,
3131 MachineModuleInfo *MMI) const override;
3232
5858 class X86WindowsTargetObjectFile : public TargetLoweringObjectFileCOFF {
5959 const MCExpr *
6060 lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS,
61 Mangler &Mang,
6261 const TargetMachine &TM) const override;
6362
6463 /// \brief Given a mergeable constant with the specified size and relocation
114114 return;
115115
116116 const DataLayout &DL = getDataLayout();
117 OutStreamer->SwitchSection(
118 getObjFileLowering().SectionForGlobal(GV, *Mang, TM));
117 OutStreamer->SwitchSection(getObjFileLowering().SectionForGlobal(GV, TM));
119118
120119 MCSymbol *GVSym = getSymbol(GV);
121120 const Constant *C = GV->getInitializer();
9494 return Flags;
9595 }
9696
97 MCSection *
98 XCoreTargetObjectFile::getExplicitSectionGlobal(const GlobalValue *GV,
99 SectionKind Kind, Mangler &Mang,
100 const TargetMachine &TM) const {
97 MCSection *XCoreTargetObjectFile::getExplicitSectionGlobal(
98 const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
10199 StringRef SectionName = GV->getSection();
102100 // Infer section flags from the section name if we can.
103101 bool IsCPRel = SectionName.startswith(".cp.");
107105 getXCoreSectionFlags(Kind, IsCPRel));
108106 }
109107
110 MCSection *
111 XCoreTargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV,
112 SectionKind Kind, Mangler &Mang,
113 const TargetMachine &TM) const {
108 MCSection *XCoreTargetObjectFile::SelectSectionForGlobal(
109 const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
114110
115111 bool UseCPRel = GV->isLocalLinkage(GV->getLinkage());
116112
2525 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
2626
2727 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
28 Mangler &Mang,
2928 const TargetMachine &TM) const override;
3029
3130 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
32 Mangler &Mang,
3331 const TargetMachine &TM) const override;
3432
3533 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,