diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2010-10-14 16:34:44 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2010-10-14 16:34:44 +0000 |
commit | a0949b50dcea35c08b50542091f97275f401529d (patch) | |
tree | 39be3892fa7ba7b6aed048aec249e46f36b4e0c8 /lib/MC/ELFObjectWriter.cpp | |
parent | 7bd698153db1403cbe8cc7cd8a250d4cd815d603 (diff) |
Remove some code duplication.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116484 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/ELFObjectWriter.cpp')
-rw-r--r-- | lib/MC/ELFObjectWriter.cpp | 67 |
1 files changed, 18 insertions, 49 deletions
diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index 8a8d68e55a..9a181621c7 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -781,7 +781,7 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) { StringMap<uint64_t> StringIndexMap; StringTable += '\x00'; - // Add the data for local symbols. + // Add the data for the symbols. for (MCAssembler::symbol_iterator it = Asm.symbol_begin(), ie = Asm.symbol_end(); it != ie; ++it) { const MCSymbol &Symbol = it->getSymbol(); @@ -789,48 +789,6 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) { if (!isInSymtab(Asm, *it, UsedInReloc.count(&Symbol))) continue; - if (!isLocal(*it)) - continue; - - uint64_t &Entry = StringIndexMap[Symbol.getName()]; - if (!Entry) { - Entry = StringTable.size(); - StringTable += Symbol.getName(); - StringTable += '\x00'; - } - - ELFSymbolData MSD; - MSD.SymbolData = it; - MSD.StringIndex = Entry; - - if (Symbol.isAbsolute()) { - MSD.SectionIndex = ELF::SHN_ABS; - LocalSymbolData.push_back(MSD); - } else { - const MCSymbol *SymbolP = &Symbol; - if (Symbol.isVariable()) { - const MCExpr *Value = Symbol.getVariableValue(); - assert (Value->getKind() == MCExpr::SymbolRef && "Unimplemented"); - const MCSymbolRefExpr *Ref = static_cast<const MCSymbolRefExpr*>(Value); - SymbolP = &Ref->getSymbol(); - } - MSD.SectionIndex = SectionIndexMap.lookup(&SymbolP->getSection()); - assert(MSD.SectionIndex && "Invalid section index!"); - LocalSymbolData.push_back(MSD); - } - } - - // Now add non-local symbols. - for (MCAssembler::symbol_iterator it = Asm.symbol_begin(), - ie = Asm.symbol_end(); it != ie; ++it) { - const MCSymbol &Symbol = it->getSymbol(); - - if (!isInSymtab(Asm, *it, UsedInReloc.count(&Symbol))) - continue; - - if (isLocal(*it)) - continue; - uint64_t &Entry = StringIndexMap[Symbol.getName()]; if (!Entry) { Entry = StringTable.size(); @@ -841,11 +799,18 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) { ELFSymbolData MSD; MSD.SymbolData = it; MSD.StringIndex = Entry; + bool Local = isLocal(*it); - // FIXME: There is duplicated code with the local case. if (it->isCommon()) { + assert(!Local); MSD.SectionIndex = ELF::SHN_COMMON; ExternalSymbolData.push_back(MSD); + } else if (Symbol.isAbsolute()) { + MSD.SectionIndex = ELF::SHN_ABS; + if (Local) + LocalSymbolData.push_back(MSD); + else + ExternalSymbolData.push_back(MSD); } else if (Symbol.isVariable()) { const MCExpr *Value = Symbol.getVariableValue(); assert (Value->getKind() == MCExpr::SymbolRef && "Unimplemented"); @@ -854,22 +819,26 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) { if (RefSymbol.isDefined()) { MSD.SectionIndex = SectionIndexMap.lookup(&RefSymbol.getSection()); assert(MSD.SectionIndex && "Invalid section index!"); - ExternalSymbolData.push_back(MSD); + if (Local) + LocalSymbolData.push_back(MSD); + else + ExternalSymbolData.push_back(MSD); } } else if (Symbol.isUndefined()) { + assert(!Local); 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); UndefinedSymbolData.push_back(MSD); - } else if (Symbol.isAbsolute()) { - MSD.SectionIndex = ELF::SHN_ABS; - ExternalSymbolData.push_back(MSD); } else { MSD.SectionIndex = SectionIndexMap.lookup(&Symbol.getSection()); assert(MSD.SectionIndex && "Invalid section index!"); - ExternalSymbolData.push_back(MSD); + if (Local) + LocalSymbolData.push_back(MSD); + else + ExternalSymbolData.push_back(MSD); } } |