[PATCH] D13275: [lld][elf2] Sort output sections.

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 07:49:57 PDT 2015


> Because we'd do layout wrong otherwise. If you have ALLOC, ALLOC
> NOBITS, ALLOC, then you get VA space allocated for the NOBITS section,
> but no file space. Then when we create the PT_LOAD it just sets filesz
> and memsz assuming the NOBITS sections come after the non-NOBITS
> sections, so the 3rd section gets loaded at the wrong VA.

Not sure I follow your explanation, the values would still list how
much disk and memory space are needed.

Looking at the musl dynamic linker and reading the spec I found out
why nobits has to be at the end: The dynamic linker only indication
there there is a NOBITS somewhere is the file size and the memory size
being different. All it can do is assume they are at the end of the
segment and zero out that part.

Given that we need that check, the function was looking a bit funny.
Part of it used the "rank" and part a more traditional compare.

I have split the rank into multiple early exits. I find this a bit
easier to read. It is particularly convenient for putting comments
explaining not what order we are sorting the sections into (C++ is
good for that), but *why* that order. What do you think?

> Also, why did you remove the section-layout test?

Just forgot to git add.

Cheers,
Rafael
-------------- next part --------------
diff --git a/ELF/OutputSections.cpp b/ELF/OutputSections.cpp
index 17bd9a6..13f599f 100644
--- a/ELF/OutputSections.cpp
+++ b/ELF/OutputSections.cpp
@@ -183,6 +183,9 @@ DynamicSection<ELFT>::DynamicSection(SymbolTable &SymTab,
 }
 
 template <class ELFT> void DynamicSection<ELFT>::finalize() {
+  if (this->Header.sh_size)
+    return; // Already finalized.
+
   typename Base::HeaderT &Header = this->Header;
   Header.sh_link = DynStrSec.getSectionIndex();
 
diff --git a/ELF/Writer.cpp b/ELF/Writer.cpp
index 3625934..dbb9baf 100644
--- a/ELF/Writer.cpp
+++ b/ELF/Writer.cpp
@@ -368,7 +368,6 @@ template <class ELFT> void Writer<ELFT>::createSections() {
   BssSec.setSize(Off);
 
   OutputSections.push_back(&SymTabSec);
-  OutputSections.push_back(&StrTabSec);
 
   if (needsDynamicSections()) {
     if (needsInterpSection())
@@ -389,12 +388,53 @@ template <class ELFT> void Writer<ELFT>::createSections() {
       OutputSections.begin(), OutputSections.end(),
       [](OutputSectionBase<ELFT::Is64Bits> *A,
          OutputSectionBase<ELFT::Is64Bits> *B) {
-        // Place SHF_ALLOC sections first.
-        return (A->getFlags() & SHF_ALLOC) && !(B->getFlags() & SHF_ALLOC);
+        uintX_t AFlags = A->getFlags();
+        uintX_t BFlags = B->getFlags();
+
+        // Allocatable sections go first to reduce the total PT_LOAD size and
+        // so debug info doesn't change addresses in actual code.
+        bool AIsAlloc = AFlags & SHF_ALLOC;
+        bool BIsAlloc = BFlags & SHF_ALLOC;
+        if (AIsAlloc != BIsAlloc)
+          return AIsAlloc;
+
+        // We don't have any special requirements for the relative order of
+        // two non allocatable sections.
+        if (!AIsAlloc)
+          return false;
+
+        // We want the read only sections first so that they go in the PT_LOAD
+        // covering the program headers at the start of the file.
+        bool AIsWritable = AFlags & SHF_WRITE;
+        bool BIsWritable = BFlags & SHF_WRITE;
+        if (AIsWritable != BIsWritable)
+          return BIsWritable;
+
+        // For a corresponding reason, put non exec sections first (the program
+        // header PT_LOAD is not executable).
+        bool AIsExec = AFlags & SHF_EXECINSTR;
+        bool BIsExec = BFlags & SHF_EXECINSTR;
+        if (AIsExec != BIsExec)
+          return BIsExec;
+
+        // If we got here we know that both A and B and in the same PT_LOAD.
+        // The last requirement we have is to put nobits section last. The
+        // reason is that the only thing the dynamic linker will see about
+        // them is a p_memsz that is larger than p_filesz. Seeing that it
+        // zeros the end of the PT_LOAD, so that has to correspond to the
+        // nobits sections.
+        return A->getType() != SHT_NOBITS && B->getType() == SHT_NOBITS;
       });
 
+  // Always put StrTabSec last so that no section names are added to it after
+  // it's finalized.
+  OutputSections.push_back(&StrTabSec);
+
   for (unsigned I = 0, N = OutputSections.size(); I < N; ++I)
     OutputSections[I]->setSectionIndex(I + 1);
+
+  // Fill the DynStrSec early.
+  DynamicSec.finalize();
 }
 
 template <class ELFT>
diff --git a/test/elf2/basic-aarch64.s b/test/elf2/basic-aarch64.s
index 9eb2b5b..64e4336 100644
--- a/test/elf2/basic-aarch64.s
+++ b/test/elf2/basic-aarch64.s
@@ -53,15 +53,15 @@ _start:
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
 # CHECK-NEXT:     Index: 1
-# CHECK-NEXT:     Name: .bss
-# CHECK-NEXT:     Type: SHT_NOBITS (0x8)
-# CHECK-NEXT:     Flags [ (0x3)
+# CHECK-NEXT:     Name: .text
+# CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
+# CHECK-NEXT:     Flags [ (0x6)
 # CHECK-NEXT:       SHF_ALLOC (0x2)
-# CHECK-NEXT:       SHF_WRITE (0x1)
+# CHECK-NEXT:       SHF_EXECINSTR (0x4)
 # CHECK-NEXT:     ]
 # CHECK-NEXT:     Address: 0x11000
 # CHECK-NEXT:     Offset: 0x1000
-# CHECK-NEXT:     Size: 0
+# CHECK-NEXT:     Size: 12
 # CHECK-NEXT:     Link: 0
 # CHECK-NEXT:     Info: 0
 # CHECK-NEXT:     AddressAlignment: 4
@@ -69,15 +69,15 @@ _start:
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
 # CHECK-NEXT:     Index: 2
-# CHECK-NEXT:     Name: .text
+# CHECK-NEXT:     Name: .data
 # CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
-# CHECK-NEXT:     Flags [ (0x6)
+# CHECK-NEXT:     Flags [ (0x3)
 # CHECK-NEXT:       SHF_ALLOC (0x2)
-# CHECK-NEXT:       SHF_EXECINSTR (0x4)
+# CHECK-NEXT:       SHF_WRITE (0x1)
 # CHECK-NEXT:     ]
-# CHECK-NEXT:     Address: 0x11000
-# CHECK-NEXT:     Offset: 0x1000
-# CHECK-NEXT:     Size: 12
+# CHECK-NEXT:     Address: 0x1100C
+# CHECK-NEXT:     Offset: 0x100C
+# CHECK-NEXT:     Size: 0
 # CHECK-NEXT:     Link: 0
 # CHECK-NEXT:     Info: 0
 # CHECK-NEXT:     AddressAlignment: 4
@@ -85,8 +85,8 @@ _start:
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
 # CHECK-NEXT:     Index: 3
-# CHECK-NEXT:     Name: .data
-# CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
+# CHECK-NEXT:     Name: .bss
+# CHECK-NEXT:     Type: SHT_NOBITS (0x8)
 # CHECK-NEXT:     Flags [ (0x3)
 # CHECK-NEXT:       SHF_ALLOC (0x2)
 # CHECK-NEXT:       SHF_WRITE (0x1)
@@ -145,7 +145,7 @@ _start:
 # CHECK-NEXT:     Binding: Local (0x0)
 # CHECK-NEXT:     Type: None (0x0)
 # CHECK-NEXT:     Other: 0
-# CHECK-NEXT:     Section: .text (0x2)
+# CHECK-NEXT:     Section: .text
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Symbol {
 # CHECK-NEXT:     Name: _start (7)
diff --git a/test/elf2/basic-mips.s b/test/elf2/basic-mips.s
index 15a5b7c..2e067ac 100644
--- a/test/elf2/basic-mips.s
+++ b/test/elf2/basic-mips.s
@@ -25,14 +25,14 @@ __start:
 # CHECK-NEXT:   Type: Executable (0x2)
 # CHECK-NEXT:   Machine: EM_MIPS (0x8)
 # CHECK-NEXT:   Version: 1
-# CHECK-NEXT:   Entry: 0x11000
+# CHECK-NEXT:   Entry: 0x12000
 # CHECK-NEXT:   ProgramHeaderOffset: 0x34
-# CHECK-NEXT:   SectionHeaderOffset: 0x2094
+# CHECK-NEXT:   SectionHeaderOffset: 0x2074
 # CHECK-NEXT:   Flags [ (0x0)
 # CHECK-NEXT:   ]
 # CHECK-NEXT:   HeaderSize: 52
 # CHECK-NEXT:   ProgramHeaderEntrySize: 32
-# CHECK-NEXT:   ProgramHeaderCount: 3
+# CHECK-NEXT:   ProgramHeaderCount: 2
 # CHECK-NEXT:   SectionHeaderEntrySize: 40
 # CHECK-NEXT:   SectionHeaderCount: 8
 # CHECK-NEXT:   StringTableSectionIndex: 7
@@ -54,30 +54,44 @@ __start:
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
 # CHECK-NEXT:     Index: 1
-# CHECK-NEXT:     Name: .bss (15)
-# CHECK-NEXT:     Type: SHT_NOBITS (0x8)
-# CHECK-NEXT:     Flags [ (0x3)
+# CHECK-NEXT:     Name: .reginfo (35)
+# CHECK-NEXT:     Type: SHT_MIPS_REGINFO (0x70000006)
+# CHECK-NEXT:     Flags [ (0x2)
 # CHECK-NEXT:       SHF_ALLOC (0x2)
-# CHECK-NEXT:       SHF_WRITE (0x1)
 # CHECK-NEXT:     ]
 # CHECK-NEXT:     Address: 0x11000
 # CHECK-NEXT:     Offset: 0x1000
-# CHECK-NEXT:     Size: 0
+# CHECK-NEXT:     Size: 24
 # CHECK-NEXT:     Link: 0
 # CHECK-NEXT:     Info: 0
-# CHECK-NEXT:     AddressAlignment: 16
+# CHECK-NEXT:     AddressAlignment: 4
 # CHECK-NEXT:     EntrySize: 0
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
 # CHECK-NEXT:     Index: 2
+# CHECK-NEXT:     Name: .MIPS.abiflags (20)
+# CHECK-NEXT:     Type: SHT_MIPS_ABIFLAGS (0x7000002A)
+# CHECK-NEXT:     Flags [ (0x2)
+# CHECK-NEXT:       SHF_ALLOC (0x2)
+# CHECK-NEXT:     ]
+# CHECK-NEXT:     Address: 0x11018
+# CHECK-NEXT:     Offset: 0x1018
+# CHECK-NEXT:     Size: 24
+# CHECK-NEXT:     Link: 0
+# CHECK-NEXT:     Info: 0
+# CHECK-NEXT:     AddressAlignment: 8
+# CHECK-NEXT:     EntrySize: 0
+# CHECK-NEXT:   }
+# CHECK-NEXT:   Section {
+# CHECK-NEXT:     Index: 3
 # CHECK-NEXT:     Name: .text (1)
 # CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
 # CHECK-NEXT:     Flags [ (0x6)
 # CHECK-NEXT:       SHF_ALLOC (0x2)
 # CHECK-NEXT:       SHF_EXECINSTR (0x4)
 # CHECK-NEXT:     ]
-# CHECK-NEXT:     Address: 0x11000
-# CHECK-NEXT:     Offset: 0x1000
+# CHECK-NEXT:     Address: 0x12000
+# CHECK-NEXT:     Offset: 0x2000
 # CHECK-NEXT:     Size: 12
 # CHECK-NEXT:     Link: 0
 # CHECK-NEXT:     Info: 0
@@ -85,15 +99,15 @@ __start:
 # CHECK-NEXT:     EntrySize: 0
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
-# CHECK-NEXT:     Index: 3
+# CHECK-NEXT:     Index: 4
 # CHECK-NEXT:     Name: .data (60)
 # CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
 # CHECK-NEXT:     Flags [ (0x3)
 # CHECK-NEXT:       SHF_ALLOC (0x2)
 # CHECK-NEXT:       SHF_WRITE (0x1)
 # CHECK-NEXT:     ]
-# CHECK-NEXT:     Address: 0x11010
-# CHECK-NEXT:     Offset: 0x1010
+# CHECK-NEXT:     Address: 0x12010
+# CHECK-NEXT:     Offset: 0x2010
 # CHECK-NEXT:     Size: 0
 # CHECK-NEXT:     Link: 0
 # CHECK-NEXT:     Info: 0
@@ -101,33 +115,19 @@ __start:
 # CHECK-NEXT:     EntrySize: 0
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
-# CHECK-NEXT:     Index: 4
-# CHECK-NEXT:     Name: .reginfo (35)
-# CHECK-NEXT:     Type: SHT_MIPS_REGINFO (0x70000006)
-# CHECK-NEXT:     Flags [ (0x2)
-# CHECK-NEXT:       SHF_ALLOC (0x2)
-# CHECK-NEXT:     ]
-# CHECK-NEXT:     Address: 0x12000
-# CHECK-NEXT:     Offset: 0x2000
-# CHECK-NEXT:     Size: 24
-# CHECK-NEXT:     Link: 0
-# CHECK-NEXT:     Info: 0
-# CHECK-NEXT:     AddressAlignment: 4
-# CHECK-NEXT:     EntrySize: 0
-# CHECK-NEXT:   }
-# CHECK-NEXT:   Section {
 # CHECK-NEXT:     Index: 5
-# CHECK-NEXT:     Name: .MIPS.abiflags (20)
-# CHECK-NEXT:     Type: SHT_MIPS_ABIFLAGS (0x7000002A)
-# CHECK-NEXT:     Flags [ (0x2)
+# CHECK-NEXT:     Name: .bss (15)
+# CHECK-NEXT:     Type: SHT_NOBITS (0x8)
+# CHECK-NEXT:     Flags [ (0x3)
 # CHECK-NEXT:       SHF_ALLOC (0x2)
+# CHECK-NEXT:       SHF_WRITE (0x1)
 # CHECK-NEXT:     ]
-# CHECK-NEXT:     Address: 0x12018
-# CHECK-NEXT:     Offset: 0x2018
-# CHECK-NEXT:     Size: 24
+# CHECK-NEXT:     Address: 0x12010
+# CHECK-NEXT:     Offset: 0x2010
+# CHECK-NEXT:     Size: 0
 # CHECK-NEXT:     Link: 0
 # CHECK-NEXT:     Info: 0
-# CHECK-NEXT:     AddressAlignment: 8
+# CHECK-NEXT:     AddressAlignment: 16
 # CHECK-NEXT:     EntrySize: 0
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
@@ -137,7 +137,7 @@ __start:
 # CHECK-NEXT:     Flags [ (0x0)
 # CHECK-NEXT:     ]
 # CHECK-NEXT:     Address: 0x0
-# CHECK-NEXT:     Offset: 0x2030
+# CHECK-NEXT:     Offset: 0x2010
 # CHECK-NEXT:     Size: 32
 # CHECK-NEXT:     Link: 7
 # CHECK-NEXT:     Info: 1
@@ -151,7 +151,7 @@ __start:
 # CHECK-NEXT:     Flags [ (0x0)
 # CHECK-NEXT:     ]
 # CHECK-NEXT:     Address: 0x0
-# CHECK-NEXT:     Offset: 0x2050
+# CHECK-NEXT:     Offset: 0x2030
 # CHECK-NEXT:     Size: 66
 # CHECK-NEXT:     Link: 0
 # CHECK-NEXT:     Info: 0
@@ -171,12 +171,12 @@ __start:
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Symbol {
 # CHECK-NEXT:     Name: __start (7)
-# CHECK-NEXT:     Value: 0x11000
+# CHECK-NEXT:     Value: 0x12000
 # CHECK-NEXT:     Size: 0
 # CHECK-NEXT:     Binding: Global (0x1)
 # CHECK-NEXT:     Type: None (0x0)
 # CHECK-NEXT:     Other: 0
-# CHECK-NEXT:     Section: .text (0x2)
+# CHECK-NEXT:     Section: .text
 # CHECK-NEXT:   }
 # CHECK-NEXT: ]
 # CHECK-NEXT: ProgramHeaders [
@@ -185,8 +185,8 @@ __start:
 # CHECK-NEXT:     Offset: 0x0
 # CHECK-NEXT:     VirtualAddress: 0x10000
 # CHECK-NEXT:     PhysicalAddress: 0x10000
-# CHECK-NEXT:     FileSize: 148
-# CHECK-NEXT:     MemSize: 148
+# CHECK-NEXT:     FileSize: 4144
+# CHECK-NEXT:     MemSize: 4144
 # CHECK-NEXT:     Flags [ (0x4)
 # CHECK-NEXT:       PF_R (0x4)
 # CHECK-NEXT:     ]
@@ -194,9 +194,9 @@ __start:
 # CHECK-NEXT:   }
 # CHECK-NEXT:   ProgramHeader {
 # CHECK-NEXT:     Type: PT_LOAD (0x1)
-# CHECK-NEXT:     Offset: 0x1000
-# CHECK-NEXT:     VirtualAddress: 0x11000
-# CHECK-NEXT:     PhysicalAddress: 0x11000
+# CHECK-NEXT:     Offset: 0x2000
+# CHECK-NEXT:     VirtualAddress: 0x12000
+# CHECK-NEXT:     PhysicalAddress: 0x12000
 # CHECK-NEXT:     FileSize: 16
 # CHECK-NEXT:     MemSize: 16
 # CHECK-NEXT:     Flags [ (0x5)
@@ -205,16 +205,4 @@ __start:
 # CHECK-NEXT:     ]
 # CHECK-NEXT:     Alignment: 4096
 # CHECK-NEXT:   }
-# CHECK-NEXT:   ProgramHeader {
-# CHECK-NEXT:     Type: PT_LOAD (0x1)
-# CHECK-NEXT:     Offset: 0x2000
-# CHECK-NEXT:     VirtualAddress: 0x12000
-# CHECK-NEXT:     PhysicalAddress: 0x12000
-# CHECK-NEXT:     FileSize: 48
-# CHECK-NEXT:     MemSize: 48
-# CHECK-NEXT:     Flags [ (0x4)
-# CHECK-NEXT:       PF_R (0x4)
-# CHECK-NEXT:     ]
-# CHECK-NEXT:     Alignment: 4096
-# CHECK-NEXT:   }
 # CHECK-NEXT: ]
diff --git a/test/elf2/basic.s b/test/elf2/basic.s
index 1504251..dca96f8 100644
--- a/test/elf2/basic.s
+++ b/test/elf2/basic.s
@@ -54,15 +54,15 @@ _start:
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
 # CHECK-NEXT:     Index: 1
-# CHECK-NEXT:     Name: .bss
-# CHECK-NEXT:     Type: SHT_NOBITS (0x8)
-# CHECK-NEXT:     Flags [ (0x3)
+# CHECK-NEXT:     Name: .text
+# CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
+# CHECK-NEXT:     Flags [ (0x6)
 # CHECK-NEXT:       SHF_ALLOC (0x2)
-# CHECK-NEXT:       SHF_WRITE (0x1)
+# CHECK-NEXT:       SHF_EXECINSTR (0x4)
 # CHECK-NEXT:     ]
 # CHECK-NEXT:     Address: 0x11000
 # CHECK-NEXT:     Offset: 0x1000
-# CHECK-NEXT:     Size: 0
+# CHECK-NEXT:     Size: 16
 # CHECK-NEXT:     Link: 0
 # CHECK-NEXT:     Info: 0
 # CHECK-NEXT:     AddressAlignment: 4
@@ -70,15 +70,15 @@ _start:
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
 # CHECK-NEXT:     Index: 2
-# CHECK-NEXT:     Name: .text
+# CHECK-NEXT:     Name: .data
 # CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
-# CHECK-NEXT:     Flags [ (0x6)
+# CHECK-NEXT:     Flags [ (0x3)
 # CHECK-NEXT:       SHF_ALLOC (0x2)
-# CHECK-NEXT:       SHF_EXECINSTR (0x4)
+# CHECK-NEXT:       SHF_WRITE (0x1)
 # CHECK-NEXT:     ]
-# CHECK-NEXT:     Address: 0x11000
-# CHECK-NEXT:     Offset: 0x1000
-# CHECK-NEXT:     Size: 16
+# CHECK-NEXT:     Address: 0x11010
+# CHECK-NEXT:     Offset: 0x1010
+# CHECK-NEXT:     Size: 0
 # CHECK-NEXT:     Link: 0
 # CHECK-NEXT:     Info: 0
 # CHECK-NEXT:     AddressAlignment: 4
@@ -86,8 +86,8 @@ _start:
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
 # CHECK-NEXT:     Index: 3
-# CHECK-NEXT:     Name: .data
-# CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
+# CHECK-NEXT:     Name: .bss
+# CHECK-NEXT:     Type: SHT_NOBITS (0x8)
 # CHECK-NEXT:     Flags [ (0x3)
 # CHECK-NEXT:       SHF_ALLOC (0x2)
 # CHECK-NEXT:       SHF_WRITE (0x1)
diff --git a/test/elf2/basic32.s b/test/elf2/basic32.s
index edafbe4..bad5750 100644
--- a/test/elf2/basic32.s
+++ b/test/elf2/basic32.s
@@ -52,15 +52,15 @@ _start:
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
 # CHECK-NEXT:     Index: 1
-# CHECK-NEXT:     Name: .bss
-# CHECK-NEXT:     Type: SHT_NOBITS (0x8)
-# CHECK-NEXT:     Flags [ (0x3)
+# CHECK-NEXT:     Name: .text
+# CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
+# CHECK-NEXT:     Flags [ (0x6)
 # CHECK-NEXT:       SHF_ALLOC (0x2)
-# CHECK-NEXT:       SHF_WRITE (0x1)
+# CHECK-NEXT:       SHF_EXECINSTR (0x4)
 # CHECK-NEXT:     ]
 # CHECK-NEXT:     Address: 0x11000
 # CHECK-NEXT:     Offset: 0x1000
-# CHECK-NEXT:     Size: 0
+# CHECK-NEXT:     Size: 12
 # CHECK-NEXT:     Link: 0
 # CHECK-NEXT:     Info: 0
 # CHECK-NEXT:     AddressAlignment: 4
@@ -68,15 +68,15 @@ _start:
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
 # CHECK-NEXT:     Index: 2
-# CHECK-NEXT:     Name: .text
+# CHECK-NEXT:     Name: .data
 # CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
-# CHECK-NEXT:     Flags [ (0x6)
+# CHECK-NEXT:     Flags [ (0x3)
 # CHECK-NEXT:       SHF_ALLOC (0x2)
-# CHECK-NEXT:       SHF_EXECINSTR (0x4)
+# CHECK-NEXT:       SHF_WRITE (0x1)
 # CHECK-NEXT:     ]
-# CHECK-NEXT:     Address: 0x11000
-# CHECK-NEXT:     Offset: 0x1000
-# CHECK-NEXT:     Size: 12
+# CHECK-NEXT:     Address: 0x1100C
+# CHECK-NEXT:     Offset: 0x100C
+# CHECK-NEXT:     Size: 0
 # CHECK-NEXT:     Link: 0
 # CHECK-NEXT:     Info: 0
 # CHECK-NEXT:     AddressAlignment: 4
@@ -84,8 +84,8 @@ _start:
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
 # CHECK-NEXT:     Index: 3
-# CHECK-NEXT:     Name: .data
-# CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
+# CHECK-NEXT:     Name: .bss
+# CHECK-NEXT:     Type: SHT_NOBITS (0x8)
 # CHECK-NEXT:     Flags [ (0x3)
 # CHECK-NEXT:       SHF_ALLOC (0x2)
 # CHECK-NEXT:       SHF_WRITE (0x1)
diff --git a/test/elf2/basic32be.s b/test/elf2/basic32be.s
index 1f5e46a..5d1cfee 100644
--- a/test/elf2/basic32be.s
+++ b/test/elf2/basic32be.s
@@ -52,15 +52,15 @@ _start:
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
 # CHECK-NEXT:     Index: 1
-# CHECK-NEXT:     Name: .bss
-# CHECK-NEXT:     Type: SHT_NOBITS (0x8)
-# CHECK-NEXT:     Flags [ (0x3)
+# CHECK-NEXT:     Name: .text
+# CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
+# CHECK-NEXT:     Flags [ (0x6)
 # CHECK-NEXT:       SHF_ALLOC (0x2)
-# CHECK-NEXT:       SHF_WRITE (0x1)
+# CHECK-NEXT:       SHF_EXECINSTR (0x4)
 # CHECK-NEXT:     ]
 # CHECK-NEXT:     Address: 0x11000
 # CHECK-NEXT:     Offset: 0x1000
-# CHECK-NEXT:     Size: 0
+# CHECK-NEXT:     Size: 12
 # CHECK-NEXT:     Link: 0
 # CHECK-NEXT:     Info: 0
 # CHECK-NEXT:     AddressAlignment: 4
@@ -68,15 +68,15 @@ _start:
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
 # CHECK-NEXT:     Index: 2
-# CHECK-NEXT:     Name: .text
+# CHECK-NEXT:     Name: .data
 # CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
-# CHECK-NEXT:     Flags [ (0x6)
+# CHECK-NEXT:     Flags [ (0x3)
 # CHECK-NEXT:       SHF_ALLOC (0x2)
-# CHECK-NEXT:       SHF_EXECINSTR (0x4)
+# CHECK-NEXT:       SHF_WRITE (0x1)
 # CHECK-NEXT:     ]
-# CHECK-NEXT:     Address: 0x11000
-# CHECK-NEXT:     Offset: 0x1000
-# CHECK-NEXT:     Size: 12
+# CHECK-NEXT:     Address: 0x1100C
+# CHECK-NEXT:     Offset: 0x100C
+# CHECK-NEXT:     Size: 0
 # CHECK-NEXT:     Link: 0
 # CHECK-NEXT:     Info: 0
 # CHECK-NEXT:     AddressAlignment: 4
@@ -84,8 +84,8 @@ _start:
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
 # CHECK-NEXT:     Index: 3
-# CHECK-NEXT:     Name: .data
-# CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
+# CHECK-NEXT:     Name: .bss
+# CHECK-NEXT:     Type: SHT_NOBITS (0x8)
 # CHECK-NEXT:     Flags [ (0x3)
 # CHECK-NEXT:       SHF_ALLOC (0x2)
 # CHECK-NEXT:       SHF_WRITE (0x1)
diff --git a/test/elf2/basic64be.s b/test/elf2/basic64be.s
index 842312a..01b85f6 100644
--- a/test/elf2/basic64be.s
+++ b/test/elf2/basic64be.s
@@ -59,22 +59,6 @@ _start:
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
 # CHECK-NEXT:     Index: 1
-# CHECK-NEXT:     Name: .bss
-# CHECK-NEXT:     Type: SHT_NOBITS (0x8)
-# CHECK-NEXT:     Flags [ (0x3)
-# CHECK-NEXT:       SHF_ALLOC (0x2)
-# CHECK-NEXT:       SHF_WRITE (0x1)
-# CHECK-NEXT:     ]
-# CHECK-NEXT:     Address: 0x11000
-# CHECK-NEXT:     Offset: 0x1000
-# CHECK-NEXT:     Size: 0
-# CHECK-NEXT:     Link: 0
-# CHECK-NEXT:     Info: 0
-# CHECK-NEXT:     AddressAlignment: 4
-# CHECK-NEXT:     EntrySize: 0
-# CHECK-NEXT:   }
-# CHECK-NEXT:   Section {
-# CHECK-NEXT:     Index: 2
 # CHECK-NEXT:     Name: .text
 # CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
 # CHECK-NEXT:     Flags [ (0x6)
@@ -92,7 +76,7 @@ _start:
 # CHECK:          )
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
-# CHECK-NEXT:     Index: 3
+# CHECK-NEXT:     Index: 2
 # CHECK-NEXT:     Name: .data
 # CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
 # CHECK-NEXT:     Flags [ (0x3)
@@ -110,7 +94,7 @@ _start:
 # CHECK:          )
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
-# CHECK-NEXT:     Index: 4
+# CHECK-NEXT:     Index: 3
 # CHECK-NEXT:     Name: .opd
 # CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
 # CHECK-NEXT:     Flags [ (0x3)
@@ -130,6 +114,22 @@ _start:
 # CHECK-NEXT:     )
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Section {
+# CHECK-NEXT:     Index: 4
+# CHECK-NEXT:     Name: .bss
+# CHECK-NEXT:     Type: SHT_NOBITS (0x8)
+# CHECK-NEXT:     Flags [ (0x3)
+# CHECK-NEXT:       SHF_ALLOC (0x2)
+# CHECK-NEXT:       SHF_WRITE (0x1)
+# CHECK-NEXT:     ]
+# CHECK-NEXT:     Address: 0x12018
+# CHECK-NEXT:     Offset: 0x2018
+# CHECK-NEXT:     Size: 0
+# CHECK-NEXT:     Link: 0
+# CHECK-NEXT:     Info: 0
+# CHECK-NEXT:     AddressAlignment: 4
+# CHECK-NEXT:     EntrySize: 0
+# CHECK-NEXT:   }
+# CHECK-NEXT:   Section {
 # CHECK-NEXT:     Index: 5
 # CHECK-NEXT:     Name: .symtab
 # CHECK-NEXT:     Type: SHT_SYMTAB
diff --git a/test/elf2/bss.s b/test/elf2/bss.s
index e8ca6be..0fa8fe4 100644
--- a/test/elf2/bss.s
+++ b/test/elf2/bss.s
@@ -19,17 +19,6 @@
 // CHECK-NEXT:   AddressAlignment: 4
 // CHECK-NEXT:   EntrySize: 0
 // CHECK-NEXT: }
-// CHECK-NEXT: Section {
-// CHECK-NEXT:   Index:
-// CHECK-NEXT:   Name:
-// CHECK-NEXT:   Type:
-// CHECK-NEXT:   Flags [
-// CHECK-NEXT:     SHF_ALLOC
-// CHECK-NEXT:     SHF_EXECINSTR
-// CHECK-NEXT:   ]
-// CHECK-NEXT:   Address:
-// CHECK-NEXT:   Offset: 0x1000
-
 
         .global _start
 _start:
diff --git a/test/elf2/discard-none.s b/test/elf2/discard-none.s
index 2c3d798..7700534 100644
--- a/test/elf2/discard-none.s
+++ b/test/elf2/discard-none.s
@@ -40,7 +40,7 @@
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Symbol {
 // CHECK-NEXT:     Name: .Lmyothervar
-// CHECK-NEXT:     Value: 0x1000
+// CHECK-NEXT:     Value: 0x102C
 // CHECK-NEXT:     Size: 0
 // CHECK-NEXT:     Binding: Local
 // CHECK-NEXT:     Type: None
@@ -49,7 +49,7 @@
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Symbol {
 // CHECK-NEXT:     Name: .Lmyvar
-// CHECK-NEXT:     Value: 0x1000
+// CHECK-NEXT:     Value: 0x102C
 // CHECK-NEXT:     Size: 0
 // CHECK-NEXT:     Binding: Local
 // CHECK-NEXT:     Type: None
diff --git a/test/elf2/dynamic-reloc-index.s b/test/elf2/dynamic-reloc-index.s
index 294595b..da4df34 100644
--- a/test/elf2/dynamic-reloc-index.s
+++ b/test/elf2/dynamic-reloc-index.s
@@ -8,7 +8,7 @@
 
 // CHECK:      Relocations [
 // CHECK-NEXT:   Section ({{.*}}) .rela.dyn {
-// CHECK-NEXT:     0x11000 R_X86_64_64 bar 0x0
+// CHECK-NEXT:     0x12000 R_X86_64_64 bar 0x0
 // CHECK-NEXT:   }
 // CHECK-NEXT: ]
 
diff --git a/test/elf2/dynamic-reloc.s b/test/elf2/dynamic-reloc.s
index 5a4b551..75cfde9 100644
--- a/test/elf2/dynamic-reloc.s
+++ b/test/elf2/dynamic-reloc.s
@@ -6,15 +6,7 @@
 // RUN: llvm-readobj -dynamic-table -r --expand-relocs -s %t | FileCheck %s
 // REQUIRES: x86
 
-// CHECK:      Name: .text
-// CHECK-NEXT: Type: SHT_PROGBITS
-// CHECK-NEXT: Flags [
-// CHECK-NEXT:   SHF_ALLOC
-// CHECK-NEXT:   SHF_EXECINSTR
-// CHECK-NEXT: ]
-// CHECK-NEXT: Address: [[ADDR:.*]]
-
-// CHECK:      Index: 4
+// CHECK:      Index: 1
 // CHECK-NEXT: Name: .dynsym
 
 // CHECK:      Name: .rela.dyn
@@ -25,11 +17,19 @@
 // CHECK-NEXT: Address: [[RELAADDR:.*]]
 // CHECK-NEXT: Offset:
 // CHECK-NEXT: Size: [[RELASIZE:.*]]
-// CHECK-NEXT: Link: 4
+// CHECK-NEXT: Link: 1
 // CHECK-NEXT: Info: 0
 // CHECK-NEXT: AddressAlignment: 8
 // CHECK-NEXT: EntrySize: 24
 
+// CHECK:      Name: .text
+// CHECK-NEXT: Type: SHT_PROGBITS
+// CHECK-NEXT: Flags [
+// CHECK-NEXT:   SHF_ALLOC
+// CHECK-NEXT:   SHF_EXECINSTR
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address: [[ADDR:.*]]
+
 // CHECK:      Relocations [
 // CHECK-NEXT:   Section ({{.*}}) .rela.dyn {
 // CHECK-NEXT:     Relocation {
diff --git a/test/elf2/got.s b/test/elf2/got.s
index aaff3a1..3e24891 100644
--- a/test/elf2/got.s
+++ b/test/elf2/got.s
@@ -12,7 +12,7 @@
 // CHECK-NEXT:   SHF_ALLOC
 // CHECK-NEXT:   SHF_WRITE
 // CHECK-NEXT: ]
-// CHECK-NEXT: Address: 0x15000
+// CHECK-NEXT: Address: 0x130A0
 // CHECK-NEXT: Offset:
 // CHECK-NEXT: Size: 16
 // CHECK-NEXT: Link: 0
@@ -21,22 +21,22 @@
 
 // CHECK:      Relocations [
 // CHECK-NEXT:   Section ({{.*}}) .rela.dyn {
-// CHECK-NEXT:     0x15000 R_X86_64_GLOB_DAT bar 0x0
-// CHECK-NEXT:     0x15008 R_X86_64_GLOB_DAT zed 0x0
+// CHECK-NEXT:     0x130A0 R_X86_64_GLOB_DAT bar 0x0
+// CHECK-NEXT:     0x130A8 R_X86_64_GLOB_DAT zed 0x0
 // CHECK-NEXT:   }
 // CHECK-NEXT: ]
 
 
 // Unfortunately FileCheck can't do math, so we have to check for explicit
 // values:
-//  0x15000 - (0x11000 + 2) - 4 = 16378
-//  0x15000 - (0x11006 + 2) - 4 = 16372
-//  0x15008 - (0x1100c + 2) - 4 = 16374
+//  0x130A0 - (0x12000 + 2) - 4 = 4250
+//  0x130A0 - (0x12006 + 2) - 4 = 4244
+//  0x130A8 - (0x1200c + 2) - 4 = 4246
 
 // DISASM:      _start:
-// DISASM-NEXT:   11000:  ff 25 fa 3f 00 00  jmpq  *16378(%rip)
-// DISASM-NEXT:   11006:  ff 25 f4 3f 00 00  jmpq  *16372(%rip)
-// DISASM-NEXT:   1100c:  ff 25 f6 3f 00 00  jmpq  *16374(%rip)
+// DISASM-NEXT:   12000:  {{.*}}  jmpq  *4250(%rip)
+// DISASM-NEXT:   12006:  {{.*}}  jmpq  *4244(%rip)
+// DISASM-NEXT:   1200c:  {{.*}}  jmpq  *4246(%rip)
 
 .global _start
 _start:
diff --git a/test/elf2/local-dynamic.s b/test/elf2/local-dynamic.s
index d95909d..503f3aa 100644
--- a/test/elf2/local-dynamic.s
+++ b/test/elf2/local-dynamic.s
@@ -16,7 +16,7 @@
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Symbol {
 // CHECK-NEXT:     Name: blah
-// CHECK-NEXT:     Value: 0x1000
+// CHECK-NEXT:     Value: 0x1050
 // CHECK-NEXT:     Size: 0
 // CHECK-NEXT:     Binding: Local
 // CHECK-NEXT:     Type: None
@@ -25,7 +25,7 @@
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Symbol {
 // CHECK-NEXT:     Name: foo
-// CHECK-NEXT:     Value: 0x1000
+// CHECK-NEXT:     Value: 0x1050
 // CHECK-NEXT:     Size: 0
 // CHECK-NEXT:     Binding: Local
 // CHECK-NEXT:     Type: None
@@ -34,7 +34,7 @@
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Symbol {
 // CHECK-NEXT:     Name: goo
-// CHECK-NEXT:     Value: 0x1000
+// CHECK-NEXT:     Value: 0x1050
 // CHECK-NEXT:     Size: 0
 // CHECK-NEXT:     Binding: Local
 // CHECK-NEXT:     Type: None
@@ -43,7 +43,7 @@
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Symbol {
 // CHECK-NEXT:     Name: _start
-// CHECK-NEXT:     Value: 0x1000
+// CHECK-NEXT:     Value: 0x1050
 // CHECK-NEXT:     Size: 0
 // CHECK-NEXT:     Binding: Global
 // CHECK-NEXT:     Type: None
@@ -64,7 +64,7 @@
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Symbol {
 // CHECK-NEXT:     Name: _start@
-// CHECK-NEXT:     Value: 0x1000
+// CHECK-NEXT:     Value: 0x1050
 // CHECK-NEXT:     Size: 0
 // CHECK-NEXT:     Binding: Global
 // CHECK-NEXT:     Type: None
diff --git a/test/elf2/plt-i686.s b/test/elf2/plt-i686.s
index 8891f9e..1fa1b60 100644
--- a/test/elf2/plt-i686.s
+++ b/test/elf2/plt-i686.s
@@ -12,7 +12,7 @@
 // CHECK-NEXT:   SHF_ALLOC
 // CHECK-NEXT:   SHF_EXECINSTR
 // CHECK-NEXT: ]
-// CHECK-NEXT: Address: 0x16000
+// CHECK-NEXT: Address: 0x12010
 // CHECK-NEXT: Offset:
 // CHECK-NEXT: Size: 16
 // CHECK-NEXT: Link: 0
@@ -21,34 +21,34 @@
 
 // CHECK:      Relocations [
 // CHECK-NEXT:   Section ({{.*}}) .rel.dyn {
-// CHECK-NEXT:     0x15000 R_386_GLOB_DAT bar 0x0
-// CHECK-NEXT:     0x15004 R_386_GLOB_DAT zed 0x0
+// CHECK-NEXT:     0x13050 R_386_GLOB_DAT bar 0x0
+// CHECK-NEXT:     0x13054 R_386_GLOB_DAT zed 0x0
 // CHECK-NEXT:   }
 // CHECK-NEXT: ]
 
 // Unfortunately FileCheck can't do math, so we have to check for explicit
 // values:
 
-// 0x16000 - (0x11000 + 1) - 4 = 20475
-// 0x16000 - (0x11005 + 1) - 4 = 20470
-// 0x16008 - (0x1100a + 1) - 4 = 20473
+// 0x12010 - (0x12000 + 1) - 4 = 11
+// 0x12010 - (0x12005 + 1) - 4 = 2
+// 0x12018 - (0x1200a + 1) - 4 = 9
 
 // DISASM:      _start:
-// DISASM-NEXT:   11000:  e9 fb 4f 00 00  jmp  20475
-// DISASM-NEXT:   11005:  e9 f6 4f 00 00  jmp  20470
-// DISASM-NEXT:   1100a:  e9 f9 4f 00 00  jmp  20473
+// DISASM-NEXT:   12000:  e9 0b 00 00 00  jmp  11
+// DISASM-NEXT:   12005:  e9 06 00 00 00  jmp  6
+// DISASM-NEXT:   1200a:  e9 09 00 00 00  jmp  9
 
-// 0x15000 = 86016
-// 0x15004 = 86020
+// 0x13050 = 77904
+// 0x13054 = 77908
 
 // DISASM:      Disassembly of section .plt:
 // DISASM-NEXT: .plt:
-// DISASM-NEXT:   16000:  ff 25 00 50 01 00  jmpl *86016
-// DISASM-NEXT:   16006:  90                 nop
-// DISASM-NEXT:   16007:  90                 nop
-// DISASM-NEXT:   16008:  ff 25 04 50 01 00  jmpl *86020
-// DISASM-NEXT:   1600e:  90                 nop
-// DISASM-NEXT:   1600f:  90                 nop
+// DISASM-NEXT:   12010:  ff 25 {{.*}}       jmpl *77904
+// DISASM-NEXT:   12016:  90                 nop
+// DISASM-NEXT:   12017:  90                 nop
+// DISASM-NEXT:   12018:  ff 25 {{.*}}       jmpl *77908
+// DISASM-NEXT:   1201e:  90                 nop
+// DISASM-NEXT:   1201f:  90                 nop
 
 .global _start
 _start:
diff --git a/test/elf2/plt.s b/test/elf2/plt.s
index 914b3e3..261ca9b 100644
--- a/test/elf2/plt.s
+++ b/test/elf2/plt.s
@@ -12,7 +12,7 @@
 // CHECK-NEXT:   SHF_ALLOC
 // CHECK-NEXT:   SHF_EXECINSTR
 // CHECK-NEXT: ]
-// CHECK-NEXT: Address: 0x16000
+// CHECK-NEXT: Address: 0x12020
 // CHECK-NEXT: Offset:
 // CHECK-NEXT: Size: 24
 // CHECK-NEXT: Link: 0
@@ -21,35 +21,35 @@
 
 // CHECK:      Relocations [
 // CHECK-NEXT:   Section ({{.*}}) .rela.dyn {
-// CHECK-NEXT:     0x15000 R_X86_64_GLOB_DAT bar 0x0
-// CHECK-NEXT:     0x15008 R_X86_64_GLOB_DAT zed 0x0
-// CHECK-NEXT:     0x15010 R_X86_64_GLOB_DAT _start 0x0
+// CHECK-NEXT:     0x130A0 R_X86_64_GLOB_DAT bar 0x0
+// CHECK-NEXT:     0x130A8 R_X86_64_GLOB_DAT zed 0x0
+// CHECK-NEXT:     0x130B0 R_X86_64_GLOB_DAT _start 0x0
 // CHECK-NEXT:   }
 // CHECK-NEXT: ]
 
 // Unfortunately FileCheck can't do math, so we have to check for explicit
 // values:
 
-// 0x16000 - (0x11000 + 1) - 4 = 20475
-// 0x16000 - (0x11005 + 1) - 4 = 20470
-// 0x16008 - (0x1100a + 1) - 4 = 20473
+// 0x12020 - (0x12000 + 1) - 4 = 27
+// 0x12020 - (0x12005 + 1) - 4 = 22
+// 0x12028 - (0x1200a + 1) - 4 = 25
 
 // DISASM:      _start:
-// DISASM-NEXT:   11000:  e9 fb 4f 00 00  jmp  20475
-// DISASM-NEXT:   11005:  e9 f6 4f 00 00  jmp  20470
-// DISASM-NEXT:   1100a:  e9 f9 4f 00 00  jmp  20473
+// DISASM-NEXT:   12000:  e9 {{.*}}       jmp  27
+// DISASM-NEXT:   12005:  e9 {{.*}}       jmp  22
+// DISASM-NEXT:   1200a:  e9 {{.*}}       jmp  25
 
-// 0x15000 - 0x16006  = -4102
-// 0x15008 - 0x1600e  = -4102
+// 0x130A0 - 0x12026  = 4218
+// 0x130A8 - 0x1202e  = 4218
 
 // DISASM:      Disassembly of section .plt:
 // DISASM-NEXT: .plt:
-// DISASM-NEXT:   16000:  ff 25 fa ef ff ff  jmpq *-4102(%rip)
-// DISASM-NEXT:   16006:  90                 nop
-// DISASM-NEXT:   16007:  90                 nop
-// DISASM-NEXT:   16008:  ff 25 fa ef ff ff  jmpq *-4102(%rip)
-// DISASM-NEXT:   1600e:  90                 nop
-// DISASM-NEXT:   1600f:  90                 nop
+// DISASM-NEXT:   12020:  ff 25 {{.*}}       jmpq *4218(%rip)
+// DISASM-NEXT:   12026:  90                 nop
+// DISASM-NEXT:   12027:  90                 nop
+// DISASM-NEXT:   12028:  ff 25 {{.*}}       jmpq *4218(%rip)
+// DISASM-NEXT:   1202e:  90                 nop
+// DISASM-NEXT:   1202f:  90                 nop
 
 .global _start
 _start:
diff --git a/test/elf2/relocation-common.s b/test/elf2/relocation-common.s
index 68eca01..8822ea7 100644
--- a/test/elf2/relocation-common.s
+++ b/test/elf2/relocation-common.s
@@ -10,5 +10,5 @@ _start:
 .global sym1
 .comm sym1,4,4
 
-// CHECK: 12000: {{.*}} movl    $1, -4106(%rip)
-// CHECK: 0000000000011000 g       .bss            00000004 sym1
+// CHECK: 11000: {{.*}} movl    $1, 4086(%rip)
+// CHECK: 0000000000012000 g       .bss            00000004 sym1
diff --git a/test/elf2/relocation-i686.s b/test/elf2/relocation-i686.s
index d028215..6208b82 100644
--- a/test/elf2/relocation-i686.s
+++ b/test/elf2/relocation-i686.s
@@ -27,14 +27,14 @@ R_386_PC32_2:
 
 // CHECK: Disassembly of section .R_386_32:
 // CHECK-NEXT: R_386_32:
-// CHECK-NEXT:  11000: {{.*}} movl $69633, %edx
+// CHECK-NEXT:  12000: {{.*}} movl $73729, %edx
 
 // CHECK: Disassembly of section .R_386_PC32:
 // CHECK-NEXT: R_386_PC32:
-// CHECK-NEXT:   11005:  e8 04 00 00 00  calll 4
+// CHECK-NEXT:   12005:  e8 04 00 00 00  calll 4
 
 // CHECK:      R_386_PC32_2:
-// CHECK-NEXT:   1100e:  90  nop
+// CHECK-NEXT:   1200e:  90  nop
 
 // Create a .got
 movl bar at GOT, %eax
@@ -46,23 +46,23 @@ movl bar at GOT, %eax
 // ADDR-NEXT:   SHF_ALLOC
 // ADDR-NEXT:   SHF_WRITE
 // ADDR-NEXT: ]
-// ADDR-NEXT: Address: 0x15000
+// ADDR-NEXT: Address: 0x13050
 
 .section .R_386_GOTPC,"ax", at progbits
 R_386_GOTPC:
  movl $_GLOBAL_OFFSET_TABLE_, %eax
 
-// 0x15000 - 0x11014 = 16364
+// 0x13050 - 0x12014 = 4156
 
 // CHECK:      Disassembly of section .R_386_GOTPC:
 // CHECK-NEXT: R_386_GOTPC:
-// CHECK-NEXT:   11014:  {{.*}} movl  $16364, %eax
+// CHECK-NEXT:   12014:  {{.*}} movl  $4156, %eax
 
 .section .dynamic_reloc, "ax", at progbits
         call bar+4
 // CHECK:      Disassembly of section .dynamic_reloc:
 // CHECK-NEXT: .dynamic_reloc:
-// CHECK-NEXT:   11019:  e8 00 00 00 00  calll  0
+// CHECK-NEXT:   12019:  e8 00 00 00 00  calll  0
 
 .section .R_386_GOT32,"ax", at progbits
 .global R_386_GOT32
@@ -71,4 +71,4 @@ R_386_GOT32:
 // This is the second symbol in the got, so the offset is 4.
 // CHECK:      Disassembly of section .R_386_GOT32:
 // CHECK-NEXT: R_386_GOT32:
-// CHECK-NEXT:   1101e:  {{.*}} movl 4, %eax
+// CHECK-NEXT:   1201e:  {{.*}} movl 4, %eax
diff --git a/test/elf2/relocation-local.s b/test/elf2/relocation-local.s
index 5042c79..3adba3d 100644
--- a/test/elf2/relocation-local.s
+++ b/test/elf2/relocation-local.s
@@ -20,7 +20,7 @@ R_X86_64_32:
 // constants in hex.
 // CHECK: Disassembly of section .text2:
 // CHECK-NEXT: R_X86_64_32:
-// CHECK-NEXT:  1100c: {{.*}} movl $69644, %edx
+// CHECK-NEXT:  12009: {{.*}} movl $73737, %edx
 
 .section .R_X86_64_32S,"ax", at progbits
 R_X86_64_32S:
@@ -28,11 +28,11 @@ R_X86_64_32S:
 
 // CHECK: Disassembly of section .R_X86_64_32S:
 // CHECK-NEXT: R_X86_64_32S:
-// CHECK-NEXT:  {{.*}}: {{.*}} movq -978935, %rdx
+// CHECK-NEXT:  {{.*}}: {{.*}} movq -974839, %rdx
 
 .section .R_X86_64_64,"a", at progbits
 R_X86_64_64:
  .quad R_X86_64_64
 
 // CHECK:      Contents of section .R_X86_64_64:
-// CHECK-NEXT:   12000 00200100 00000000
+// CHECK-NEXT:   11000 00100100 00000000
diff --git a/test/elf2/relocation.s b/test/elf2/relocation.s
index 4046f2b..b56dcd8 100644
--- a/test/elf2/relocation.s
+++ b/test/elf2/relocation.s
@@ -6,13 +6,23 @@
 // RUN: llvm-objdump -s -d %t3 | FileCheck %s
 // REQUIRES: x86
 
+// SEC:      Name: .plt
+// SEC-NEXT: Type: SHT_PROGBITS
+// SEC-NEXT: Flags [
+// SEC-NEXT:   SHF_ALLOC
+// SEC-NEXT:   SHF_EXECINSTR
+// SEC-NEXT: ]
+// SEC-NEXT: Address: 0x12020
+// SEC-NEXT: Offset: 0x2020
+// SEC-NEXT: Size: 8
+
 // SEC:         Name: .got
 // SEC-NEXT:   Type: SHT_PROGBITS
 // SEC-NEXT:   Flags [
 // SEC-NEXT:     SHF_ALLOC
 // SEC-NEXT:     SHF_WRITE
 // SEC-NEXT:   ]
-// SEC-NEXT:   Address: 0x15000
+// SEC-NEXT:   Address: 0x130A0
 // SEC-NEXT:   Offset:
 // SEC-NEXT:   Size: 16
 // SEC-NEXT:   Link: 0
@@ -21,16 +31,6 @@
 // SEC-NEXT:   EntrySize: 0
 // SEC-NEXT: }
 
-// SEC:      Name: .plt
-// SEC-NEXT: Type: SHT_PROGBITS
-// SEC-NEXT: Flags [
-// SEC-NEXT:   SHF_ALLOC
-// SEC-NEXT:   SHF_EXECINSTR
-// SEC-NEXT: ]
-// SEC-NEXT: Address: 0x16000
-// SEC-NEXT: Offset: 0x6000
-// SEC-NEXT: Size: 8
-
 .section       .text,"ax", at progbits,unique,1
 .global _start
 _start:
@@ -44,11 +44,11 @@ lulz:
 
 // CHECK: Disassembly of section .text:
 // CHECK-NEXT: _start:
-// CHECK-NEXT:   11000:  e8 04 00 00 00   callq 4
-// CHECK-NEXT:   11005:
+// CHECK-NEXT:   12000:  e8 04 00 00 00   callq 4
+// CHECK-NEXT:   12005:
 
 // CHECK:      lulz:
-// CHECK-NEXT:   11009:  90  nop
+// CHECK-NEXT:   12009:  90  nop
 
 
 .section       .text2,"ax", at progbits
@@ -60,7 +60,7 @@ R_X86_64_32:
 // constants in hex.
 // CHECK: Disassembly of section .text2:
 // CHECK-NEXT: R_X86_64_32:
-// CHECK-NEXT:  1100c: {{.*}} movl $69644, %edx
+// CHECK-NEXT:  1200a: {{.*}} movl $73738, %edx
 
 .section .R_X86_64_32S,"ax", at progbits
 .global R_X86_64_32S
@@ -69,16 +69,16 @@ R_X86_64_32S:
 
 // CHECK: Disassembly of section .R_X86_64_32S:
 // CHECK-NEXT: R_X86_64_32S:
-// CHECK-NEXT:  {{.*}}: {{.*}} movq -978935, %rdx
+// CHECK-NEXT:  {{.*}}: {{.*}} movq -974839, %rdx
 
 .section .R_X86_64_PC32,"ax", at progbits
 .global R_X86_64_PC32
 R_X86_64_PC32:
  call bar
-// 0x16000 - (0x11019 + 5) = 20450
+// 0x12020 - (0x12017 + 5) = 4
 // CHECK:      Disassembly of section .R_X86_64_PC32:
 // CHECK-NEXT: R_X86_64_PC32:
-// CHECK-NEXT:  11019:   e8 e2 4f 00 00  callq  20450
+// CHECK-NEXT:  12017:   e8 04 00 00 00  callq  4
 
 .section .R_X86_64_64,"a", at progbits
 .global R_X86_64_64
@@ -86,14 +86,14 @@ R_X86_64_64:
  .quad R_X86_64_64
 
 // CHECK:      Contents of section .R_X86_64_64:
-// CHECK-NEXT:   12000 00200100 00000000
+// CHECK-NEXT:   11000 00100100 00000000
 
 .section .R_X86_64_GOTPCREL,"a", at progbits
 .global R_X86_64_GOTPCREL
 R_X86_64_GOTPCREL:
  .long R_X86_64_GOTPCREL at gotpcrel
 
-// 0x15008 - 0x12008 = 12288
-// 12288 = 0x00300000   in little endian
+// 0x130A8 - 0x11008 = 8352
+// 8352 = 0x80200000   in little endian
 // CHECK:      Contents of section .R_X86_64_GOTPCREL
-// CHECK-NEXT:   12008 00300000
+// CHECK-NEXT:   11008 a0200000
diff --git a/test/elf2/section-layout.s b/test/elf2/section-layout.s
new file mode 100644
index 0000000..24cb948
--- /dev/null
+++ b/test/elf2/section-layout.s
@@ -0,0 +1,28 @@
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: lld -flavor gnu2 %t -o %tout
+# RUN: llvm-readobj -sections %tout | FileCheck %s
+# REQUIRES: x86
+
+# Check that sections are laid out in the correct order.
+
+.global _start
+.text
+_start:
+
+.section h,""
+.section g,"", at nobits
+.section f,"aw", at nobits
+.section e,"aw"
+.section d,"ax", at nobits
+.section c,"ax"
+.section b,"a", at nobits
+.section a,"a"
+
+// CHECK: Name: a
+// CHECK: Name: b
+// CHECK: Name: c
+// CHECK: Name: d
+// CHECK: Name: e
+// CHECK: Name: f
+// CHECK: Name: h
+// CHECK: Name: g
diff --git a/test/elf2/shared.s b/test/elf2/shared.s
index dcda240..6d02249 100644
--- a/test/elf2/shared.s
+++ b/test/elf2/shared.s
@@ -14,7 +14,7 @@
 // SO-NEXT: Flags [
 // SO-NEXT: ]
 // SO-NEXT: Address:
-// SO-NEXT: Offset: 0x300C
+// SO-NEXT: Offset: 0x2030
 // SO-NEXT: Size:
 // SO-NEXT: Link:
 // SO-NEXT: Info:
@@ -39,14 +39,14 @@
 // CHECK-NEXT: }
 
 // test that .hash is linked to .dynsym
-// CHECK:        Index: 5
+// CHECK:        Index: 2
 // CHECK-NEXT:   Name: .dynsym
 // CHECK-NEXT:   Type: SHT_DYNSYM
 // CHECK-NEXT:   Flags [
 // CHECK-NEXT:     SHF_ALLOC
 // CHECK-NEXT:   ]
 // CHECK-NEXT:   Address: [[DYNSYMADDR:.*]]
-// CHECK-NEXT:   Offset: 0x201C
+// CHECK-NEXT:   Offset: 0x101C
 // CHECK-NEXT:   Size:
 // CHECK-NEXT:   Link: [[DYNSTR:.*]]
 // CHECK-NEXT:   Info: 1
@@ -60,7 +60,7 @@
 // CHECK-NEXT:   )
 // CHECK-NEXT: }
 // CHECK-NEXT: Section {
-// CHECK-NEXT:   Index: 6
+// CHECK-NEXT:   Index: 3
 // CHECK-NEXT:    Name: .hash
 // CHECK-NEXT:    Type: SHT_HASH
 // CHECK-NEXT:    Flags [
@@ -69,29 +69,11 @@
 // CHECK-NEXT:    Address: [[HASHADDR:.*]]
 // CHECK-NEXT:    Offset:
 // CHECK-NEXT:    Size:
-// CHECK-NEXT:    Link: 5
+// CHECK-NEXT:    Link: 2
 // CHECK-NEXT:    Info: 0
 // CHECK-NEXT:    AddressAlignment: 4
 // CHECK-NEXT:    EntrySize: 4
 
-
-// CHECK:        Name: .dynamic
-// CHECK-NEXT:   Type: SHT_DYNAMIC
-// CHECK-NEXT:   Flags [
-// CHECK-NEXT:     SHF_ALLOC
-// CHECK-NEXT:     SHF_WRITE
-// CHECK-NEXT:   ]
-// CHECK-NEXT:   Address: [[ADDR:.*]]
-// CHECK-NEXT:   Offset: [[OFFSET:.*]]
-// CHECK-NEXT:   Size: [[SIZE:.*]]
-// CHECK-NEXT:   Link: [[DYNSTR]]
-// CHECK-NEXT:   Info: 0
-// CHECK-NEXT:   AddressAlignment: [[ALIGN:.*]]
-// CHECK-NEXT:   EntrySize: 8
-// CHECK-NEXT:   SectionData (
-// CHECK:        )
-// CHECK-NEXT: }
-
 // CHECK:        Index: [[DYNSTR]]
 // CHECK-NEXT:   Name: .dynstr
 // CHECK-NEXT:   Type: SHT_STRTAB
@@ -122,6 +104,23 @@
 // CHECK-NEXT: AddressAlignment:
 // CHECK-NEXT: EntrySize: [[RELENT:.*]]
 
+// CHECK:        Name: .dynamic
+// CHECK-NEXT:   Type: SHT_DYNAMIC
+// CHECK-NEXT:   Flags [
+// CHECK-NEXT:     SHF_ALLOC
+// CHECK-NEXT:     SHF_WRITE
+// CHECK-NEXT:   ]
+// CHECK-NEXT:   Address: [[ADDR:.*]]
+// CHECK-NEXT:   Offset: [[OFFSET:.*]]
+// CHECK-NEXT:   Size: [[SIZE:.*]]
+// CHECK-NEXT:   Link: [[DYNSTR]]
+// CHECK-NEXT:   Info: 0
+// CHECK-NEXT:   AddressAlignment: [[ALIGN:.*]]
+// CHECK-NEXT:   EntrySize: 8
+// CHECK-NEXT:   SectionData (
+// CHECK:        )
+// CHECK-NEXT: }
+
 // CHECK:      Name: .symtab
 // CHECK-NEXT: Type: SHT_SYMTAB
 // CHECK-NEXT: Flags [
@@ -146,7 +145,7 @@
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Symbol {
 // CHECK-NEXT:     Name: _start
-// CHECK-NEXT:     Value: 0x11000
+// CHECK-NEXT:     Value: 0x12000
 // CHECK-NEXT:     Size: 0
 // CHECK-NEXT:     Binding: Global
 // CHECK-NEXT:     Type: None
@@ -185,7 +184,7 @@
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Symbol {
 // CHECK-NEXT:     Name: _start@
-// CHECK-NEXT:     Value: 0x11000
+// CHECK-NEXT:     Value: 0x12000
 // CHECK-NEXT:     Size: 0
 // CHECK-NEXT:     Binding: Global
 // CHECK-NEXT:     Type: Non
diff --git a/test/elf2/symbols.s b/test/elf2/symbols.s
index 607048d..27e6fb7 100644
--- a/test/elf2/symbols.s
+++ b/test/elf2/symbols.s
@@ -45,15 +45,12 @@ hidden:
 .internal internal
 internal:
 
-// CHECK:      Name: .bss
+// CHECK:      Name: foobar
 // CHECK-NEXT: Type: SHT_NOBITS
 // CHECK-NEXT: Flags [
 // CHECK-NEXT:   SHF_ALLOC
-// CHECK-NEXT:   SHF_WRITE
 // CHECK-NEXT: ]
 // CHECK-NEXT: Address: 0x11000
-// CHECK-NEXT: Offset: 0x1000
-// CHECK-NEXT: Size: 4
 
 // CHECK:      Name: .text
 // CHECK-NEXT: Type: SHT_PROGBITS
@@ -63,12 +60,15 @@ internal:
 // CHECK-NEXT: ]
 // CHECK-NEXT: Address: 0x12000
 
-// CHECK:      Name: foobar
+// CHECK:      Name: .bss
 // CHECK-NEXT: Type: SHT_NOBITS
 // CHECK-NEXT: Flags [
 // CHECK-NEXT:   SHF_ALLOC
+// CHECK-NEXT:   SHF_WRITE
 // CHECK-NEXT: ]
 // CHECK-NEXT: Address: 0x13000
+// CHECK-NEXT: Offset: 0x2000
+// CHECK-NEXT: Size: 4
 
 // CHECK:      Symbols [
 // CHECK-NEXT:   Symbol {
@@ -109,7 +109,7 @@ internal:
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Symbol {
 // CHECK-NEXT:     Name: common
-// CHECK-NEXT:     Value: 0x11000
+// CHECK-NEXT:     Value: 0x13000
 // CHECK-NEXT:     Size: 4
 // CHECK-NEXT:     Binding: Global
 // CHECK-NEXT:     Type: Object
@@ -127,7 +127,7 @@ internal:
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Symbol {
 // CHECK-NEXT:     Name: protected
-// CHECK-NEXT:     Value: 0x13008
+// CHECK-NEXT:     Value: 0x11008
 // CHECK-NEXT:     Size: 0
 // CHECK-NEXT:     Binding: Global
 // CHECK-NEXT:     Type: None
@@ -136,7 +136,7 @@ internal:
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Symbol {
 // CHECK-NEXT:     Name: zed
-// CHECK-NEXT:     Value: 0x13000
+// CHECK-NEXT:     Value: 0x11000
 // CHECK-NEXT:     Size: 0
 // CHECK-NEXT:     Binding: Global (0x1)
 // CHECK-NEXT:     Type: None
@@ -145,7 +145,7 @@ internal:
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Symbol {
 // CHECK-NEXT:     Name: zed2
-// CHECK-NEXT:     Value: 0x13004
+// CHECK-NEXT:     Value: 0x11004
 // CHECK-NEXT:     Size: 0
 // CHECK-NEXT:     Binding: Global
 // CHECK-NEXT:     Type: None
@@ -154,7 +154,7 @@ internal:
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Symbol {
 // CHECK-NEXT:     Name: zed3
-// CHECK-NEXT:     Value: 0x13008
+// CHECK-NEXT:     Value: 0x11008
 // CHECK-NEXT:     Size: 4
 // CHECK-NEXT:     Binding: Global
 // CHECK-NEXT:     Type: None


More information about the llvm-commits mailing list