llvm.org GIT mirror llvm / 0b4bad5
properly use MCSymbol to print the strings aquired from getNameWithPrefix. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93332 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
1 changed file(s) with 66 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
3131 #include "llvm/CodeGen/MachineInstr.h"
3232 #include "llvm/CodeGen/MachineInstrBuilder.h"
3333 #include "llvm/MC/MCAsmInfo.h"
34 #include "llvm/MC/MCContext.h"
3435 #include "llvm/MC/MCSectionMachO.h"
3536 #include "llvm/MC/MCStreamer.h"
3637 #include "llvm/MC/MCSymbol.h"
5758 class PPCAsmPrinter : public AsmPrinter {
5859 protected:
5960 struct FnStubInfo {
60 std::string Stub, LazyPtr, AnonSymbol;
61 std::string StubName, LazyPtrName, AnonSymbolName;
62 MCSymbol *StubSym, *LazyPtrSym, *AnonSymbolSym;
6163
62 FnStubInfo() {}
64 FnStubInfo() {
65 StubSym = LazyPtrSym = AnonSymbolSym = 0;
66 }
6367
6468 void Init(const GlobalValue *GV, Mangler *Mang) {
6569 // Already initialized.
66 if (!Stub.empty()) return;
67 Stub = Mang->getMangledName(GV, "$stub", true);
68 LazyPtr = Mang->getMangledName(GV, "$lazy_ptr", true);
69 AnonSymbol = Mang->getMangledName(GV, "$stub$tmp", true);
70 }
71
72 void Init(StringRef GVName, Mangler *Mang) {
70 if (!StubName.empty()) return;
71 StubName = Mang->getMangledName(GV, "$stub", true);
72 LazyPtrName = Mang->getMangledName(GV, "$lazy_ptr", true);
73 AnonSymbolName = Mang->getMangledName(GV, "$stub$tmp", true);
74 }
75
76 void Init(StringRef GVName, Mangler *Mang, MCContext &Ctx) {
7377 assert(!GVName.empty());
74 if (!Stub.empty()) return; // Already initialized.
78 if (StubSym != 0) return; // Already initialized.
7579 // Get the names for the external symbol name.
7680 SmallString<128> TmpStr;
7781 Mang->getNameWithPrefix(TmpStr, GVName + "$stub", Mangler::Private);
78 Stub = TmpStr.str();
82 StubSym = Ctx.GetOrCreateSymbol(TmpStr.str());
7983 TmpStr.clear();
8084
8185 Mang->getNameWithPrefix(TmpStr, GVName + "$lazy_ptr", Mangler::Private);
82 LazyPtr = TmpStr.str();
86 LazyPtrSym = Ctx.GetOrCreateSymbol(TmpStr.str());
8387 TmpStr.clear();
8488
8589 Mang->getNameWithPrefix(TmpStr, GVName + "$stub$tmp", Mangler::Private);
86 AnonSymbol = TmpStr.str();
90 AnonSymbolSym = Ctx.GetOrCreateSymbol(TmpStr.str());
91 }
92
93 void printStub(raw_ostream &OS, const MCAsmInfo *MAI) const {
94 if (StubSym)
95 StubSym->print(OS, MAI);
96 else
97 OS << StubName;
98 }
99 void printLazyPtr(raw_ostream &OS, const MCAsmInfo *MAI) const {
100 if (LazyPtrSym)
101 LazyPtrSym->print(OS, MAI);
102 else
103 OS << LazyPtrName;
104 }
105 void printAnonSymbol(raw_ostream &OS, const MCAsmInfo *MAI) const {
106 if (AnonSymbolSym)
107 AnonSymbolSym->print(OS, MAI);
108 else
109 OS << AnonSymbolName;
87110 }
88111 };
89112
231254 // Dynamically-resolved functions need a stub for the function.
232255 FnStubInfo &FnInfo = FnStubs[Mang->getMangledName(GV)];
233256 FnInfo.Init(GV, Mang);
234 O << FnInfo.Stub;
257 FnInfo.printStub(O, MAI);
235258 return;
236259 }
237260 }
239262 SmallString<128> MangledName;
240263 Mang->getNameWithPrefix(MangledName, MO.getSymbolName());
241264 FnStubInfo &FnInfo = FnStubs[MangledName.str()];
242 FnInfo.Init(MO.getSymbolName(), Mang);
243 O << FnInfo.Stub;
265 FnInfo.Init(MO.getSymbolName(), Mang, OutContext);
266 FnInfo.printStub(O, MAI);
244267 return;
245268 }
246269 }
10451068 MCSectionMachO::S_SYMBOL_STUBS |
10461069 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
10471070 32, SectionKind::getText());
1048 for (StringMap::iterator I = FnStubs.begin(), E = FnStubs.end();
1071 for (StringMap::iterator I = FnStubs.begin(), E = FnStubs.end();
10491072 I != E; ++I) {
10501073 OutStreamer.SwitchSection(StubSection);
10511074 EmitAlignment(4);
10521075 const FnStubInfo &Info = I->second;
1053 O << Info.Stub << ":\n";
1076 Info.printStub(O, MAI);
1077 O << ":\n";
10541078 O << "\t.indirect_symbol " << I->getKeyData() << '\n';
10551079 O << "\tmflr r0\n";
1056 O << "\tbcl 20,31," << Info.AnonSymbol << '\n';
1057 O << Info.AnonSymbol << ":\n";
1080 O << "\tbcl 20,31,";
1081 Info.printAnonSymbol(O, MAI);
1082 O << '\n';
1083 Info.printAnonSymbol(O, MAI);
1084 O << ":\n";
10581085 O << "\tmflr r11\n";
1059 O << "\taddis r11,r11,ha16(" << Info.LazyPtr << "-" << Info.AnonSymbol;
1086 O << "\taddis r11,r11,ha16(";
1087 Info.printLazyPtr(O, MAI);
1088 O << '-';
1089 Info.printAnonSymbol(O, MAI);
10601090 O << ")\n";
10611091 O << "\tmtlr r0\n";
10621092 O << (isPPC64 ? "\tldu" : "\tlwzu") << " r12,lo16(";
1063 O << Info.LazyPtr << "-" << Info.AnonSymbol << ")(r11)\n";
1093 Info.printLazyPtr(O, MAI);
1094 O << '-';
1095 Info.printAnonSymbol(O, MAI);
1096 O << ")(r11)\n";
10641097 O << "\tmtctr r12\n";
10651098 O << "\tbctr\n";
10661099
10671100 OutStreamer.SwitchSection(LSPSection);
1068 O << Info.LazyPtr << ":\n";
1101 Info.printLazyPtr(O, MAI);
1102 O << ":\n";
10691103 O << "\t.indirect_symbol " << I->getKeyData() << '\n';
10701104 O << (isPPC64 ? "\t.quad" : "\t.long") << " dyld_stub_binding_helper\n";
10711105 }
10811115 OutStreamer.SwitchSection(StubSection);
10821116 EmitAlignment(4);
10831117 const FnStubInfo &Info = I->second;
1084 O << Info.Stub << ":\n";
1118 Info.printStub(O, MAI);
1119 O << ":\n";
10851120 O << "\t.indirect_symbol " << I->getKeyData() << '\n';
1086 O << "\tlis r11,ha16(" << Info.LazyPtr << ")\n";
1121 O << "\tlis r11,ha16(";
1122 Info.printLazyPtr(O, MAI);
1123 O << ")\n";
10871124 O << (isPPC64 ? "\tldu" : "\tlwzu") << " r12,lo16(";
1088 O << Info.LazyPtr << ")(r11)\n";
1125 Info.printLazyPtr(O, MAI);
1126 O << ")(r11)\n";
10891127 O << "\tmtctr r12\n";
10901128 O << "\tbctr\n";
10911129 OutStreamer.SwitchSection(LSPSection);
1092 O << Info.LazyPtr << ":\n";
1130 Info.printLazyPtr(O, MAI);
1131 O << ":\n";
10931132 O << "\t.indirect_symbol " << I->getKeyData() << '\n';
10941133 O << (isPPC64 ? "\t.quad" : "\t.long") << " dyld_stub_binding_helper\n";
10951134 }