From 872266937b2110656db675f388d5470c53d8862a Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 7 Apr 2015 21:51:41 +0000 Subject: [PATCH] Don't subtract the header size just to add it back. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234362 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index 7505bb8884d..983e7b0b5b9 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -218,7 +218,7 @@ class ELFObjectWriter : public MCObjectWriter { } void WriteHeader(const MCAssembler &Asm, - uint64_t SectionDataSize, + uint64_t SectionHeaderOffset, unsigned NumberOfSections); void WriteSymbol(SymbolTableWriter &Writer, ELFSymbolData &MSD, @@ -429,7 +429,7 @@ ELFObjectWriter::~ELFObjectWriter() // Emit the ELF header. void ELFObjectWriter::WriteHeader(const MCAssembler &Asm, - uint64_t SectionDataSize, + uint64_t SectionHeaderOffset, unsigned NumberOfSections) { // ELF Header // ---------- @@ -463,8 +463,7 @@ void ELFObjectWriter::WriteHeader(const MCAssembler &Asm, Write32(ELF::EV_CURRENT); // e_version WriteWord(0); // e_entry, no entry point in .o file WriteWord(0); // e_phoff, no program header for .o - WriteWord(SectionDataSize + (is64Bit() ? sizeof(ELF::Elf64_Ehdr) : - sizeof(ELF::Elf32_Ehdr))); // e_shoff = sec hdr table off in bytes + WriteWord(SectionHeaderOffset); // e_shoff = sec hdr table off in bytes // e_flags = whatever the target wants Write32(Asm.getELFHeaderEFlags()); @@ -1719,7 +1718,7 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm, FileOff = RoundUpToAlignment(FileOff, NaturalAlignment); - const unsigned SectionHeaderOffset = FileOff - HeaderSize; + const unsigned SectionHeaderOffset = FileOff; uint64_t SectionHeaderEntrySize = is64Bit() ? sizeof(ELF::Elf64_Shdr) : sizeof(ELF::Elf32_Shdr);