From 5f237942f5fb678c673d37d3fa165bbd8300bacd Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Tue, 17 Aug 2010 00:00:46 +0000 Subject: [PATCH] A round of minor cleanups for ELFObjectWriter. llvm-svn: 111213 --- llvm/lib/MC/ELFObjectWriter.cpp | 41 ++++++++++----------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index 4d0b374196c4..34f1fcd134e6 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -354,6 +354,7 @@ void ELFObjectWriterImpl::WriteSymbolEntry(MCDataFragment *F, uint64_t name, String8(buf, info); F->getContents() += StringRef(buf, 1); // st_info + String8(buf, other); F->getContents() += StringRef(buf, 1); // st_other @@ -416,9 +417,7 @@ void ELFObjectWriterImpl::WriteSymbol(MCDataFragment *F, ELFSymbolData &MSD, Value = Layout.getSymbolAddress(&Data); } } else if (ESize->getKind() == MCExpr::Constant) { - const MCConstantExpr *CE; - CE = static_cast(ESize); - Size = CE->getValue(); + Size = static_cast(ESize)->getValue(); } else { assert(0 && "Unsupported size expression"); } @@ -440,8 +439,7 @@ void ELFObjectWriterImpl::WriteSymbolTable(MCDataFragment *F, // The first entry is the undefined symbol entry. unsigned EntrySize = Is64Bit ? ELF::SYMENTRY_SIZE64 : ELF::SYMENTRY_SIZE32; - for (unsigned i = 0; i < EntrySize; ++i) - F->getContents() += '\x00'; + F->getContents().append(EntrySize, '\x00'); // Write the symbol table entries. LastLocalSymbolIndex = LocalSymbolData.size() + 1; @@ -456,9 +454,8 @@ void ELFObjectWriterImpl::WriteSymbolTable(MCDataFragment *F, unsigned Index = 1; for (MCAssembler::const_iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it, ++Index) { - const MCSectionData &SD = *it; const MCSectionELF &Section = - static_cast(SD.getSection()); + static_cast(it->getSection()); // Leave out relocations so we don't have indexes within // the relocations messed up if (Section.getType() == ELF::SHT_RELA) @@ -613,15 +610,10 @@ uint64_t ELFObjectWriterImpl::getSymbolIndexInSymbolTable(MCAssembler &Asm, ELFSymbolData MSD; MSD.SymbolData = it; - if (Symbol.isUndefined()) { + if (Symbol.isUndefined()) Undefined.push_back(MSD); - } else if (Symbol.isAbsolute()) { + else External.push_back(MSD); - } else if (it->isCommon()) { - External.push_back(MSD); - } else { - External.push_back(MSD); - } } array_pod_sort(Local.begin(), Local.end()); @@ -800,19 +792,12 @@ void ELFObjectWriterImpl::WriteRelocationsFragment(const MCAssembler &Asm, for (unsigned i = 0, e = Relocs.size(); i != e; ++i) { ELFRelocationEntry entry = Relocs[e - i - 1]; - if (Is64Bit) { - F->getContents() += StringRef((const char *)&entry.r_offset, 8); - F->getContents() += StringRef((const char *)&entry.r_info, 8); + unsigned WordSize = Is64Bit ? 8 : 4; + F->getContents() += StringRef((const char *)&entry.r_offset, WordSize); + F->getContents() += StringRef((const char *)&entry.r_info, WordSize); - if (HasRelocationAddend) - F->getContents() += StringRef((const char *)&entry.r_addend, 8); - } else { - F->getContents() += StringRef((const char *)&entry.r_offset, 4); - F->getContents() += StringRef((const char *)&entry.r_info, 4); - - if (HasRelocationAddend) - F->getContents() += StringRef((const char *)&entry.r_addend, 4); - } + if (HasRelocationAddend) + F->getContents() += StringRef((const char *)&entry.r_addend, WordSize); } } @@ -877,10 +862,8 @@ void ELFObjectWriterImpl::CreateMetadataSections(MCAssembler &Asm, for (MCAssembler::const_iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it) { - const MCSectionData &SD = *it; const MCSectionELF &Section = - static_cast(SD.getSection()); - + static_cast(it->getSection()); // Remember the index into the string table so we can write it // into the sh_name field of the section header table.