Fixed mingw\cygwin linkonce linkage once again.

Added workaround for linker bug with linkonce sections.
Changed sections prefix to allow linker merge them
(PE loader doesn't like too much long-named sections :) )
All of this unbreaks libstdc++ on mingw32 allowing (small)
programs to be compiled, linked and run.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31033 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Anton Korobeynikov 2006-10-18 09:12:29 +00:00
parent a6fc5016ee
commit b1c8802407
2 changed files with 10 additions and 28 deletions

View File

@ -40,7 +40,7 @@ std::string X86ATTAsmPrinter::getSectionForFunction(const Function &F) const {
if (Subtarget->isTargetDarwin()) {
return ".section __TEXT,__textcoal_nt,coalesced,pure_instructions";
} else if (Subtarget->isTargetCygwin()) {
return "\t.section\t.llvm.linkonce.t." + CurrentFnName + ",\"ax\"\n";
return "\t.section\t.text$linkonce." + CurrentFnName + ",\"ax\"\n";
} else {
return "\t.section\t.llvm.linkonce.t." + CurrentFnName +
",\"ax\",@progbits\n";
@ -90,6 +90,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
O << "\t.globl\t" << CurrentFnName << "\n";
break;
case Function::LinkOnceLinkage:
case Function::WeakLinkage:
if (Subtarget->isTargetDarwin()) {
O << "\t.globl\t" << CurrentFnName << "\n";
O << "\t.weak_definition\t" << CurrentFnName << "\n";
@ -102,20 +103,13 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
O << "\t.weak " << CurrentFnName << "\n";
}
break;
case Function::WeakLinkage:
if (Subtarget->isTargetDarwin()) {
O << "\t.globl\t" << CurrentFnName << "\n";
O << "\t.weak_definition\t" << CurrentFnName << "\n";
} else if (Subtarget->isTargetCygwin()) {
EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
O << "\t.weak " << CurrentFnName << "\n";
} else {
EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
O << "\t.weak " << CurrentFnName << "\n";
}
break;
}
O << CurrentFnName << ":\n";
// Add some workaround for linkonce linkage on Cygwin\MinGW
if (Subtarget->isTargetCygwin() &&
(F->getLinkage() == Function::LinkOnceLinkage ||
F->getLinkage() == Function::WeakLinkage))
O << "_llvm$workaround$fake$stub_" << CurrentFnName << ":\n";
if (Subtarget->isTargetDarwin()) {
// Emit pre-function debug information.

View File

@ -174,27 +174,15 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
} else {
switch (I->getLinkage()) {
case GlobalValue::LinkOnceLinkage:
if (Subtarget->isTargetDarwin()) {
O << "\t.globl " << name << "\n"
<< "\t.weak_definition " << name << "\n";
SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
} else if (Subtarget->isTargetCygwin()) {
O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\"\n"
<< "\t.globl " << name << "\n"
<< "\t.linkonce same_size\n";
} else {
O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n"
<< "\t.weak " << name << "\n";
}
break;
case GlobalValue::WeakLinkage:
if (Subtarget->isTargetDarwin()) {
O << "\t.globl " << name << "\n"
<< "\t.weak_definition " << name << "\n";
SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
} else if (Subtarget->isTargetCygwin()) {
O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\"\n"
<< "\t.weak " << name << "\n";
O << "\t.section\t.data$linkonce." << name << ",\"aw\"\n"
<< "\t.globl " << name << "\n"
<< "\t.linkonce same_size\n";
} else {
O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n"
<< "\t.weak " << name << "\n";