Handle quoted names when constructing $stub's,

$non_lazy_ptr's and $lazy_ptr's.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51277 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dale Johannesen 2008-05-19 21:38:18 +00:00
parent 7be1c454c9
commit c215b3ef5d
6 changed files with 85 additions and 39 deletions

View File

@ -348,6 +348,11 @@ namespace llvm {
/// specified type. /// specified type.
void printDataDirective(const Type *type); void printDataDirective(const Type *type);
/// printSuffixedName - This prints a name with preceding
/// getPrivateGlobalPrefix and the specified suffix, handling quoted names
/// correctly.
void printSuffixedName(std::string &Name, const char* Suffix);
private: private:
void EmitLLVMUsedList(Constant *List); void EmitLLVMUsedList(Constant *List);
void EmitXXStructorList(Constant *List); void EmitXXStructorList(Constant *List);

View File

@ -1435,3 +1435,10 @@ void AsmPrinter::printDataDirective(const Type *type) {
} }
} }
void AsmPrinter::printSuffixedName(std::string &Name, const char* Suffix) {
if (Name[0]=='\"')
O << "\"" << TAI->getPrivateGlobalPrefix() <<
Name.substr(1, Name.length()-2) << Suffix << "\"";
else
O << TAI->getPrivateGlobalPrefix() << Name << Suffix;
}

View File

@ -127,10 +127,10 @@ namespace {
Name += ACPV->getSymbol(); Name += ACPV->getSymbol();
if (ACPV->isNonLazyPointer()) { if (ACPV->isNonLazyPointer()) {
GVNonLazyPtrs.insert(Name); GVNonLazyPtrs.insert(Name);
O << TAI->getPrivateGlobalPrefix() << Name << "$non_lazy_ptr"; printSuffixedName(Name, "$non_lazy_ptr");
} else if (ACPV->isStub()) { } else if (ACPV->isStub()) {
FnStubs.insert(Name); FnStubs.insert(Name);
O << TAI->getPrivateGlobalPrefix() << Name << "$stub"; printSuffixedName(Name, "$stub");
} else } else
O << Name; O << Name;
if (ACPV->hasModifier()) O << "(" << ACPV->getModifier() << ")"; if (ACPV->hasModifier()) O << "(" << ACPV->getModifier() << ")";
@ -295,7 +295,7 @@ void ARMAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
GV->hasLinkOnceLinkage()); GV->hasLinkOnceLinkage());
if (isExt && isCallOp && Subtarget->isTargetDarwin() && if (isExt && isCallOp && Subtarget->isTargetDarwin() &&
TM.getRelocationModel() != Reloc::Static) { TM.getRelocationModel() != Reloc::Static) {
O << TAI->getPrivateGlobalPrefix() << Name << "$stub"; printSuffixedName(Name, "$stub");
FnStubs.insert(Name); FnStubs.insert(Name);
} else } else
O << Name; O << Name;
@ -318,7 +318,7 @@ void ARMAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
Name += MO.getSymbolName(); Name += MO.getSymbolName();
if (isCallOp && Subtarget->isTargetDarwin() && if (isCallOp && Subtarget->isTargetDarwin() &&
TM.getRelocationModel() != Reloc::Static) { TM.getRelocationModel() != Reloc::Static) {
O << TAI->getPrivateGlobalPrefix() << Name << "$stub"; printSuffixedName(Name, "$stub");
FnStubs.insert(Name); FnStubs.insert(Name);
} else } else
O << Name; O << Name;
@ -1004,21 +1004,32 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
EmitAlignment(2); EmitAlignment(2);
O << "\t.code\t32\n"; O << "\t.code\t32\n";
O << "L" << *i << "$stub:\n"; std::string p = *i;
printSuffixedName(p, "$stub");
O << ":\n";
O << "\t.indirect_symbol " << *i << "\n"; O << "\t.indirect_symbol " << *i << "\n";
O << "\tldr ip, L" << *i << "$slp\n"; O << "\tldr ip, ";
printSuffixedName(p, "$slp");
O << "\n";
if (TM.getRelocationModel() == Reloc::PIC_) { if (TM.getRelocationModel() == Reloc::PIC_) {
O << "L" << *i << "$scv:\n"; printSuffixedName(p, "$scv");
O << ":\n";
O << "\tadd ip, pc, ip\n"; O << "\tadd ip, pc, ip\n";
} }
O << "\tldr pc, [ip, #0]\n"; O << "\tldr pc, [ip, #0]\n";
O << "L" << *i << "$slp:\n"; printSuffixedName(p, "$slp");
if (TM.getRelocationModel() == Reloc::PIC_) O << ":\n";
O << "\t.long\tL" << *i << "$lazy_ptr-(L" << *i << "$scv+8)\n"; O << "\t.long\t";
else printSuffixedName(p, "$lazy_ptr");
O << "\t.long\tL" << *i << "$lazy_ptr\n"; if (TM.getRelocationModel() == Reloc::PIC_) {
O << "-(";
printSuffixedName(p, "$scv");
O << "+8)\n";
} else
O << "\n";
SwitchToDataSection(".lazy_symbol_pointer", 0); SwitchToDataSection(".lazy_symbol_pointer", 0);
O << "L" << *i << "$lazy_ptr:\n"; printSuffixedName(p, "$lazy_ptr");
O << ":\n";
O << "\t.indirect_symbol " << *i << "\n"; O << "\t.indirect_symbol " << *i << "\n";
O << "\t.long\tdyld_stub_binding_helper\n"; O << "\t.long\tdyld_stub_binding_helper\n";
} }
@ -1029,7 +1040,9 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
SwitchToDataSection(".non_lazy_symbol_pointer", 0); SwitchToDataSection(".non_lazy_symbol_pointer", 0);
for (std::set<std::string>::iterator i = GVNonLazyPtrs.begin(), for (std::set<std::string>::iterator i = GVNonLazyPtrs.begin(),
e = GVNonLazyPtrs.end(); i != e; ++i) { e = GVNonLazyPtrs.end(); i != e; ++i) {
O << "L" << *i << "$non_lazy_ptr:\n"; std::string p = *i;
printSuffixedName(p, "$non_lazy_ptr");
O << ":\n";
O << "\t.indirect_symbol " << *i << "\n"; O << "\t.indirect_symbol " << *i << "\n";
O << "\t.long\t0\n"; O << "\t.long\t0\n";
} }

