From 3223f19ff0920ffee686faba3bf74babf580e8a5 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 6 Oct 2010 16:47:31 +0000 Subject: [PATCH] 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 --- lib/MC/ELFObjectWriter.cpp | 5 +++-- lib/MC/MCELFStreamer.cpp | 1 + test/MC/ELF/weak.s | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index da3e7efda8b..cbe0ebfa4ad 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -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++; diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp index b63bedc7030..65a0a7d7e65 100644 --- a/lib/MC/MCELFStreamer.cpp +++ b/lib/MC/MCELFStreamer.cpp @@ -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; diff --git a/test/MC/ELF/weak.s b/test/MC/ELF/weak.s index ef8e000c60d..0b93a871183 100644 --- a/test/MC/ELF/weak.s +++ b/test/MC/ELF/weak.s @@ -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: ])