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: ])