Make sure weak symbols are listed after the local ones.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115795 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2010-10-06 16:47:31 +00:00
parent 8cecf253e4
commit 3223f19ff0
3 changed files with 20 additions and 2 deletions

View File

@ -512,8 +512,9 @@ void ELFObjectWriterImpl::WriteSymbolTable(MCDataFragment *F,
for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i) {
ELFSymbolData &MSD = ExternalSymbolData[i];
MCSymbolData &Data = *MSD.SymbolData;
assert((Data.getFlags() & ELF_STB_Global) &&
"External symbol requires STB_GLOBAL flag");
assert(((Data.getFlags() & ELF_STB_Global) ||
(Data.getFlags() & ELF_STB_Weak)) &&
"External symbol requires STB_GLOBAL or STB_WEAK flag");
WriteSymbol(F, MSD, Layout);
if (GetBinding(Data) == ELF::STB_LOCAL)
LastLocalSymbolIndex++;

View File

@ -272,6 +272,7 @@ void MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
case MCSA_WeakReference:
case MCSA_Weak:
SetBinding(SD, ELF::STB_WEAK);
SD.setExternal(true);
BindingExplicitlySet.insert(Symbol);
break;

View File

@ -5,6 +5,20 @@
.weak foo
.long foo
// And that bar is after all local symbols
.weak bar
bar:
//CHECK: # Symbol 4
//CHECK-NEXT: (('st_name', 5) # 'bar'
//CHECK-NEXT: ('st_bind', 2)
//CHECK-NEXT: ('st_type', 0)
//CHECK-NEXT: ('st_other', 0)
//CHECK-NEXT: ('st_shndx', 1)
//CHECK-NEXT: ('st_value', 0)
//CHECK-NEXT: ('st_size', 0)
//CHECK-NEXT: ),
//CHECK-NEXT: # Symbol 5
//CHECK: (('st_name', 1) # 'foo'
//CHECK-NEXT: ('st_bind', 2)
//CHECK-NEXT: ('st_type', 0)
@ -12,3 +26,5 @@
//CHECK-NEXT: ('st_shndx', 0)
//CHECK-NEXT: ('st_value', 0)
//CHECK-NEXT: ('st_size', 0)
//CHECK-NEXT: ),
//CHECK-NEXT: ])