llvm.org GIT mirror llvm / 228252f
Make a new X8632_MachoTargetObjectFile TLOF implementation whose getSymbolForDwarfGlobalReference is smart enough to know that it needs to register the stub it references with MachineModuleInfoMachO, so that it gets emitted at the end of the file. Move stub emission from X86ATTAsmPrinter::doFinalization to the new X86ATTAsmPrinter::EmitEndOfAsmFile asmprinter hook. The important thing here is that EmitEndOfAsmFile is called *after* the ehframes are emitted, so we get all the stubs. This allows us to remove a gross hack from the asmprinter where it would "just know" that it needed to output stubs for personality functions. Now this is all driven from a consistent interface. The testcase change is just reordering the expected output now that the stubs come out after the ehframe instead of before. This also unblocks other changes that Bill wants to make. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82269 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
6 changed file(s) with 53 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
878878 O << "\t.size\t" << name << ", " << Size << '\n';
879879 }
880880
881 bool X86ATTAsmPrinter::doFinalization(Module &M) {
881 void X86ATTAsmPrinter::EmitEndOfAsmFile(Module &M) {
882882 if (Subtarget->isTargetDarwin()) {
883883 // All darwin targets use mach-o.
884884 TargetLoweringObjectFileMachO &TLOFMacho =
887887 MachineModuleInfoMachO &MMIMacho =
888888 MMI->getObjFileInfo();
889889
890 // Add the (possibly multiple) personalities to the set of global value
891 // stubs. Only referenced functions get into the Personalities list.
892 if (!Subtarget->is64Bit()) {
893 const std::vector &Personalities = MMI->getPersonalities();
894 for (unsigned i = 0, e = Personalities.size(); i != e; ++i) {
895 if (Personalities[i] == 0)
896 continue;
897
898 SmallString<128> Name;
899 Mang->getNameWithPrefix(Name, Personalities[i], true /*private label*/);
900 Name += "$non_lazy_ptr";
901 MCSymbol *NLPName = OutContext.GetOrCreateSymbol(Name.str());
902
903 const MCSymbol *&StubName = MMIMacho.getGVStubEntry(NLPName);
904 Name.clear();
905 Mang->getNameWithPrefix(Name, Personalities[i], false);
906 StubName = OutContext.GetOrCreateSymbol(Name.str());
907 }
908 }
909
910890 // Output stubs for dynamically-linked functions.
911891 MachineModuleInfoMachO::SymbolListTy Stubs;
912892
1009989 O << "\t.ascii \" -export:" << i->getKeyData() << "\"\n";
1010990 }
1011991 }
1012
1013 // Do common shutdown.
1014 return AsmPrinter::doFinalization(M);
1015 }
1016
992 }
993
5757 AsmPrinter::getAnalysisUsage(AU);
5858 }
5959
60 bool doFinalization(Module &M);
61
60
61 virtual void EmitEndOfAsmFile(Module &M);
62
6263 void printInstructionThroughMCStreamer(const MachineInstr *MI);
6364
6465
6464 case X86Subtarget::isDarwin:
6565 if (TM.getSubtarget().is64Bit())
6666 return new X8664_MachoTargetObjectFile();
67 return new TargetLoweringObjectFileMachO();
67 return new X8632_MachoTargetObjectFile();
6868 case X86Subtarget::isELF:
6969 return new TargetLoweringObjectFileELF();
7070 case X86Subtarget::isMingw:
99 #include "X86TargetObjectFile.h"
1010 #include "llvm/ADT/SmallString.h"
1111 #include "llvm/Support/Mangler.h"
12 #include "llvm/MC/MCContext.h"
1213 #include "llvm/MC/MCExpr.h"
14 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
1315 using namespace llvm;
16
17 const MCExpr *X8632_MachoTargetObjectFile::
18 getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
19 MachineModuleInfo *MMI,
20 bool &IsIndirect, bool &IsPCRel) const {
21 // The mach-o version of this method defaults to returning a stub reference.
22 IsIndirect = true;
23 IsPCRel = false;
24
25
26 MachineModuleInfoMachO &MachOMMI =
27 MMI->getObjFileInfo();
28
29 SmallString<128> Name;
30 Mang->getNameWithPrefix(Name, GV, true);
31 Name += "$non_lazy_ptr";
32
33 // Add information about the stub reference to MachOMMI so that the stub gets
34 // emitted by the asmprinter.
35 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name.str());
36 const MCSymbol *&StubSym = MachOMMI.getGVStubEntry(Sym);
37 if (StubSym == 0) {
38 Name.clear();
39 Mang->getNameWithPrefix(Name, GV, false);
40 StubSym = getContext().GetOrCreateSymbol(Name.str());
41 }
42
43 return MCSymbolRefExpr::Create(Sym, getContext());
44 }
1445
1546 const MCExpr *X8664_MachoTargetObjectFile::
1647 getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
1313
1414 namespace llvm {
1515
16 /// X8632_MachoTargetObjectFile - This TLOF implementation is used for
17 /// Darwin/x86-32.
18 class X8632_MachoTargetObjectFile : public TargetLoweringObjectFileMachO {
19 public:
20
21 virtual const MCExpr *
22 getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
23 MachineModuleInfo *MMI,
24 bool &IsIndirect, bool &IsPCRel) const;
25 };
26
1627 /// X8664_MachoTargetObjectFile - This TLOF implementation is used for
1728 /// Darwin/x86-64.
1829 class X8664_MachoTargetObjectFile : public TargetLoweringObjectFileMachO {
4040 ; X64: Leh_frame_common_begin:
4141 ; X64: .long ___gxx_personality_v0@GOTPCREL+4
4242
43 ; X32: Leh_frame_common_begin:
44 ; X32: .long L___gxx_personality_v0$non_lazy_ptr-
45 ; ....
46
4347 ; X32: .section __IMPORT,__pointers,non_lazy_symbol_pointers
4448 ; X32: L___gxx_personality_v0$non_lazy_ptr:
4549 ; X32: .indirect_symbol ___gxx_personality_v0
46 ; ....
47 ; X32: Leh_frame_common_begin:
48 ; X32: .long L___gxx_personality_v0$non_lazy_ptr-