diff options
Diffstat (limited to 'llvm/lib/MC/ELFObjectWriter.cpp')
| -rw-r--r-- | llvm/lib/MC/ELFObjectWriter.cpp | 15 | 
1 files changed, 10 insertions, 5 deletions
| diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index ebbba1327dd..f3a09c8df23 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -386,6 +386,8 @@ void ELFObjectWriterImpl::WriteSymbol(MCDataFragment *F, ELFSymbolData &MSD,    if (Data.isCommon() && Data.isExternal())      Value = Data.getCommonAlignment(); +  assert(!(Data.isCommon() && !Data.isExternal())); +    if (!Data.isCommon() && !(Data.getFlags() & ELF_STB_Weak))      if (MCFragment *FF = Data.getFragment())        Value = Layout.getSymbolAddress(&Data) - @@ -502,7 +504,10 @@ void ELFObjectWriterImpl::RecordRelocation(const MCAssembler &Asm,      if (Base) {        if (F && (!Symbol->isInSection() || SD.isCommon()) && !SD.isExternal()) {          Index = F->getParent()->getOrdinal() + LocalSymbolData.size() + 1; -        Value += Layout.getSymbolAddress(&SD); + +        MCSectionData *FSD = F->getParent(); +        // Offset of the symbol in the section +        Value += Layout.getSymbolAddress(&SD) - Layout.getSectionAddress(FSD);        } else          Index = getSymbolIndexInSymbolTable(Asm, Symbol);        if (Base != &SD) @@ -672,7 +677,10 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) {      MSD.SymbolData = it;      MSD.StringIndex = Entry; -    if (Symbol.isUndefined()) { +    if (it->isCommon()) { +      MSD.SectionIndex = ELF::SHN_COMMON; +      ExternalSymbolData.push_back(MSD); +    } else if (Symbol.isUndefined()) {        MSD.SectionIndex = ELF::SHN_UNDEF;        // XXX: for some reason we dont Emit* this        it->setFlags(it->getFlags() | ELF_STB_Global); @@ -680,9 +688,6 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) {      } else if (Symbol.isAbsolute()) {        MSD.SectionIndex = ELF::SHN_ABS;        ExternalSymbolData.push_back(MSD); -    } else if (it->isCommon()) { -      MSD.SectionIndex = ELF::SHN_COMMON; -      ExternalSymbolData.push_back(MSD);      } else {        MSD.SectionIndex = SectionIndexMap.lookup(&Symbol.getSection());        assert(MSD.SectionIndex && "Invalid section index!"); | 

