Write the section header in the end.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 8 Apr 2015 11:41:24 +0000 (11:41 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 8 Apr 2015 11:41:24 +0000 (11:41 +0000)
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.

llvm-svn: 234400

21 files changed:
llvm/lib/MC/ELFObjectWriter.cpp
llvm/test/MC/ARM/elf-movt.s
llvm/test/MC/ELF/cfi-adjust-cfa-offset.s
llvm/test/MC/ELF/cfi-advance-loc2.s
llvm/test/MC/ELF/cfi-def-cfa-offset.s
llvm/test/MC/ELF/cfi-def-cfa-register.s
llvm/test/MC/ELF/cfi-def-cfa.s
llvm/test/MC/ELF/cfi-escape.s
llvm/test/MC/ELF/cfi-offset.s
llvm/test/MC/ELF/cfi-register.s
llvm/test/MC/ELF/cfi-rel-offset.s
llvm/test/MC/ELF/cfi-rel-offset2.s
llvm/test/MC/ELF/cfi-remember.s
llvm/test/MC/ELF/cfi-restore.s
llvm/test/MC/ELF/cfi-same-value.s
llvm/test/MC/ELF/cfi-undefined.s
llvm/test/MC/ELF/cfi-window-save.s
llvm/test/MC/ELF/cfi-zero-addr-delta.s
llvm/test/MC/ELF/cfi.s
llvm/test/MC/ELF/relocation-pc.s
llvm/test/MC/ELF/rename.s

index b3ae4a5..f6b2090 100644 (file)
@@ -1676,8 +1676,6 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
   createIndexedSections(Asm, const_cast<MCAsmLayout &>(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(
index 0080db4..7f7590f 100644 (file)
@@ -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
index 200f897..bbaa785 100644 (file)
@@ -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
index 98caa01..be14a43 100644 (file)
@@ -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
index 59f7400..d84ab82 100644 (file)
@@ -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
index 178ba32..1efe0b2 100644 (file)
@@ -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
index dfb0d4b..5e185d5 100644 (file)
@@ -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
index 5394ee4..5c427d6 100644 (file)
@@ -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
index a65b4fc..ad73b50 100644 (file)
@@ -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
index 9441770..48fd879 100644 (file)
@@ -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
index 0dc69c8..15e1f9e 100644 (file)
@@ -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
index 360e7b0..53c2075 100644 (file)
@@ -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
index 3a38948..d9de0ff 100644 (file)
@@ -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
index e225797..19e1624 100644 (file)
@@ -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
index 2d37f4d..53da4dc 100644 (file)
@@ -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
index 568b315..7afeea6 100644 (file)
@@ -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
index b083901..00fd37f 100644 (file)
@@ -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
index 8662839..85aa3e1 100644 (file)
@@ -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
index 21be615..dc61dca 100644 (file)
@@ -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
index 0ce3201..dc60c1a 100644 (file)
@@ -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
index 5364dde..7031c01 100644 (file)
@@ -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