print weak references

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32276 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2006-12-06 13:35:10 +00:00
parent 2792cfb82d
commit 392b1b2ef3
3 changed files with 24 additions and 2 deletions

View File

@ -63,6 +63,8 @@ namespace {
: AsmPrinter(O, TM, T) {
}
std::set<std::string> 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().
@ -127,7 +129,7 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
break;
case Function::WeakLinkage:
case Function::LinkOnceLinkage:
O << "\t.weak\t" << CurrentFnName << "\n";
O << TAI->getWeakRefDirective() << CurrentFnName << "\n";
break;
}
EmitAlignment(2, F);
@ -244,6 +246,9 @@ void ARMAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
GlobalValue *GV = MO.getGlobal();
std::string Name = Mang->getValueName(GV);
O << Name;
if (GV->hasExternalWeakLinkage()) {
ExtWeakSymbols.insert(Name);
}
}
break;
case MachineOperand::MO_ExternalSymbol:
@ -325,6 +330,13 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
}
}
if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
SwitchToDataSection("");
for (std::set<std::string>::iterator i = ExtWeakSymbols.begin(),
e = ExtWeakSymbols.end(); i != e; ++i) {
O << TAI->getWeakRefDirective() << *i << "\n";
}
AsmPrinter::doFinalization(M);
return false; // success
}

View File

@ -23,4 +23,5 @@ ARMTargetAsmInfo::ARMTargetAsmInfo(const ARMTargetMachine &TM) {
CommentString = "@";
ConstantPoolSection = "\t.text\n";
AlignmentIsInBytes = false;
WeakRefDirective = "\t.weak\t";
}

View File

@ -1,5 +1,6 @@
; RUN: llvm-upgrade < %s | llvm-as | llc -march=arm &&
; RUN: llvm-upgrade < %s | llvm-as | llc -march=arm | grep .weak
; RUN: llvm-upgrade < %s | llvm-as | llc -march=arm | grep .weak.*f &&
; RUN: llvm-upgrade < %s | llvm-as | llc -march=arm | grep .weak.*h
implementation ; Functions:
@ -7,3 +8,11 @@ weak uint %f() {
entry:
unreachable
}
void %g() {
entry:
tail call void %h( )
ret void
}
declare extern_weak void %h()