[lld] r282799 - Don't put ro before rx when using linker scripts.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 29 15:48:56 PDT 2016


Author: rafael
Date: Thu Sep 29 17:48:55 2016
New Revision: 282799

URL: http://llvm.org/viewvc/llvm-project?rev=282799&view=rev
Log:
Don't put ro before rx when using linker scripts.

Since they end up going on the same PT_LOAD, there is no reason to
sort them. This matches bfd's behaviour and is user visible in the
placement of orphan sections.

Modified:
    lld/trunk/ELF/Writer.cpp
    lld/trunk/test/ELF/linkerscript/merge-sections.s
    lld/trunk/test/ELF/linkerscript/no-space.s
    lld/trunk/test/ELF/linkerscript/non-alloc.s
    lld/trunk/test/ELF/linkerscript/sections-constraint.s
    lld/trunk/test/ELF/linkerscript/sections-keep.s
    lld/trunk/test/ELF/linkerscript/sections-sort.s
    lld/trunk/test/ELF/linkerscript/sort-non-script.s
    lld/trunk/test/ELF/linkerscript/va.s

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=282799&r1=282798&r2=282799&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Sep 29 17:48:55 2016
@@ -466,12 +466,17 @@ static bool compareSectionsNonScript(Out
   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 (!ScriptConfig->HasSections) {
+    // For a corresponding reason, put non exec sections first (the program
+    // header PT_LOAD is not executable).
+    // We only do that if we are not using linker scripts, since with linker
+    // scripts ro and rx sections are in the same PT_LOAD, so their relative
+    // order is not important.
+    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 are in the same PT_LOAD.
 

Modified: lld/trunk/test/ELF/linkerscript/merge-sections.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/merge-sections.s?rev=282799&r1=282798&r2=282799&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/merge-sections.s (original)
+++ lld/trunk/test/ELF/linkerscript/merge-sections.s Thu Sep 29 17:48:55 2016
@@ -58,6 +58,7 @@
 # CHECK-NEXT:   Type:
 # CHECK-NEXT:   Flags [
 # CHECK-NEXT:     SHF_ALLOC
+# CHECK-NEXT:     SHF_EXECINSTR
 # CHECK-NEXT:   ]
 # CHECK-NEXT:   Address: 0x[[ADDR2:.*]]
 # CHECK-NEXT:   Offset: 0x[[ADDR2]]

Modified: lld/trunk/test/ELF/linkerscript/no-space.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/no-space.s?rev=282799&r1=282798&r2=282799&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/no-space.s (original)
+++ lld/trunk/test/ELF/linkerscript/no-space.s Thu Sep 29 17:48:55 2016
@@ -16,7 +16,7 @@
 # CHECK:      Section to Segment mapping:
 # CHECK-NEXT:  Segment Sections...
 # CHECK-NEXT:   00
-# CHECK-NEXT:   01     foo .dynsym .hash .dynstr
+# CHECK-NEXT:   01     foo .text .dynsym .hash .dynstr
 
 .section foo, "a"
 .quad 0

Modified: lld/trunk/test/ELF/linkerscript/non-alloc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/non-alloc.s?rev=282799&r1=282798&r2=282799&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/non-alloc.s (original)
+++ lld/trunk/test/ELF/linkerscript/non-alloc.s Thu Sep 29 17:48:55 2016
@@ -17,7 +17,7 @@
 # CHECK:      Section to Segment mapping:
 # CHECK-NEXT:  Segment Sections...
 # CHECK-NEXT:   00
-# CHECK-NEXT:   01     .dynsym .hash .dynstr .text
+# CHECK-NEXT:   01     .text .dynsym .hash .dynstr
 # CHECK-NEXT:   02     .dynamic
 
 nop

Modified: lld/trunk/test/ELF/linkerscript/sections-constraint.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/sections-constraint.s?rev=282799&r1=282798&r2=282799&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/sections-constraint.s (original)
+++ lld/trunk/test/ELF/linkerscript/sections-constraint.s Thu Sep 29 17:48:55 2016
@@ -24,8 +24,8 @@
 # NO1-NEXT: 0               00000000
 # NO1:  .writable     00000004
 # NO1:  .readable     00000004
-# NO1:  .foo.2        00000004
 # NO1:  .foo.1        00000004
+# NO1:  .foo.2        00000004
 
 .global _start
 _start:

Modified: lld/trunk/test/ELF/linkerscript/sections-keep.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/sections-keep.s?rev=282799&r1=282798&r2=282799&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/sections-keep.s (original)
+++ lld/trunk/test/ELF/linkerscript/sections-keep.s Thu Sep 29 17:48:55 2016
@@ -42,11 +42,11 @@
 # MIXED1-NEXT: Idx Name          Size
 # MIXED1-NEXT:   0               00000000
 # MIXED1-NEXT:   1 .keep         00000004
-# MIXED1-NEXT:   2 .temp         00000004
-# MIXED1-NEXT:   3 .text         00000007
-# MIXED1-NEXT:   4 .symtab       00000060
-# MIXED1-NEXT:   5 .shstrtab     0000002d
-# MIXED1-NEXT:   6 .strtab       00000012
+# MIXED1-NEXT:   2 .text         00000007 00000000000000ec TEXT DATA
+# MIXED1-NEXT:   3 .temp         00000004 00000000000000f3 DATA
+# MIXED1-NEXT:   4 .symtab       00000060 0000000000000000
+# MIXED1-NEXT:   5 .shstrtab     0000002d 0000000000000000
+# MIXED1-NEXT:   6 .strtab       00000012 0000000000000000
 
 ## The same, but now section without KEEP is at first place.
 ## gold and bfd linkers disagree here. gold collects .keep while
@@ -60,12 +60,12 @@
 # MIXED2:      Sections:
 # MIXED2-NEXT: Idx Name          Size
 # MIXED2-NEXT:   0               00000000
-# MIXED2-NEXT:   1 .nokeep       00000004
-# MIXED2-NEXT:   2 .temp         00000004
-# MIXED2-NEXT:   3 .text         00000007
-# MIXED2-NEXT:   4 .symtab       00000060
-# MIXED2-NEXT:   5 .shstrtab     0000002f
-# MIXED2-NEXT:   6 .strtab       00000012
+# MIXED2-NEXT:   1 .nokeep       00000004 00000000000000e8 DATA
+# MIXED2-NEXT:   2 .text         00000007 00000000000000ec TEXT DATA
+# MIXED2-NEXT:   3 .temp         00000004 00000000000000f3 DATA
+# MIXED2-NEXT:   4 .symtab       00000060 0000000000000000
+# MIXED2-NEXT:   5 .shstrtab     0000002f 0000000000000000
+# MIXED2-NEXT:   6 .strtab       00000012 0000000000000000
 
 .global _start
 _start:

Modified: lld/trunk/test/ELF/linkerscript/sections-sort.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/sections-sort.s?rev=282799&r1=282798&r2=282799&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/sections-sort.s (original)
+++ lld/trunk/test/ELF/linkerscript/sections-sort.s Thu Sep 29 17:48:55 2016
@@ -18,11 +18,11 @@ nop
 
 # CHECK: Id
 # CHECK-NEXT: 0
-# CHECK-NEXT: 1 .dynsym
-# CHECK-NEXT: 2 .hash
-# CHECK-NEXT: 3 .dynstr
-# CHECK-NEXT: 4 .text
-# CHECK-NEXT: 5 foo
+# CHECK-NEXT: 1 .text
+# CHECK-NEXT: 2 foo
+# CHECK-NEXT: 3 .dynsym
+# CHECK-NEXT: 4 .hash
+# CHECK-NEXT: 5 .dynstr
 # CHECK-NEXT: 6 .dynamic
 # CHECK-NEXT: 7 .symtab
 # CHECK-NEXT: 8 .shstrtab

Modified: lld/trunk/test/ELF/linkerscript/sort-non-script.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/sort-non-script.s?rev=282799&r1=282798&r2=282799&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/sort-non-script.s (original)
+++ lld/trunk/test/ELF/linkerscript/sort-non-script.s Thu Sep 29 17:48:55 2016
@@ -5,10 +5,10 @@
 # RUN: ld.lld -o %t1 --script %t.script %t -shared
 # RUN: llvm-readobj -elf-output-style=GNU -s %t1 | FileCheck %s
 
-# CHECK:      .dynsym  {{.*}}   A
+# CHECK:      .text    {{.*}}   AX
+# CHECK-NEXT: .dynsym  {{.*}}   A
 # CHECK-NEXT: .hash    {{.*}}   A
 # CHECK-NEXT: .dynstr  {{.*}}   A
-# CHECK-NEXT: .text    {{.*}}   AX
 # CHECK-NEXT: .dynamic {{.*}}  WA
 # CHECK-NEXT: foo      {{.*}}  WA
 

Modified: lld/trunk/test/ELF/linkerscript/va.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/va.s?rev=282799&r1=282798&r2=282799&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/va.s (original)
+++ lld/trunk/test/ELF/linkerscript/va.s Thu Sep 29 17:48:55 2016
@@ -7,9 +7,9 @@
 # CHECK:      Sections:
 # CHECK-NEXT: Idx Name          Size      Address          Type
 # CHECK-NEXT:   0               00000000 0000000000000000
-# CHECK-NEXT:   1 .foo          00000004 00000000000000e8 DATA
-# CHECK-NEXT:   2 .boo          00000004 00000000000000ec DATA
-# CHECK-NEXT:   3 .text         00000001 00000000000000f0 TEXT DATA
+# CHECK-NEXT:   1 .text         00000001 00000000000000e8 TEXT DATA
+# CHECK-NEXT:   2 .foo          00000004 00000000000000e9 DATA
+# CHECK-NEXT:   3 .boo          00000004 00000000000000ed DATA
 
 .global _start
 _start:




More information about the llvm-commits mailing list