Write the section header string table directly to the output stream.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 29 Apr 2015 20:25:24 +0000 (20:25 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 29 Apr 2015 20:25:24 +0000 (20:25 +0000)
Instead of accumulating the content in a fragment first, just write it
to the output stream.

Also put it first in the section table, so that we never have to worry
about its index being >= SHN_LORESERVE.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236145 91177308-0d34-0410-b5e6-96231b3b80d8

14 files changed:
lib/MC/ELFObjectWriter.cpp
test/MC/ARM/eh-directive-section-comdat.s
test/MC/ARM/eh-directive-section-multiple-func.s
test/MC/ARM/eh-directive-section.s
test/MC/ARM/eh-directive-text-section.s
test/MC/ARM/eh-link.s
test/MC/ELF/comdat-dup-group-name.s
test/MC/ELF/comdat-reloc.s
test/MC/ELF/comdat.s
test/MC/ELF/empty.s
test/MC/ELF/many-sections-2.s
test/MC/ELF/many-sections.s
test/MC/ELF/section-sym.s
test/MC/ELF/section-unique.s

index bcdde320d3106c5ccf0871db7efa81ec660969c8..0b8f752d0764f405b7f09b4fc1c5b86042dafe6d 100644 (file)
@@ -247,6 +247,9 @@ class ELFObjectWriter : public MCObjectWriter {
 
     void WriteRelocations(MCAssembler &Asm, const MCAsmLayout &Layout);
 
+    void
+    createSectionHeaderStringTable(MCAssembler &Asm,
+                                   std::vector<const MCSectionELF *> &Sections);
     void CreateMetadataSections(MCAssembler &Asm, const MCAsmLayout &Layout,
                                 std::vector<const MCSectionELF *> &Sections);
 
@@ -452,10 +455,8 @@ void ELFObjectWriter::WriteHeader(const MCAssembler &Asm,
     Write16(NumberOfSections);
 
   // e_shstrndx  = Section # of '.shstrtab'
-  if (ShstrtabIndex >= ELF::SHN_LORESERVE)
-    Write16(ELF::SHN_XINDEX);
-  else
-    Write16(ShstrtabIndex);
+  assert(ShstrtabIndex < ELF::SHN_LORESERVE);
+  Write16(ShstrtabIndex);
 }
 
 uint64_t ELFObjectWriter::SymbolValue(MCSymbolData &Data,
@@ -1372,6 +1373,21 @@ void ELFObjectWriter::WriteRelocationsFragment(const MCAssembler &Asm,
   }
 }
 
+void ELFObjectWriter::createSectionHeaderStringTable(
+    MCAssembler &Asm, std::vector<const MCSectionELF *> &Sections) {
+  const MCSectionELF *ShstrtabSection = Sections[ShstrtabIndex - 1];
+
+  Asm.getOrCreateSectionData(*ShstrtabSection);
+
+  for (MCSectionData &SD : Asm) {
+    const MCSectionELF &Section =
+        static_cast<const MCSectionELF &>(SD.getSection());
+    ShStrTabBuilder.add(Section.getSectionName());
+  }
+  ShStrTabBuilder.finalize(StringTableBuilder::ELF);
+  OS << ShStrTabBuilder.data();
+}
+
 void ELFObjectWriter::CreateMetadataSections(
     MCAssembler &Asm, const MCAsmLayout &Layout,
     std::vector<const MCSectionELF *> &Sections) {
@@ -1380,14 +1396,6 @@ void ELFObjectWriter::CreateMetadataSections(
 
   unsigned EntrySize = is64Bit() ? ELF::SYMENTRY_SIZE64 : ELF::SYMENTRY_SIZE32;
 
-  // We construct .shstrtab, .symtab and .strtab in this order to match gnu as.
-  const MCSectionELF *ShstrtabSection =
-      Ctx.getELFSection(".shstrtab", ELF::SHT_STRTAB, 0);
-  MCSectionData &ShstrtabSD = Asm.getOrCreateSectionData(*ShstrtabSection);
-  ShstrtabSD.setAlignment(1);
-  ShstrtabIndex = Sections.size() + 1;
-  Sections.push_back(ShstrtabSection);
-
   const MCSectionELF *SymtabSection =
     Ctx.getELFSection(".symtab", ELF::SHT_SYMTAB, 0,
                       EntrySize, "");
@@ -1410,18 +1418,6 @@ void ELFObjectWriter::CreateMetadataSections(
   F = new MCDataFragment(&StrtabSD);
   F->getContents().append(StrTabBuilder.data().begin(),
                           StrTabBuilder.data().end());
-
-  F = new MCDataFragment(&ShstrtabSD);
-
-  // Section header string table.
-  for (auto it = Asm.begin(), ie = Asm.end(); it != ie; ++it) {
-    const MCSectionELF &Section =
-      static_cast<const MCSectionELF&>(it->getSection());
-    ShStrTabBuilder.add(Section.getSectionName());
-  }
-  ShStrTabBuilder.finalize(StringTableBuilder::ELF);
-  F->getContents().append(ShStrTabBuilder.data().begin(),
-                          ShStrTabBuilder.data().end());
 }
 
 void ELFObjectWriter::createIndexedSections(
@@ -1430,6 +1426,12 @@ void ELFObjectWriter::createIndexedSections(
     SectionIndexMapTy &SectionIndexMap) {
   MCContext &Ctx = Asm.getContext();
 
+  const MCSectionELF *ShstrtabSection =
+      Ctx.getELFSection(".shstrtab", ELF::SHT_STRTAB, 0);
+  Sections.push_back(ShstrtabSection);
+  ShstrtabIndex = Sections.size();
+  assert(ShstrtabIndex == 1);
+
   // Build the groups
   for (const MCSectionData &SD : Asm) {
     const MCSectionELF &Section =
@@ -1537,9 +1539,7 @@ void ELFObjectWriter::writeSectionHeader(
   // Null section first.
   uint64_t FirstSectionSize =
       (NumSections + 1) >= ELF::SHN_LORESERVE ? NumSections + 1 : 0;
-  uint32_t FirstSectionLink =
-    ShstrtabIndex >= ELF::SHN_LORESERVE ? ShstrtabIndex : 0;
-  WriteSecHdrEntry(0, 0, 0, 0, 0, FirstSectionSize, FirstSectionLink, 0, 0, 0);
+  WriteSecHdrEntry(0, 0, 0, 0, 0, FirstSectionSize, 0, 0, 0, 0);
 
   for (unsigned i = 0; i < NumSections; ++i) {
     const MCSectionELF &Section = *Sections[i];
@@ -1576,15 +1576,16 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
 
   CreateMetadataSections(Asm, Layout, Sections);
 
-  unsigned NumSections = Asm.size();
+  unsigned NumSections = Asm.size() + 1;
   SectionOffsetsTy SectionOffsets;
 
   // Write out the ELF header ...
   WriteHeader(Asm, NumSections + 1);
 
   // ... then the sections ...
-  for (const MCSectionELF *Section : Sections) {
-    const MCSectionData &SD = Asm.getOrCreateSectionData(*Section);
+  SectionOffsets.push_back(std::make_pair(0, 0));
+  for (auto I = ++Sections.begin(), E = Sections.end(); I != E; ++I) {
+    const MCSectionData &SD = Asm.getOrCreateSectionData(**I);
     uint64_t Padding = OffsetToAlignment(OS.tell(), SD.getAlignment());
     WriteZeros(Padding);
 
@@ -1595,6 +1596,13 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
     SectionOffsets.push_back(std::make_pair(SecStart, SecEnd));
   }
 
+  {
+    uint64_t SecStart = OS.tell();
+    createSectionHeaderStringTable(Asm, Sections);
+    uint64_t SecEnd = OS.tell();
+    SectionOffsets[0] = std::make_pair(SecStart, SecEnd);
+  }
+
   uint64_t NaturalAlignment = is64Bit() ? 8 : 4;
   uint64_t Padding = OffsetToAlignment(OS.tell(), NaturalAlignment);
   WriteZeros(Padding);
index fb2a83b47e41224f3c2ab0262a26f865103f55f1..3f24ddf2864a83f3f62ba0727572b1b776d2aef4 100644 (file)
@@ -52,7 +52,7 @@ func1:
 @ The second, third, and fourth word should correspond to the section index
 @ of .TEST1, .ARM.extab.TEST1, and .ARM.exidx.TEST1.
 @-------------------------------------------------------------------------------
-@ CHECK:       0000: 01000000 05000000 06000000 07000000  |................|
+@ CHECK:       0000: 01000000 06000000 07000000 08000000  |................|
 @ CHECK:     )
 @ CHECK:   }
 
@@ -61,8 +61,8 @@ func1:
 @ Check the .TEST1 section
 @-------------------------------------------------------------------------------
 @ CHECK:   Section {
-@ CHECK:     Index: 5
-@ CHECK:     Name: .TEST1
+@ CHECK:     Index: 6
+@ CHECK-NEXT:     Name: .TEST1
 @ CHECK:     Type: SHT_PROGBITS (0x1)
 @-------------------------------------------------------------------------------
 @ The flags should contain SHF_GROUP.
@@ -79,8 +79,8 @@ func1:
 @ Check the .ARM.extab.TEST1 section
 @-------------------------------------------------------------------------------
 @ CHECK:   Section {
-@ CHECK:     Index: 6
-@ CHECK:     Name: .ARM.extab.TEST1
+@ CHECK:     Index: 7
+@ CHECK-NEXT:     Name: .ARM.extab.TEST1
 @ CHECK:     Type: SHT_PROGBITS (0x1)
 @-------------------------------------------------------------------------------
 @ The flags should contain SHF_GROUP.
@@ -96,8 +96,8 @@ func1:
 @ Check the .ARM.exidx.TEST1 section
 @-------------------------------------------------------------------------------
 @ CHECK:   Section {
-@ CHECK:     Index: 7
-@ CHECK:     Name: .ARM.exidx.TEST1
+@ CHECK:     Index: 8
+@ CHECK-NEXT:     Name: .ARM.exidx.TEST1
 @ CHECK:     Type: SHT_ARM_EXIDX (0x70000001)
 @-------------------------------------------------------------------------------
 @ The flags should contain SHF_GROUP.
@@ -107,7 +107,7 @@ func1:
 @ CHECK:       SHF_GROUP (0x200)
 @ CHECK:       SHF_LINK_ORDER (0x80)
 @ CHECK:     ]
-@ CHECK:     Link: 5
+@ CHECK:     Link: 6
 @ CHECK:   }
 @ CHECK: ]
 
@@ -121,6 +121,6 @@ func1:
 @ CHECK:     Name: func1
 @ CHECK:     Binding: Weak (0x2)
 @ CHECK:     Type: Function (0x2)
-@ CHECK:     Section: .TEST1 (0x5)
+@ CHECK:     Section: .TEST1
 @ CHECK:   }
 @ CHECK: ]
index e7198a4aecbeac2dde56f44a0cd50abd5b9be6c5..e5307cf9190cd0a1fc6579fd8ac81c3501e9612e 100644 (file)
@@ -54,7 +54,8 @@ func2:
 @ Check the .TEST1 section.  There should be two "bx lr" instructions.
 @-------------------------------------------------------------------------------
 @ CHECK:   Section {
-@ CHECK:     Name: .TEST1
+@ CHECK:     Index: 5
+@ CHECK-NEXT:     Name: .TEST1
 @ CHECK:     SectionData (
 @ CHECK:       0000: 1EFF2FE1 1EFF2FE1                    |../.../.|
 @ CHECK:     )
@@ -86,7 +87,7 @@ func2:
 @-------------------------------------------------------------------------------
 @ CHECK:   Section {
 @ CHECK:     Name: .ARM.exidx.TEST1
-@ CHECK:     Link: 4
+@ CHECK:     Link: 5
 @-------------------------------------------------------------------------------
 @ The first word should be the offset to .TEST1.
 @ The second word should be the offset to .ARM.extab.TEST1
@@ -123,7 +124,7 @@ func2:
 @ CHECK:     Binding: Global (0x1)
 @ CHECK:     Type: Function (0x2)
 @ CHECK:     Other: 0
-@ CHECK:     Section: .TEST1 (0x4)
+@ CHECK:     Section: .TEST1
 @ CHECK:   }
 @ CHECK:   Symbol {
 @ CHECK:     Name: func2
@@ -132,6 +133,6 @@ func2:
 @ CHECK:     Binding: Global (0x1)
 @ CHECK:     Type: Function (0x2)
 @ CHECK:     Other: 0
-@ CHECK:     Section: .TEST1 (0x4)
+@ CHECK:     Section: .TEST1
 @ CHECK:   }
 @ CHECK: ]
index 53ac48e848b565accfb0d339d121adb345bc309b..f46daf3ad8af1a03438747874ea1ea90c1b7a77f 100644 (file)
@@ -50,8 +50,8 @@ func2:
 @-------------------------------------------------------------------------------
 @ CHECK: Sections [
 @ CHECK:   Section {
-@ CHECK:     Index: 4
-@ CHECK:     Name: .TEST1
+@ CHECK:     Index: 5
+@ CHECK-NEXT:     Name: .TEST1
 @ CHECK:     SectionData (
 @ CHECK:       0000: 1EFF2FE1                             |../.|
 @ CHECK:     )
@@ -84,7 +84,7 @@ func2:
 @-------------------------------------------------------------------------------
 @ This section should linked with .TEST1 section.
 @-------------------------------------------------------------------------------
-@ CHECK:     Link: 4
+@ CHECK:     Link: 5
 
 @-------------------------------------------------------------------------------
 @ The first word should be relocated to the code address in .TEST1 section.
@@ -109,8 +109,8 @@ func2:
 @ Check the TEST2 section (without the dot in the beginning)
 @-------------------------------------------------------------------------------
 @ CHECK:   Section {
-@ CHECK:     Index: 7
-@ CHECK:     Name: TEST2
+@ CHECK:     Index: 8
+@ CHECK-NEXT:     Name: TEST2
 @ CHECK:     SectionData (
 @ CHECK:       0000: 1EFF2FE1                             |../.|
 @ CHECK:     )
@@ -143,7 +143,7 @@ func2:
 @-------------------------------------------------------------------------------
 @ This section should linked with TEST2 section.
 @-------------------------------------------------------------------------------
-@ CHECK:     Link: 7
+@ CHECK:     Link: 8
 
 @-------------------------------------------------------------------------------
 @ The first word should be relocated to the code address in TEST2 section.
@@ -171,10 +171,10 @@ func2:
 @ CHECK: Symbols [
 @ CHECK:   Symbol {
 @ CHECK:     Name: func1
-@ CHECK:     Section: .TEST1 (0x4)
+@ CHECK:     Section: .TEST1
 @ CHECK:   }
 @ CHECK:   Symbol {
 @ CHECK:     Name: func2
-@ CHECK:     Section: TEST2 (0x7)
+@ CHECK:     Section: TEST2
 @ CHECK:   }
 @ CHECK: ]
index 4a073aa81151ddf6ae396e6c80d59c1cba0dabd6..32696d5a1dad34c879ac0ddca1d529d0ba01a64e 100644 (file)
@@ -29,8 +29,8 @@ func1:
 @-------------------------------------------------------------------------------
 @ Check the index of .text section.  This will be used in .ARM.exidx.
 @-------------------------------------------------------------------------------
-@ CHECK:     Index: 1
-@ CHECK:     Name: .text
+@ CHECK:     Index: 2
+@ CHECK-NEXT:     Name: .text
 @ CHECK:     Type: SHT_PROGBITS (0x1)
 @ CHECK:     Flags [ (0x6)
 @ CHECK:       SHF_ALLOC (0x2)
@@ -58,7 +58,7 @@ func1:
 @ Check the linked section of the EXIDX section.  This should be the index
 @ of the .text section.
 @-------------------------------------------------------------------------------
-@ CHECK:     Link: 1
+@ CHECK:     Link: 2
 
 @-------------------------------------------------------------------------------
 @ The first word should be the offset to .text.  The second word should be
index 296f9072e0e074283405076d1717ad45e4a58208..ddcb257e7f6d0647ad40ac48efca24bfef90b9a9 100644 (file)
@@ -8,7 +8,7 @@
 @ name first we could use a FileCheck variable.
 
 @ CHECK:      Section {
-@ CHECK:        Index: 6
+@ CHECK:        Index: 7
 @ CHECK-NEXT:   Name: .text
 @ CHECK-NEXT:   Type: SHT_PROGBITS
 @ CHECK-NEXT:   Flags [
@@ -25,7 +25,7 @@
 @ CHECK-NEXT:   EntrySize: 0
 @ CHECK-NEXT: }
 @ CHECK-NEXT: Section {
-@ CHECK-NEXT:   Index: 7
+@ CHECK-NEXT:   Index: 8
 @ CHECK-NEXT:   Name: .ARM.exidx
 @ CHECK-NEXT:   Type: SHT_ARM_EXIDX
 @ CHECK-NEXT:   Flags [
 @ CHECK-NEXT:   Address: 0x0
 @ CHECK-NEXT:   Offset: 0x58
 @ CHECK-NEXT:   Size: 8
-@ CHECK-NEXT:   Link: 6
+@ CHECK-NEXT:   Link: 7
 @ CHECK-NEXT:   Info: 0
 @ CHECK-NEXT:   AddressAlignment: 4
 @ CHECK-NEXT:   EntrySize: 0
 @ CHECK-NEXT: }
 
 @ CHECK:      Section {
-@ CHECK:        Index: 8
+@ CHECK:        Index: 9
 @ CHECK-NEXT:   Name: .text
 @ CHECK-NEXT:   Type: SHT_PROGBITS
 @ CHECK-NEXT:   Flags [
@@ -60,7 +60,7 @@
 @ CHECK-NEXT:   EntrySize: 0
 @ CHECK-NEXT: }
 @ CHECK-NEXT: Section {
-@ CHECK-NEXT:   Index: 9
+@ CHECK-NEXT:   Index: 10
 @ CHECK-NEXT:   Name: .ARM.exidx
 @ CHECK-NEXT:   Type: SHT_ARM_EXIDX
 @ CHECK-NEXT:   Flags [
@@ -71,7 +71,7 @@
 @ CHECK-NEXT:   Address: 0x0
 @ CHECK-NEXT:   Offset:
 @ CHECK-NEXT:   Size: 8
-@ CHECK-NEXT:   Link: 8
+@ CHECK-NEXT:   Link: 9
 @ CHECK-NEXT:   Info: 0
 @ CHECK-NEXT:   AddressAlignment: 4
 @ CHECK-NEXT:   EntrySize: 0
index 1181e2eab02ae718d81fd4b5179c753c81d7e0a6..acf0db1b54e9e34fef19b7639dcfe21c22adaafd 100644 (file)
@@ -2,35 +2,35 @@
 
 // Test that we produce two foo sections, each in separate groups
 
-// CHECK: Index: 1
+// CHECK: Index: 2
 // CHECK-NEXT: Name: .group
 
-// CHECK: Index: 2
+// CHECK: Index: 3
 // CHECK-NEXT: Name: .group
 
-// CHECK: Index: 6
+// CHECK: Index: 7
 // CHECK-NEXT: Name: .foo
 
-// CHECK: Index: 7
+// CHECK: Index: 8
 // CHECK-NEXT: Name: .foo
 
 // CHECK: Symbols [
 
 // CHECK: Name: f1
 // CHECK-NOT: }
-// CHECK: Section: .group (0x1)
+// CHECK: Section: .group (0x2)
 
 // CHECK: Name: f2
 // CHECK-NOT: }
-// CHECK: Section: .group (0x2)
+// CHECK: Section: .group (0x3)
 
 // CHECK: Name: .foo
 // CHECK-NOT: }
-// CHECK: Section: .foo (0x6)
+// CHECK: Section: .foo (0x7)
 
 // CHECK: Name: .foo
 // CHECK-NOT: }
-// CHECK: Section: .foo (0x7)
+// CHECK: Section: .foo (0x8)
 
 
        .section        .foo,"axG",@progbits,f1,comdat
index e7aa3d93738e0cee52b3a7c1b09e89433c1ba014..80901deac6edb5a17cd233e9cecaa6ce86ddb65b 100644 (file)
@@ -16,14 +16,14 @@ world:
 // CHECK:  Name: .group
 // CHECK-NOT: SectionData
 // CHECK: SectionData
-// CHECK-NEXT: 0000: 01000000 05000000 07000000
+// CHECK-NEXT: 0000: 01000000 06000000 08000000
 
-// CHECK: Index: 5
+// CHECK: Index: 6
 // CHECK-NEXT: Name: .text.world
 // CHECK-NOT: Section {
 // CHECK: SHF_GROUP
 
-// CHECK: Index: 7
+// CHECK: Index: 8
 // CHECK-NEXT: Name: .rela.text.world
 // CHECK-NOT: Section {
 // CHECK: SHF_GROUP
index 479667552204d32aab6e95601b6051b5ab97220e..1b0dd414fa23874c4733eeff7a5294fe02578247 100644 (file)
@@ -4,7 +4,7 @@
 // of the file.
 
 // CHECK:        Section {
-// CHECK:          Index: 1
+// CHECK:          Index: 2
 // CHECK-NEXT:     Name: .group
 // CHECK-NEXT:     Type: SHT_GROUP
 // CHECK-NEXT:     Flags [
 // CHECK-NEXT:     Address: 0x0
 // CHECK-NEXT:     Offset: 0x40
 // CHECK-NEXT:     Size: 12
-// CHECK-NEXT:     Link: 13
+// CHECK-NEXT:     Link:
 // CHECK-NEXT:     Info: 1
 // CHECK-NEXT:     AddressAlignment: 4
 // CHECK-NEXT:     EntrySize: 4
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Section {
-// CHECK-NEXT:     Index: 2
+// CHECK-NEXT:     Index: 3
 // CHECK-NEXT:     Name: .group
 // CHECK-NEXT:     Type: SHT_GROUP
 // CHECK-NEXT:     Flags [
 // CHECK-NEXT:     Address: 0x0
 // CHECK-NEXT:     Offset: 0x4C
 // CHECK-NEXT:     Size: 8
-// CHECK-NEXT:     Link: 13
+// CHECK-NEXT:     Link:
 // CHECK-NEXT:     Info: 2
 // CHECK-NEXT:     AddressAlignment: 4
 // CHECK-NEXT:     EntrySize: 4
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Section {
-// CHECK-NEXT:     Index: 3
+// CHECK-NEXT:     Index: 4
 // CHECK-NEXT:     Name: .group
 // CHECK-NEXT:     Type: SHT_GROUP
 // CHECK-NEXT:     Flags [
@@ -40,7 +40,7 @@
 // CHECK-NEXT:     Address: 0x0
 // CHECK-NEXT:     Offset: 0x54
 // CHECK-NEXT:     Size: 12
-// CHECK-NEXT:     Link: 13
+// CHECK-NEXT:     Link:
 // CHECK-NEXT:     Info: 10
 // CHECK-NEXT:     AddressAlignment: 4
 // CHECK-NEXT:     EntrySize: 4
@@ -55,7 +55,7 @@
 // CHECK-NEXT:     Binding: Local
 // CHECK-NEXT:     Type: None
 // CHECK-NEXT:     Other: 0
-// CHECK-NEXT:     Section: .foo (0x7)
+// CHECK-NEXT:     Section: .foo
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Symbol {
 // CHECK-NEXT:     Name: g2
@@ -64,7 +64,7 @@
 // CHECK-NEXT:     Binding: Local
 // CHECK-NEXT:     Type: None
 // CHECK-NEXT:     Other: 0
-// CHECK-NEXT:     Section: .group (0x2)
+// CHECK-NEXT:     Section: .group (0x3)
 // CHECK-NEXT:   }
 
 // CHECK:        Symbol {
index c421fe844882f18aa1b367ca63b4f82ce452febf..d6a852ce15ad179b15f5e05e8f73eb682218a1e8 100644 (file)
@@ -1,8 +1,21 @@
 // RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | llvm-readobj -s | FileCheck %s
 
 // Test that like gnu as we create text, data and bss by default. Also test
-// that shstrtab, symtab and strtab are listed in that order.
+// that shstrtab, symtab and strtab are listed.
 
+// CHECK:        Section {
+// CHECK:          Name: .shstrtab
+// CHECK-NEXT:     Type: SHT_STRTAB
+// CHECK-NEXT:     Flags [
+// CHECK-NEXT:     ]
+// CHECK-NEXT:     Address: 0x0
+// CHECK-NEXT:     Offset:
+// CHECK-NEXT:     Size: 44
+// CHECK-NEXT:     Link: 0
+// CHECK-NEXT:     Info: 0
+// CHECK-NEXT:     AddressAlignment: 1
+// CHECK-NEXT:     EntrySize: 0
+// CHECK-NEXT:   }
 // CHECK:        Section {
 // CHECK:          Name: .text
 // CHECK-NEXT:     Type: SHT_PROGBITS
 // CHECK-NEXT:     EntrySize: 0
 // CHECK-NEXT:   }
 // CHECK:        Section {
-// CHECK:          Name: .shstrtab
-// CHECK-NEXT:     Type: SHT_STRTAB
-// CHECK-NEXT:     Flags [
-// CHECK-NEXT:     ]
-// CHECK-NEXT:     Address: 0x0
-// CHECK-NEXT:     Offset: 0x40
-// CHECK-NEXT:     Size: 44
-// CHECK-NEXT:     Link: 0
-// CHECK-NEXT:     Info: 0
-// CHECK-NEXT:     AddressAlignment: 1
-// CHECK-NEXT:     EntrySize: 0
-// CHECK-NEXT:   }
-// CHECK:        Section {
 // CHECK:          Name: .symtab
 // CHECK-NEXT:     Type: SHT_SYMTAB
 // CHECK-NEXT:     Flags [
@@ -69,7 +69,7 @@
 // CHECK-NEXT:     Address: 0x0
 // CHECK-NEXT:     Offset:
 // CHECK-NEXT:     Size: 96
-// CHECK-NEXT:     Link: 6
+// CHECK-NEXT:     Link:
 // CHECK-NEXT:     Info: 4
 // CHECK-NEXT:     AddressAlignment: 8
 // CHECK-NEXT:     EntrySize: 24
index 88a4822c3869780cc9656374d23710be3b079b41..b52c01af49050a7ee5459af63fd88b21b7651f5b 100644 (file)
@@ -18,7 +18,7 @@
 // SYMBOLS-NEXT:    Binding: Local (0x0)
 // SYMBOLS-NEXT:    Type: None (0x0)
 // SYMBOLS-NEXT:    Other: 0
-// SYMBOLS-NEXT:    Section: last (0xFF00)
+// SYMBOLS-NEXT:    Section: dm (0xFF00)
 // SYMBOLS-NEXT:  }
 // SYMBOLS-NEXT:  Symbol {
 // SYMBOLS-NEXT:    Name: b
 // SYMBOLS-NEXT:    Binding: Local (0x0)
 // SYMBOLS-NEXT:    Type: None (0x0)
 // SYMBOLS-NEXT:    Other: 0
-// SYMBOLS-NEXT:    Section: last (0xFF00)
+// SYMBOLS-NEXT:    Section: dm (0xFF00)
 // SYMBOLS-NEXT:  }
 
 
 // Test that this file has one section too many.
-// SYMBOLS:         Name: last
+// SYMBOLS:         Name: dm
 // SYMBOLS-NEXT:    Value: 0x0
 // SYMBOLS-NEXT:    Size: 0
 // SYMBOLS-NEXT:    Binding: Local (0x0)
 // SYMBOLS-NEXT:    Type: Section (0x3)
 // SYMBOLS-NEXT:    Other: 0
-// SYMBOLS-NEXT:    Section: last (0xFF00)
+// SYMBOLS-NEXT:    Section: dm (0xFF00)
 // SYMBOLS-NEXT:  }
 // SYMBOLS-NEXT:]
 
@@ -128,6 +128,5 @@ gen_sections16 k
 gen_sections8 l
 gen_sections4 m
 
-.section last
 a:
 b = a + 1
index 93ea8e7821e231206c9e5a59562ede991fe5f544..dbba8711fdf6761ae4091e14cdcfd4847d3304f0 100644 (file)
@@ -9,13 +9,13 @@
 
 // Check the last referenced section.
 
-// SYMBOLS:         Name: dm (0)
+// SYMBOLS:         Name: zed
 // SYMBOLS-NEXT:    Value: 0x0
 // SYMBOLS-NEXT:    Size: 0
 // SYMBOLS-NEXT:    Binding: Local (0x0)
 // SYMBOLS-NEXT:    Type: Section (0x3)
 // SYMBOLS-NEXT:    Other: 0
-// SYMBOLS-NEXT:    Section: dm (0xFEFF)
+// SYMBOLS-NEXT:    Section: zed (0xFEFF)
 // SYMBOLS-NEXT:  }
 // SYMBOLS-NEXT:]
 
@@ -103,4 +103,6 @@ gen_sections64 i
 gen_sections32 j
 gen_sections16 k
 gen_sections8 l
-gen_sections4 m
+        .section foo
+        .section bar
+        .section zed
index 3b76d813fe7c8d1724934fad23344656ab08f610..4b265961740cb299bc4a1517764fa1c1af092f51 100644 (file)
@@ -7,9 +7,9 @@
 
 // Test that the relocation points to the first section foo.
 
-// The first seciton foo has index 6
+// The first seciton foo has index 7
 // CHECK:      Section {
-// CHECK:        Index:   6
+// CHECK:        Index:   7
 // CHECK-NEXT:   Name:    foo (28)
 // CHECK-NEXT:   Type:    SHT_PROGBITS (0x1)
 // CHECK-NEXT:   Flags [ (0x202)
@@ -25,7 +25,7 @@
 // CHECK-NEXT:   EntrySize:       0
 // CHECK-NEXT: }
 // CHECK-NEXT: Section {
-// CHECK-NEXT:   Index:   7
+// CHECK-NEXT:   Index:   8
 // CHECK-NEXT:   Name:    foo (28)
 // CHECK-NEXT:   Type:    SHT_PROGBITS (0x1)
 // CHECK-NEXT:   Flags [ (0x200)
@@ -42,7 +42,7 @@
 
 // The relocation points to symbol 6
 // CHECK:      Relocations [
-// CHECK-NEXT:   Section (9) .relabar {
+// CHECK-NEXT:   Section ({{.*}}) .relabar {
 // CHECK-NEXT:     Relocation {
 // CHECK-NEXT:       Offset:  0x0
 // CHECK-NEXT:       Type:    R_X86_64_32 (10)
@@ -83,9 +83,9 @@
 // symbol 6
 // CHECK-NOT: Name
 // CHECK: Name:    foo
-// CHECK: Section: foo (0x6)
+// CHECK: Section: foo (0x7)
 
 // symbol 7
 // CHECK-NOT: Name
 // CHECK: Name:    foo
-// CHECK: Section: foo (0x7)
+// CHECK: Section: foo (0x8)
index 3fe727127afd228a4226c93aded081e96c176a49..bd15148f6d83283da3eb62ec84c059313e3ff9e7 100644 (file)
@@ -26,7 +26,7 @@ g:
 // OBJ:   Binding: Global
 // OBJ:   Type:    None
 // OBJ:   Other:   0
-// OBJ:   Section: .text (0x4)
+// OBJ:   Section: .text (0x5)
 // OBJ: }
 // OBJ: Symbol {
 // OBJ:   Name:    g
@@ -35,5 +35,5 @@ g:
 // OBJ:   Binding: Global
 // OBJ:   Type:    None
 // OBJ:   Other:   0
-// OBJ:   Section: .text (0x5)
+// OBJ:   Section: .text (0x6)
 // OBJ: }