llvm.org GIT mirror llvm / f61159b
convert macho stub emission to use SwitchToSection instead of textual sections. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78007 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
1 changed file(s) with 52 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
12681268
12691269 bool ARMAsmPrinter::doFinalization(Module &M) {
12701270 if (Subtarget->isTargetDarwin()) {
1271 SwitchToDataSection("");
1272
1271 // All darwin targets use mach-o.
1272 TargetLoweringObjectFileMachO &TLOFMacho =
1273 static_cast(getObjFileLowering());
1274
12731275 O << '\n';
1274 // Output stubs for dynamically-linked functions
1275 for (StringMap::iterator I = FnStubs.begin(), E = FnStubs.end();
1276 I != E; ++I) {
1277 const FnStubInfo &Info = I->second;
1276
1277 if (!FnStubs.empty()) {
1278 const MCSection *StubSection;
12781279 if (TM.getRelocationModel() == Reloc::PIC_)
1279 SwitchToTextSection(".section __TEXT,__picsymbolstub4,symbol_stubs,"
1280 "none,16", 0);
1280 StubSection = TLOFMacho.getMachOSection(".section __TEXT,__picsymbolstu"
1281 "b4,symbol_stubs,none,16", true,
1282 SectionKind::getText());
12811283 else
1282 SwitchToTextSection(".section __TEXT,__symbol_stub4,symbol_stubs,"
1283 "none,12", 0);
1284
1285 EmitAlignment(2);
1286 O << "\t.code\t32\n";
1287
1288 O << Info.Stub << ":\n";
1289 O << "\t.indirect_symbol " << I->getKeyData() << '\n';
1290 O << "\tldr ip, " << Info.SLP << '\n';
1291 if (TM.getRelocationModel() == Reloc::PIC_) {
1292 O << Info.SCV << ":\n";
1293 O << "\tadd ip, pc, ip\n";
1284 StubSection = TLOFMacho.getMachOSection(".section __TEXT,__symbol_stub4"
1285 ",symbol_stubs,none,12", true,
1286 SectionKind::getText());
1287
1288 const MCSection *LazySymbolPointerSection
1289 = TLOFMacho.getMachOSection(".lazy_symbol_pointer", true,
1290 SectionKind::getMetadata());
1291
1292 // Output stubs for dynamically-linked functions
1293 for (StringMap::iterator I = FnStubs.begin(),
1294 E = FnStubs.end(); I != E; ++I) {
1295 const FnStubInfo &Info = I->second;
1296
1297 SwitchToSection(StubSection);
1298 EmitAlignment(2);
1299 O << "\t.code\t32\n";
1300
1301 O << Info.Stub << ":\n";
1302 O << "\t.indirect_symbol " << I->getKeyData() << '\n';
1303 O << "\tldr ip, " << Info.SLP << '\n';
1304 if (TM.getRelocationModel() == Reloc::PIC_) {
1305 O << Info.SCV << ":\n";
1306 O << "\tadd ip, pc, ip\n";
1307 }
1308 O << "\tldr pc, [ip, #0]\n";
1309 O << Info.SLP << ":\n";
1310 O << "\t.long\t" << Info.LazyPtr;
1311 if (TM.getRelocationModel() == Reloc::PIC_)
1312 O << "-(" << Info.SCV << "+8)";
1313 O << '\n';
1314
1315 SwitchToSection(LazySymbolPointerSection);
1316 O << Info.LazyPtr << ":\n";
1317 O << "\t.indirect_symbol " << I->getKeyData() << "\n";
1318 O << "\t.long\tdyld_stub_binding_helper\n";
12941319 }
1295 O << "\tldr pc, [ip, #0]\n";
1296 O << Info.SLP << ":\n";
1297 O << "\t.long\t" << Info.LazyPtr;
1298 if (TM.getRelocationModel() == Reloc::PIC_)
1299 O << "-(" << Info.SCV << "+8)";
13001320 O << '\n';
1301
1302 SwitchToDataSection(".lazy_symbol_pointer", 0);
1303 O << Info.LazyPtr << ":\n";
1304 O << "\t.indirect_symbol " << I->getKeyData() << "\n";
1305 O << "\t.long\tdyld_stub_binding_helper\n";
1306 }
1307 O << '\n';
1308
1321 }
1322
13091323 // Output non-lazy-pointers for external and common global variables.
13101324 if (!GVNonLazyPtrs.empty()) {
1311 SwitchToDataSection("\t.non_lazy_symbol_pointer", 0);
1312 for (StringMap::iterator I = GVNonLazyPtrs.begin(),
1313 E = GVNonLazyPtrs.end(); I != E; ++I) {
1325 SwitchToSection(TLOFMacho.getMachOSection(".non_lazy_symbol_pointer",
1326 true,
1327 SectionKind::getMetadata()));
1328 for (StringMap::iterator I = GVNonLazyPtrs.begin(),
1329 E = GVNonLazyPtrs.end(); I != E; ++I) {
13141330 O << I->second << ":\n";
13151331 O << "\t.indirect_symbol " << I->getKeyData() << "\n";
13161332 O << "\t.long\t0\n";