llvm.org GIT mirror llvm / dc62ea0
move FnStubs/GVSTubs/HiddenGVStub handling out of the X86 asmprinter and use MachineModuleInfoMachO instead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82022 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
7 changed file(s) with 54 addition(s) and 51 deletion(s). Raw diff Collapse all Expand all
7575 ///
7676 MachineLoopInfo *LI;
7777
78 protected:
78 public:
7979 /// MMI - If available, this is a pointer to the current MachineModuleInfo.
8080 MachineModuleInfo *MMI;
8181
82 protected:
8283 /// DW - If available, this is a pointer to the current dwarf writer.
8384 DwarfWriter *DW;
8485
162162 /// backends that would like to do so.
163163 ///
164164 template
165 Ty *getObjFileInfo() {
165 Ty &getObjFileInfo() {
166166 if (ObjFileMMI == 0)
167167 ObjFileMMI = new Ty(*this);
168168
169169 assert((void*)dynamic_cast(ObjFileMMI) == (void*)ObjFileMMI &&
170170 "Invalid concrete type or multiple inheritence for getInfo");
171 return static_cast(ObjFileMMI);
171 return *static_cast(ObjFileMMI);
172172 }
173173
174174 template
175 const Ty *getObjFileInfo() const {
175 const Ty &getObjFileInfo() const {
176176 return const_cast(this)->getObjFileInfo();
177177 }
178178
3737
3838 virtual void Anchor(); // Out of line virtual method.
3939 public:
40 MachineModuleInfoMachO(const MachineModuleInfo &) {}
4041
4142 const MCSymbol *&getFnStubEntry(const MCSymbol *Sym) {
4243 assert(Sym && "Key cannot be null");
4344 return FnStubs[Sym];
4445 }
4546
46 const MCSymbol *&getGVStubsEntry(const MCSymbol *Sym) {
47 const MCSymbol *&getGVStubEntry(const MCSymbol *Sym) {
4748 assert(Sym && "Key cannot be null");
4849 return GVStubs[Sym];
4950 }
5051
51 const MCSymbol *&getHiddenGVStubsEntry(const MCSymbol *Sym) {
52 const MCSymbol *&getHiddenGVStubEntry(const MCSymbol *Sym) {
5253 assert(Sym && "Key cannot be null");
5354 return HiddenGVStubs[Sym];
5455 }
3030 #include "llvm/MC/MCStreamer.h"
3131 #include "llvm/MC/MCSymbol.h"
3232 #include "llvm/CodeGen/MachineJumpTableInfo.h"
33 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
3334 #include "llvm/Support/ErrorHandling.h"
3435 #include "llvm/Support/FormattedStream.h"
3536 #include "llvm/Support/Mangler.h"
319320 Mang->getNameWithPrefix(NameStr, GV, true);
320321 NameStr += "$non_lazy_ptr";
321322 MCSymbol *Sym = OutContext.GetOrCreateSymbol(NameStr.str());
322 MCSymbol *&StubSym = GVStubs[Sym];
323
324 const MCSymbol *&StubSym =
325 MMI->getObjFileInfo().getGVStubEntry(Sym);
323326 if (StubSym == 0) {
324327 NameStr.clear();
325328 Mang->getNameWithPrefix(NameStr, GV, false);
330333 Mang->getNameWithPrefix(NameStr, GV, true);
331334 NameStr += "$non_lazy_ptr";
332335 MCSymbol *Sym = OutContext.GetOrCreateSymbol(NameStr.str());
333 MCSymbol *&StubSym = HiddenGVStubs[Sym];
336 const MCSymbol *&StubSym =
337 MMI->getObjFileInfo().getHiddenGVStubEntry(Sym);
334338 if (StubSym == 0) {
335339 NameStr.clear();
336340 Mang->getNameWithPrefix(NameStr, GV, false);
341345 Mang->getNameWithPrefix(NameStr, GV, true);
342346 NameStr += "$stub";
343347 MCSymbol *Sym = OutContext.GetOrCreateSymbol(NameStr.str());
344 MCSymbol *&StubSym = FnStubs[Sym];
348 const MCSymbol *&StubSym =
349 MMI->getObjFileInfo().getFnStubEntry(Sym);
345350 if (StubSym == 0) {
346351 NameStr.clear();
347352 Mang->getNameWithPrefix(NameStr, GV, false);
363368 std::string Name = Mang->makeNameProper(MO.getSymbolName());
364369 if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
365370 Name += "$stub";
366 MCSymbol *&StubSym = FnStubs[OutContext.GetOrCreateSymbol(Name)];
371 MCSymbol *Sym = OutContext.GetOrCreateSymbol(Name);
372 const MCSymbol *&StubSym =
373 MMI->getObjFileInfo().getFnStubEntry(Sym);
367374 if (StubSym == 0) {
368375 Name.erase(Name.end()-5, Name.end());
369376 StubSym = OutContext.GetOrCreateSymbol(Name);
871878 O << "\t.size\t" << name << ", " << Size << '\n';
872879 }
873880
874 static int SortSymbolPair(const void *LHS, const void *RHS) {
875 MCSymbol *LHSS = ((const std::pair*)LHS)->first;
876 MCSymbol *RHSS = ((const std::pair*)RHS)->first;
877 return LHSS->getName().compare(RHSS->getName());
878 }
879
880 /// GetSortedStubs - Return the entries from a DenseMap in a deterministic
881 /// sorted orer.
882 static std::vector >
883 GetSortedStubs(const DenseMap &Map) {
884 assert(!Map.empty());
885 std::vector > List(Map.begin(), Map.end());
886 qsort(&List[0], List.size(), sizeof(List[0]), SortSymbolPair);
887 return List;
888 }
889
890881 bool X86ATTAsmPrinter::doFinalization(Module &M) {
891882 if (Subtarget->isTargetDarwin()) {
892883 // All darwin targets use mach-o.
893884 TargetLoweringObjectFileMachO &TLOFMacho =
894885 static_cast(getObjFileLowering());
886
887 MachineModuleInfoMachO &MMIMacho =
888 MMI->getObjFileInfo();
895889
896890 // Add the (possibly multiple) personalities to the set of global value
897891 // stubs. Only referenced functions get into the Personalities list.
906900 Name += "$non_lazy_ptr";
907901 MCSymbol *NLPName = OutContext.GetOrCreateSymbol(Name.str());
908902
909 MCSymbol *&StubName = GVStubs[NLPName];
910 if (StubName != 0) continue;
911
912
903 const MCSymbol *&StubName = MMIMacho.getGVStubEntry(NLPName);
913904 Name.clear();
914905 Mang->getNameWithPrefix(Name, Personalities[i], false);
915906 StubName = OutContext.GetOrCreateSymbol(Name.str());
916907 }
917908 }
918909
919 // Output stubs for dynamically-linked functions
920 if (!FnStubs.empty()) {
910 // Output stubs for dynamically-linked functions.
911 MachineModuleInfoMachO::SymbolListTy Stubs;
912
913 Stubs = MMIMacho.GetFnStubList();
914 if (!Stubs.empty()) {
921915 const MCSection *TheSection =
922916 TLOFMacho.getMachOSection("__IMPORT", "__jump_table",
923917 MCSectionMachO::S_SYMBOL_STUBS |
926920 5, SectionKind::getMetadata());
927921 OutStreamer.SwitchSection(TheSection);
928922
929 std::vector > Stubs
930 = GetSortedStubs(FnStubs);
931923 for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
932924 Stubs[i].first->print(O, MAI);
933925 O << ":\n" << "\t.indirect_symbol ";
936928 O << "\n\thlt ; hlt ; hlt ; hlt ; hlt\n";
937929 }
938930 O << '\n';
931
932 Stubs.clear();
939933 }
940934
941935 // Output stubs for external and common global variables.
942 if (!GVStubs.empty()) {
936 Stubs = MMIMacho.GetGVStubList();
937 if (!Stubs.empty()) {
943938 const MCSection *TheSection =
944939 TLOFMacho.getMachOSection("__IMPORT", "__pointers",
945940 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
946941 SectionKind::getMetadata());
947942 OutStreamer.SwitchSection(TheSection);
948943
949 std::vector > Stubs
950 = GetSortedStubs(GVStubs);
951944 for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
952945 Stubs[i].first->print(O, MAI);
953946 O << ":\n\t.indirect_symbol ";
954947 Stubs[i].second->print(O, MAI);
955948 O << "\n\t.long\t0\n";
956949 }
957 }
958
959 if (!HiddenGVStubs.empty()) {
950 Stubs.clear();
951 }
952
953 Stubs = MMIMacho.GetHiddenGVStubList();
954 if (!Stubs.empty()) {
960955 OutStreamer.SwitchSection(getObjFileLowering().getDataSection());
961956 EmitAlignment(2);
962957
963 std::vector > Stubs
964 = GetSortedStubs(HiddenGVStubs);
965958 for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
966959 Stubs[i].first->print(O, MAI);
967960 O << ":\n" << MAI->getData32bitsDirective();
968961 Stubs[i].second->print(O, MAI);
969962 O << '\n';
970963 }
964 Stubs.clear();
971965 }
972966
973967 // Funny Darwin hack: This flag tells the linker that no global symbols
151151
152152 void emitFunctionHeader(const MachineFunction &MF);
153153
154 // Necessary for Darwin to print out the appropriate types of linker stubs.
155 DenseMap FnStubs; // Darwin $stub stubs.
156 DenseMap GVStubs; // Darwin $non_lazy_ptr stub.
157 DenseMap HiddenGVStubs; // Darwin $non_lazy_ptr stub.
158
159154 // Necessary for dllexport support
160155 StringSet<> CygMingStubs, DLLExportedFns, DLLExportedGVs;
161156
1414 #include "X86MCInstLower.h"
1515 #include "X86ATTAsmPrinter.h"
1616 #include "X86MCAsmInfo.h"
17 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
1718 #include "llvm/MC/MCContext.h"
1819 #include "llvm/MC/MCExpr.h"
1920 #include "llvm/MC/MCInst.h"
2829 return AsmPrinter.getSubtarget();
2930 }
3031
32 MachineModuleInfoMachO &X86MCInstLower::getMachOMMI() const {
33 assert(getSubtarget().isTargetDarwin() &&"Can only get MachO info on darwin");
34 return AsmPrinter.MMI->getObjFileInfo();
35 }
36
3137
3238 MCSymbol *X86MCInstLower::GetPICBaseSymbol() const {
3339 SmallString<60> Name;
7177 case X86II::MO_DARWIN_NONLAZY_PIC_BASE: {
7278 Name += "$non_lazy_ptr";
7379 MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
74 MCSymbol *&StubSym = AsmPrinter.GVStubs[Sym];
80
81 const MCSymbol *&StubSym = getMachOMMI().getGVStubEntry(Sym);
7582 if (StubSym == 0) {
7683 Name.clear();
7784 Mang->getNameWithPrefix(Name, GV, false);
8289 case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: {
8390 Name += "$non_lazy_ptr";
8491 MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
85 MCSymbol *&StubSym = AsmPrinter.HiddenGVStubs[Sym];
92 const MCSymbol *&StubSym = getMachOMMI().getHiddenGVStubEntry(Sym);
8693 if (StubSym == 0) {
8794 Name.clear();
8895 Mang->getNameWithPrefix(Name, GV, false);
93100 case X86II::MO_DARWIN_STUB: {
94101 Name += "$stub";
95102 MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
96 MCSymbol *&StubSym = AsmPrinter.FnStubs[Sym];
103 const MCSymbol *&StubSym = getMachOMMI().getFnStubEntry(Sym);
97104 if (StubSym == 0) {
98105 Name.clear();
99106 Mang->getNameWithPrefix(Name, GV, false);
137144 case X86II::MO_DARWIN_STUB: {
138145 Name += "$stub";
139146 MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
140 MCSymbol *&StubSym = AsmPrinter.FnStubs[Sym];
147 const MCSymbol *&StubSym = getMachOMMI().getFnStubEntry(Sym);
148
141149 if (StubSym == 0) {
142150 Name.erase(Name.end()-5, Name.end());
143151 StubSym = Ctx.GetOrCreateSymbol(Name.str());
1717 class MCOperand;
1818 class MCSymbol;
1919 class MachineInstr;
20 class MachineModuleInfoMachO;
2021 class MachineOperand;
2122 class Mangler;
2223 class X86ATTAsmPrinter;
4243 MCSymbol *GetJumpTableSymbol(const MachineOperand &MO) const;
4344 MCSymbol *GetConstantPoolIndexSymbol(const MachineOperand &MO) const;
4445 MCOperand LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const;
46
47 private:
48 MachineModuleInfoMachO &getMachOMMI() const;
4549 };
4650
4751 }