diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h index 59d5b153ea7..2f54d6de742 100644 --- a/include/llvm/CodeGen/AsmPrinter.h +++ b/include/llvm/CodeGen/AsmPrinter.h @@ -18,6 +18,7 @@ #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/Support/DataTypes.h" +#include namespace llvm { class Constant; @@ -39,6 +40,10 @@ namespace llvm { /// unsigned FunctionNumber; + protected: + // Necessary for external weak linkage support + std::set ExtWeakSymbols; + public: /// Output stream on which we're printing assembly code. /// diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp index 8757d303ec8..833ed28f085 100644 --- a/lib/CodeGen/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter.cpp @@ -106,6 +106,18 @@ bool AsmPrinter::doInitialization(Module &M) { } bool AsmPrinter::doFinalization(Module &M) { + if (TAI->getWeakRefDirective()) { + if (ExtWeakSymbols.begin() != ExtWeakSymbols.end()) + SwitchToDataSection(""); + + for (std::set::iterator i = ExtWeakSymbols.begin(), + e = ExtWeakSymbols.end(); i != e; ++i) { + const GlobalValue *GV = *i; + std::string Name = Mang->getValueName(GV); + O << TAI->getWeakRefDirective() << Name << "\n"; + } + } + delete Mang; Mang = 0; return false; } diff --git a/lib/Target/ARM/ARMAsmPrinter.cpp b/lib/Target/ARM/ARMAsmPrinter.cpp index c30c593084b..291073e04cd 100644 --- a/lib/Target/ARM/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/ARMAsmPrinter.cpp @@ -62,8 +62,6 @@ namespace { : AsmPrinter(O, TM, T) { } - std::set ExtWeakSymbols; - /// We name each basic block in a Function with a unique number, so /// that we can consistently refer to them later. This is cleared /// at the beginning of each call to runOnMachineFunction(). @@ -246,7 +244,7 @@ void ARMAsmPrinter::printOperand(const MachineInstr *MI, int opNum) { std::string Name = Mang->getValueName(GV); O << Name; if (GV->hasExternalWeakLinkage()) { - ExtWeakSymbols.insert(Name); + ExtWeakSymbols.insert(GV); } } break; @@ -337,13 +335,6 @@ bool ARMAsmPrinter::doFinalization(Module &M) { } } - if (ExtWeakSymbols.begin() != ExtWeakSymbols.end()) - SwitchToDataSection(""); - for (std::set::iterator i = ExtWeakSymbols.begin(), - e = ExtWeakSymbols.end(); i != e; ++i) { - O << TAI->getWeakRefDirective() << *i << "\n"; - } - AsmPrinter::doFinalization(M); return false; // success } diff --git a/lib/Target/PowerPC/PPCAsmPrinter.cpp b/lib/Target/PowerPC/PPCAsmPrinter.cpp index 0659f033653..1ffd65265f1 100644 --- a/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -50,9 +50,6 @@ namespace { struct VISIBILITY_HIDDEN PPCAsmPrinter : public AsmPrinter { std::set FnStubs, GVStubs; const PPCSubtarget &Subtarget; - - // Necessary for external weak linkage support - std::set ExtWeakSymbols; PPCAsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T) : AsmPrinter(O, TM, T), Subtarget(TM.getSubtarget()) { @@ -162,7 +159,7 @@ namespace { FnStubs.insert(Name); O << "L" << Name << "$stub"; if (GV->hasExternalWeakLinkage()) - ExtWeakSymbols.insert(Name); + ExtWeakSymbols.insert(GV); return; } } @@ -337,7 +334,7 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO) { O << Name; if (GV->hasExternalWeakLinkage()) - ExtWeakSymbols.insert(Name); + ExtWeakSymbols.insert(GV); return; } @@ -658,22 +655,13 @@ bool DarwinAsmPrinter::doFinalization(Module &M) { // reference! if (const GlobalValue *GV = dyn_cast(C)) if (GV->hasExternalWeakLinkage()) - ExtWeakSymbols.insert(Mang->getValueName(GV)); + ExtWeakSymbols.insert(GV); EmitGlobalConstant(C); O << '\n'; } } - if (TAI->getWeakRefDirective()) { - if (ExtWeakSymbols.begin() != ExtWeakSymbols.end()) - SwitchToDataSection(""); - for (std::set::iterator i = ExtWeakSymbols.begin(), - e = ExtWeakSymbols.end(); i != e; ++i) { - O << TAI->getWeakRefDirective() << *i << "\n"; - } - } - bool isPPC64 = TD->getPointerSizeInBits() == 64; // Output stubs for dynamically-linked functions diff --git a/lib/Target/X86/X86ATTAsmPrinter.cpp b/lib/Target/X86/X86ATTAsmPrinter.cpp index 62f24db4e82..f9645b80d28 100755 --- a/lib/Target/X86/X86ATTAsmPrinter.cpp +++ b/lib/Target/X86/X86ATTAsmPrinter.cpp @@ -257,7 +257,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, } if (GV->hasExternalWeakLinkage()) - ExtWeakSymbols.insert(Name); + ExtWeakSymbols.insert(GV); int Offset = MO.getOffset(); if (Offset > 0) diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp index 021e55c5c5c..578e1aa9785 100644 --- a/lib/Target/X86/X86AsmPrinter.cpp +++ b/lib/Target/X86/X86AsmPrinter.cpp @@ -250,7 +250,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) { // reference! if (const GlobalValue *GV = dyn_cast(C)) if (GV->hasExternalWeakLinkage()) - ExtWeakSymbols.insert(Mang->getValueName(GV)); + ExtWeakSymbols.insert(GV); EmitGlobalConstant(C); O << '\n'; @@ -278,15 +278,6 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) { O << "\t.ascii \" -export:" << *i << "\"\n"; } - if (TAI->getWeakRefDirective()) { - if (ExtWeakSymbols.begin() != ExtWeakSymbols.end()) - SwitchToDataSection(""); - for (std::set::iterator i = ExtWeakSymbols.begin(), - e = ExtWeakSymbols.end(); i != e; ++i) { - O << TAI->getWeakRefDirective() << *i << "\n"; - } - } - if (Subtarget->isTargetDarwin()) { SwitchToDataSection(""); diff --git a/lib/Target/X86/X86AsmPrinter.h b/lib/Target/X86/X86AsmPrinter.h index b9b643b701e..af182fab259 100755 --- a/lib/Target/X86/X86AsmPrinter.h +++ b/lib/Target/X86/X86AsmPrinter.h @@ -86,9 +86,6 @@ struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter { // Necessary for dllexport support std::set DLLExportedFns, DLLExportedGVs; - // Necessary for external weak linkage support - std::set ExtWeakSymbols; - inline static bool isScale(const MachineOperand &MO) { return MO.isImmediate() && (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||