From 541279fdf9f3ff49908b4734a4daaca980a50441 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 8 Apr 2015 11:41:24 +0000 Subject: [PATCH] Write the section header in the end. One could make the argument for writing it immediately after the ELF header, but writing it in the middle of the sections like we were doing just makes it harder for no reason. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234400 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.cpp | 31 ++++------------------------- test/MC/ARM/elf-movt.s | 2 +- test/MC/ELF/cfi-adjust-cfa-offset.s | 2 +- test/MC/ELF/cfi-advance-loc2.s | 2 +- test/MC/ELF/cfi-def-cfa-offset.s | 2 +- test/MC/ELF/cfi-def-cfa-register.s | 2 +- test/MC/ELF/cfi-def-cfa.s | 2 +- test/MC/ELF/cfi-escape.s | 2 +- test/MC/ELF/cfi-offset.s | 2 +- test/MC/ELF/cfi-register.s | 2 +- test/MC/ELF/cfi-rel-offset.s | 2 +- test/MC/ELF/cfi-rel-offset2.s | 2 +- test/MC/ELF/cfi-remember.s | 2 +- test/MC/ELF/cfi-restore.s | 2 +- test/MC/ELF/cfi-same-value.s | 2 +- test/MC/ELF/cfi-undefined.s | 2 +- test/MC/ELF/cfi-window-save.s | 2 +- test/MC/ELF/cfi-zero-addr-delta.s | 2 +- test/MC/ELF/cfi.s | 2 +- test/MC/ELF/relocation-pc.s | 2 +- test/MC/ELF/rename.s | 2 +- 21 files changed, 24 insertions(+), 47 deletions(-) diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index b3ae4a545f1..f6b20900911 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -1676,8 +1676,6 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm, createIndexedSections(Asm, const_cast(Layout), GroupMap, RevGroupMap, SectionIndexMap); - unsigned NumRegularSections = Asm.size(); - // Compute symbol table information. computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap); @@ -1696,7 +1694,8 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm, ComputeSectionOrder(Asm, Sections); unsigned NumSections = Sections.size(); SectionOffsetMapTy SectionOffsetMap; - for (unsigned i = 0; i < NumRegularSections + 1; ++i) { + for (unsigned i = 0; i < NumSections; ++i) { + const MCSectionELF &Section = *Sections[i]; const MCSectionData &SD = Asm.getOrCreateSectionData(Section); @@ -1713,29 +1712,11 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm, const unsigned SectionHeaderOffset = FileOff; - uint64_t SectionHeaderEntrySize = is64Bit() ? - sizeof(ELF::Elf64_Shdr) : sizeof(ELF::Elf32_Shdr); - FileOff += (NumSections + 1) * SectionHeaderEntrySize; - - for (unsigned i = NumRegularSections + 1; i < NumSections; ++i) { - const MCSectionELF &Section = *Sections[i]; - const MCSectionData &SD = Asm.getOrCreateSectionData(Section); - - FileOff = RoundUpToAlignment(FileOff, SD.getAlignment()); - - // Remember the offset into the file for this section. - SectionOffsetMap[&Section] = FileOff; - - // Get the size of the section in the output file (including padding). - FileOff += GetSectionFileSize(Layout, SD); - } - // Write out the ELF header ... WriteHeader(Asm, SectionHeaderOffset, NumSections + 1); - // ... then the regular sections ... - // + because of .shstrtab - for (unsigned i = 0; i < NumRegularSections + 1; ++i) + // ... then the sections ... + for (unsigned i = 0; i < NumSections; ++i) WriteDataSectionData(Asm, Layout, *Sections[i]); uint64_t Padding = OffsetToAlignment(OS.tell(), NaturalAlignment); @@ -1743,10 +1724,6 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm, // ... then the section header table ... writeSectionHeader(Asm, GroupMap, Layout, SectionIndexMap, SectionOffsetMap); - - // ... and then the remaining sections ... - for (unsigned i = NumRegularSections + 1; i < NumSections; ++i) - WriteDataSectionData(Asm, Layout, *Sections[i]); } bool ELFObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl( diff --git a/test/MC/ARM/elf-movt.s b/test/MC/ARM/elf-movt.s index 0080db4ac8a..7f7590f426f 100644 --- a/test/MC/ARM/elf-movt.s +++ b/test/MC/ARM/elf-movt.s @@ -42,7 +42,7 @@ barf: @ @barf @ OBJ-NEXT: Flags [ (0x0) @ OBJ-NEXT: ] @ OBJ-NEXT: Address: 0x0 -@ OBJ-NEXT: Offset: 0x22C +@ OBJ-NEXT: Offset: @ OBJ-NEXT: Size: 16 @ OBJ-NEXT: Link: 6 @ OBJ-NEXT: Info: 1 diff --git a/test/MC/ELF/cfi-adjust-cfa-offset.s b/test/MC/ELF/cfi-adjust-cfa-offset.s index 200f897d2e1..bbaa7850566 100644 --- a/test/MC/ELF/cfi-adjust-cfa-offset.s +++ b/test/MC/ELF/cfi-adjust-cfa-offset.s @@ -53,7 +53,7 @@ f: // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x3C8 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 72 // CHECK-NEXT: Link: 7 // CHECK-NEXT: Info: 4 diff --git a/test/MC/ELF/cfi-advance-loc2.s b/test/MC/ELF/cfi-advance-loc2.s index 98caa0185f5..be14a431a1d 100644 --- a/test/MC/ELF/cfi-advance-loc2.s +++ b/test/MC/ELF/cfi-advance-loc2.s @@ -38,7 +38,7 @@ f: // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x490 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 7 // CHECK-NEXT: Info: 4 diff --git a/test/MC/ELF/cfi-def-cfa-offset.s b/test/MC/ELF/cfi-def-cfa-offset.s index 59f740055d4..d84ab829bb3 100644 --- a/test/MC/ELF/cfi-def-cfa-offset.s +++ b/test/MC/ELF/cfi-def-cfa-offset.s @@ -40,7 +40,7 @@ f: // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x398 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 7 // CHECK-NEXT: Info: 4 diff --git a/test/MC/ELF/cfi-def-cfa-register.s b/test/MC/ELF/cfi-def-cfa-register.s index 178ba32882d..1efe0b29eaa 100644 --- a/test/MC/ELF/cfi-def-cfa-register.s +++ b/test/MC/ELF/cfi-def-cfa-register.s @@ -35,7 +35,7 @@ f: // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x390 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 7 // CHECK-NEXT: Info: 4 diff --git a/test/MC/ELF/cfi-def-cfa.s b/test/MC/ELF/cfi-def-cfa.s index dfb0d4b5939..5e185d5d981 100644 --- a/test/MC/ELF/cfi-def-cfa.s +++ b/test/MC/ELF/cfi-def-cfa.s @@ -35,7 +35,7 @@ f: // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x390 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 7 // CHECK-NEXT: Info: 4 diff --git a/test/MC/ELF/cfi-escape.s b/test/MC/ELF/cfi-escape.s index 5394ee414aa..5c427d62304 100644 --- a/test/MC/ELF/cfi-escape.s +++ b/test/MC/ELF/cfi-escape.s @@ -36,7 +36,7 @@ f: // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x390 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 7 // CHECK-NEXT: Info: 4 diff --git a/test/MC/ELF/cfi-offset.s b/test/MC/ELF/cfi-offset.s index a65b4fc783c..ad73b502535 100644 --- a/test/MC/ELF/cfi-offset.s +++ b/test/MC/ELF/cfi-offset.s @@ -35,7 +35,7 @@ f: // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x390 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 7 // CHECK-NEXT: Info: 4 diff --git a/test/MC/ELF/cfi-register.s b/test/MC/ELF/cfi-register.s index 94417702c13..48fd87953b6 100644 --- a/test/MC/ELF/cfi-register.s +++ b/test/MC/ELF/cfi-register.s @@ -36,7 +36,7 @@ f: // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x390 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 7 // CHECK-NEXT: Info: 4 diff --git a/test/MC/ELF/cfi-rel-offset.s b/test/MC/ELF/cfi-rel-offset.s index 0dc69c89cf4..15e1f9eac15 100644 --- a/test/MC/ELF/cfi-rel-offset.s +++ b/test/MC/ELF/cfi-rel-offset.s @@ -44,7 +44,7 @@ f: // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x3A0 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 7 // CHECK-NEXT: Info: 4 diff --git a/test/MC/ELF/cfi-rel-offset2.s b/test/MC/ELF/cfi-rel-offset2.s index 360e7b0ea0f..53c207576a3 100644 --- a/test/MC/ELF/cfi-rel-offset2.s +++ b/test/MC/ELF/cfi-rel-offset2.s @@ -35,7 +35,7 @@ f: // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x390 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 7 // CHECK-NEXT: Info: 4 diff --git a/test/MC/ELF/cfi-remember.s b/test/MC/ELF/cfi-remember.s index 3a38948b6a3..d9de0ff170b 100644 --- a/test/MC/ELF/cfi-remember.s +++ b/test/MC/ELF/cfi-remember.s @@ -38,7 +38,7 @@ f: // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x390 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 7 // CHECK-NEXT: Info: 4 diff --git a/test/MC/ELF/cfi-restore.s b/test/MC/ELF/cfi-restore.s index e225797f54d..19e16247cea 100644 --- a/test/MC/ELF/cfi-restore.s +++ b/test/MC/ELF/cfi-restore.s @@ -36,7 +36,7 @@ f: // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x390 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 7 // CHECK-NEXT: Info: 4 diff --git a/test/MC/ELF/cfi-same-value.s b/test/MC/ELF/cfi-same-value.s index 2d37f4d0b43..53da4dc2494 100644 --- a/test/MC/ELF/cfi-same-value.s +++ b/test/MC/ELF/cfi-same-value.s @@ -36,7 +36,7 @@ f: // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x390 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 7 // CHECK-NEXT: Info: 4 diff --git a/test/MC/ELF/cfi-undefined.s b/test/MC/ELF/cfi-undefined.s index 568b3159cc4..7afeea68101 100644 --- a/test/MC/ELF/cfi-undefined.s +++ b/test/MC/ELF/cfi-undefined.s @@ -36,7 +36,7 @@ f: // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x390 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 7 // CHECK-NEXT: Info: 4 diff --git a/test/MC/ELF/cfi-window-save.s b/test/MC/ELF/cfi-window-save.s index b083901c137..00fd37f7fb1 100644 --- a/test/MC/ELF/cfi-window-save.s +++ b/test/MC/ELF/cfi-window-save.s @@ -38,7 +38,7 @@ f: // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x390 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 7 // CHECK-NEXT: Info: 4 diff --git a/test/MC/ELF/cfi-zero-addr-delta.s b/test/MC/ELF/cfi-zero-addr-delta.s index 8662839b527..85aa3e126df 100644 --- a/test/MC/ELF/cfi-zero-addr-delta.s +++ b/test/MC/ELF/cfi-zero-addr-delta.s @@ -43,7 +43,7 @@ f: // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x398 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 7 // CHECK-NEXT: Info: 4 diff --git a/test/MC/ELF/cfi.s b/test/MC/ELF/cfi.s index 21be615c5f3..dc61dca7ca6 100644 --- a/test/MC/ELF/cfi.s +++ b/test/MC/ELF/cfi.s @@ -355,7 +355,7 @@ f37: // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0xE70 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 1752 // CHECK-NEXT: Link: 7 // CHECK-NEXT: Info: 4 diff --git a/test/MC/ELF/relocation-pc.s b/test/MC/ELF/relocation-pc.s index 0ce32010cf0..dc60c1ae4a2 100644 --- a/test/MC/ELF/relocation-pc.s +++ b/test/MC/ELF/relocation-pc.s @@ -19,7 +19,7 @@ // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x2E8 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 48 // CHECK-NEXT: Link: 6 // CHECK-NEXT: Info: 1 diff --git a/test/MC/ELF/rename.s b/test/MC/ELF/rename.s index 5364dde9f46..7031c013862 100644 --- a/test/MC/ELF/rename.s +++ b/test/MC/ELF/rename.s @@ -41,7 +41,7 @@ defined3: // CHECK-NEXT: Flags [ (0x0) // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x0 -// CHECK-NEXT: Offset: 0x320 +// CHECK-NEXT: Offset: // CHECK-NEXT: Size: 24 // CHECK-NEXT: Link: 6 // CHECK-NEXT: Info: 1 -- 2.34.1