diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2010-10-28 18:33:03 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2010-10-28 18:33:03 +0000 |
commit | f571f9a8fe764d5010970e45203415cb00eab739 (patch) | |
tree | ce25fcde729c3922bc7503da03955c057c62aa3f /lib/MC/ELFObjectWriter.cpp | |
parent | 3cabc9d2c974140c384e21cf5c1904b514acb82b (diff) |
Aliases defined with .symver should copy the binding of the symbols they alias.
Move the existing patching for undefined symbols so that all the patching
is done in the same function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117570 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/ELFObjectWriter.cpp')
-rw-r--r-- | lib/MC/ELFObjectWriter.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index b979de9322..ef2901d749 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -465,14 +465,32 @@ void ELFObjectWriterImpl::ExecutePostLayoutBinding(MCAssembler &Asm) { for (MCAssembler::symbol_iterator it = Asm.symbol_begin(), ie = Asm.symbol_end(); it != ie; ++it) { const MCSymbol &Alias = it->getSymbol(); - if (!Alias.isVariable()) - continue; const MCSymbol &Symbol = AliasedSymbol(Alias); + MCSymbolData &SD = Asm.getSymbolData(Symbol); + + // Undefined symbols are global, but this is the first place we + // are able to set it. + if (Symbol.isUndefined() && !Symbol.isVariable()) { + if (GetBinding(SD) == ELF::STB_LOCAL) { + SetBinding(SD, ELF::STB_GLOBAL); + SetBinding(*it, ELF::STB_GLOBAL); + } + } + + // Not an alias. + if (&Symbol == &Alias) + continue; + StringRef AliasName = Alias.getName(); size_t Pos = AliasName.find('@'); if (Pos == StringRef::npos) continue; + // Aliases defined with .symvar copy the binding from the symbol they alias. + // This is the first place we are able to copy this information. + it->setExternal(SD.isExternal()); + SetBinding(*it, GetBinding(SD)); + StringRef Rest = AliasName.substr(Pos); if (!Symbol.isUndefined() && !Rest.startswith("@@@")) continue; @@ -881,6 +899,7 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) { MCSymbol *Sym = Asm.getContext().GetOrCreateSymbol(Name); MCSymbolData &Data = Asm.getOrCreateSymbolData(*Sym); Data.setExternal(true); + SetBinding(Data, ELF::STB_GLOBAL); } // Build section lookup table. @@ -916,10 +935,6 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) { MSD.SectionIndex = ELF::SHN_ABS; } else if (RefSymbol.isUndefined()) { MSD.SectionIndex = ELF::SHN_UNDEF; - // FIXME: Undefined symbols are global, but this is the first place we - // are able to set it. - if (GetBinding(*it) == ELF::STB_LOCAL) - SetBinding(*it, ELF::STB_GLOBAL); } else { MSD.SectionIndex = SectionIndexMap.lookup(&RefSymbol.getSection()); assert(MSD.SectionIndex && "Invalid section index!"); |