View File

@ -189,7 +189,7 @@ namespace {
// Dynamically-resolved functions need a stub for the function. // Dynamically-resolved functions need a stub for the function.
std::string Name = Mang->getValueName(GV); std::string Name = Mang->getValueName(GV);
FnStubs.insert(Name); FnStubs.insert(Name);
O << "L" << Name << "$stub"; printSuffixedName(Name, "$stub");
if (GV->hasExternalWeakLinkage()) if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV); ExtWeakSymbols.insert(GV);
return; return;
@ -198,7 +198,7 @@ namespace {
if (MO.getType() == MachineOperand::MO_ExternalSymbol) { if (MO.getType() == MachineOperand::MO_ExternalSymbol) {
std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName(); std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName();
FnStubs.insert(Name); FnStubs.insert(Name);
O << "L" << Name << "$stub"; printSuffixedName(Name, "$stub");
return; return;
} }
} }
@ -377,7 +377,7 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO) {
if (TM.getRelocationModel() != Reloc::Static) { if (TM.getRelocationModel() != Reloc::Static) {
std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName(); std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName();
GVStubs.insert(Name); GVStubs.insert(Name);
O << "L" << Name << "$non_lazy_ptr"; printSuffixedName(Name, "$non_lazy_ptr");
return; return;
} }
O << TAI->getGlobalPrefix() << MO.getSymbolName(); O << TAI->getGlobalPrefix() << MO.getSymbolName();
@ -392,7 +392,7 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO) {
if (((GV->isDeclaration() || GV->hasWeakLinkage() || if (((GV->isDeclaration() || GV->hasWeakLinkage() ||
GV->hasLinkOnceLinkage() || GV->hasCommonLinkage()))) { GV->hasLinkOnceLinkage() || GV->hasCommonLinkage()))) {
GVStubs.insert(Name); GVStubs.insert(Name);
O << "L" << Name << "$non_lazy_ptr"; printSuffixedName(Name, "$non_lazy_ptr");
if (GV->hasExternalWeakLinkage()) if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV); ExtWeakSymbols.insert(GV);
return; return;
@ -422,7 +422,7 @@ void PPCAsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) {
std::string Name = getGlobalLinkName(GV); std::string Name = getGlobalLinkName(GV);
if (TM.getRelocationModel() != Reloc::Static) { if (TM.getRelocationModel() != Reloc::Static) {
GVStubs.insert(Name); GVStubs.insert(Name);
O << "L" << Name << "$non_lazy_ptr"; printSuffixedName(Name, "$non_lazy_ptr");
return; return;
} }
O << Name; O << Name;
@ -1051,22 +1051,30 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
SwitchToTextSection("\t.section __TEXT,__picsymbolstub1,symbol_stubs," SwitchToTextSection("\t.section __TEXT,__picsymbolstub1,symbol_stubs,"
"pure_instructions,32"); "pure_instructions,32");
EmitAlignment(4); EmitAlignment(4);
O << "L" << *i << "$stub:\n"; std::string p = *i;
std::string L0p = (p[0]=='\"') ? "\"L0$" + p.substr(1) : "L0$" + p ;
printSuffixedName(p, "$stub");
O << ":\n";
O << "\t.indirect_symbol " << *i << "\n"; O << "\t.indirect_symbol " << *i << "\n";
O << "\tmflr r0\n"; O << "\tmflr r0\n";
O << "\tbcl 20,31,L0$" << *i << "\n"; O << "\tbcl 20,31," << L0p << "\n";
O << "L0$" << *i << ":\n"; O << L0p << ":\n";
O << "\tmflr r11\n"; O << "\tmflr r11\n";
O << "\taddis r11,r11,ha16(L" << *i << "$lazy_ptr-L0$" << *i << ")\n"; O << "\taddis r11,r11,ha16(";
printSuffixedName(p, "$lazy_ptr");
O << "-" << L0p << ")\n";
O << "\tmtlr r0\n"; O << "\tmtlr r0\n";
if (isPPC64) if (isPPC64)
O << "\tldu r12,lo16(L" << *i << "$lazy_ptr-L0$" << *i << ")(r11)\n"; O << "\tldu r12,lo16(";
else else
O << "\tlwzu r12,lo16(L" << *i << "$lazy_ptr-L0$" << *i << ")(r11)\n"; O << "\tlwzu r12,lo16(";
printSuffixedName(p, "$lazy_ptr");
O << "-" << L0p << ")(r11)\n";
O << "\tmtctr r12\n"; O << "\tmtctr r12\n";
O << "\tbctr\n"; O << "\tbctr\n";
SwitchToDataSection(".lazy_symbol_pointer"); SwitchToDataSection(".lazy_symbol_pointer");
O << "L" << *i << "$lazy_ptr:\n"; printSuffixedName(p, "$lazy_ptr");
O << ":\n";
O << "\t.indirect_symbol " << *i << "\n"; O << "\t.indirect_symbol " << *i << "\n";
if (isPPC64) if (isPPC64)
O << "\t.quad dyld_stub_binding_helper\n"; O << "\t.quad dyld_stub_binding_helper\n";
@ -1079,17 +1087,24 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
SwitchToTextSection("\t.section __TEXT,__symbol_stub1,symbol_stubs," SwitchToTextSection("\t.section __TEXT,__symbol_stub1,symbol_stubs,"
"pure_instructions,16"); "pure_instructions,16");
EmitAlignment(4); EmitAlignment(4);
O << "L" << *i << "$stub:\n"; std::string p = *i;
printSuffixedName(p, "$stub");
O << ":\n";
O << "\t.indirect_symbol " << *i << "\n"; O << "\t.indirect_symbol " << *i << "\n";
O << "\tlis r11,ha16(L" << *i << "$lazy_ptr)\n"; O << "\tlis r11,ha16(";
printSuffixedName(p, "$lazy_ptr");
O << ")\n";
if (isPPC64) if (isPPC64)
O << "\tldu r12,lo16(L" << *i << "$lazy_ptr)(r11)\n"; O << "\tldu r12,lo16(";
else else
O << "\tlwzu r12,lo16(L" << *i << "$lazy_ptr)(r11)\n"; O << "\tlwzu r12,lo16(";
printSuffixedName(p, "$lazy_ptr");
O << ")(r11)\n";
O << "\tmtctr r12\n"; O << "\tmtctr r12\n";
O << "\tbctr\n"; O << "\tbctr\n";
SwitchToDataSection(".lazy_symbol_pointer"); SwitchToDataSection(".lazy_symbol_pointer");
O << "L" << *i << "$lazy_ptr:\n"; printSuffixedName(p, "$lazy_ptr");
O << ":\n";
O << "\t.indirect_symbol " << *i << "\n"; O << "\t.indirect_symbol " << *i << "\n";
if (isPPC64) if (isPPC64)
O << "\t.quad dyld_stub_binding_helper\n"; O << "\t.quad dyld_stub_binding_helper\n";
@ -1115,7 +1130,9 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
SwitchToDataSection(".non_lazy_symbol_pointer"); SwitchToDataSection(".non_lazy_symbol_pointer");
for (std::set<std::string>::iterator I = GVStubs.begin(), for (std::set<std::string>::iterator I = GVStubs.begin(),
E = GVStubs.end(); I != E; ++I) { E = GVStubs.end(); I != E; ++I) {
O << "L" << *I << "$non_lazy_ptr:\n"; std::string p = *I;
printSuffixedName(p, "$non_lazy_ptr");
O << ":\n";
O << "\t.indirect_symbol " << *I << "\n"; O << "\t.indirect_symbol " << *I << "\n";
if (isPPC64) if (isPPC64)
O << "\t.quad\t0\n"; O << "\t.quad\t0\n";

View File

@ -314,10 +314,10 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
// Dynamically-resolved functions need a stub for the function. // Dynamically-resolved functions need a stub for the function.
if (isCallOp && isa<Function>(GV)) { if (isCallOp && isa<Function>(GV)) {
FnStubs.insert(Name); FnStubs.insert(Name);
O << TAI->getPrivateGlobalPrefix() << Name << "$stub"; printSuffixedName(Name, "$stub");
} else { } else {
GVStubs.insert(Name); GVStubs.insert(Name);
O << TAI->getPrivateGlobalPrefix() << Name << "$non_lazy_ptr"; printSuffixedName(Name, "$non_lazy_ptr");
} }
} else { } else {
if (GV->hasDLLImportLinkage()) if (GV->hasDLLImportLinkage())
@ -398,7 +398,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
Name += MO.getSymbolName(); Name += MO.getSymbolName();
if (isCallOp && printStub(TM, Subtarget)) { if (isCallOp && printStub(TM, Subtarget)) {
FnStubs.insert(Name); FnStubs.insert(Name);
O << TAI->getPrivateGlobalPrefix() << Name << "$stub"; printSuffixedName(Name, "$stub");
return; return;
} }
if (!isCallOp) if (!isCallOp)

View File

@ -385,8 +385,10 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
i != e; ++i, ++j) { i != e; ++i, ++j) {
SwitchToDataSection("\t.section __IMPORT,__jump_table,symbol_stubs," SwitchToDataSection("\t.section __IMPORT,__jump_table,symbol_stubs,"
"self_modifying_code+pure_instructions,5", 0); "self_modifying_code+pure_instructions,5", 0);
O << "L" << *i << "$stub:\n"; std::string p = *i;
O << "\t.indirect_symbol " << *i << "\n"; printSuffixedName(p, "$stub");
O << ":\n";
O << "\t.indirect_symbol " << p << "\n";
O << "\thlt ; hlt ; hlt ; hlt ; hlt\n"; O << "\thlt ; hlt ; hlt ; hlt ; hlt\n";
} }
@ -408,8 +410,10 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
"\t.section __IMPORT,__pointers,non_lazy_symbol_pointers"); "\t.section __IMPORT,__pointers,non_lazy_symbol_pointers");
for (std::set<std::string>::iterator i = GVStubs.begin(), e = GVStubs.end(); for (std::set<std::string>::iterator i = GVStubs.begin(), e = GVStubs.end();
i != e; ++i) { i != e; ++i) {
O << "L" << *i << "$non_lazy_ptr:\n"; std::string p = *i;
O << "\t.indirect_symbol " << *i << "\n"; printSuffixedName(p, "$non_lazy_ptr");
O << ":\n";
O << "\t.indirect_symbol " << p << "\n";
O << "\t.long\t0\n"; O << "\t.long\t0\n";
} }