[lld] r282015 - Only restrict order if both sections are in the script.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 20 13:54:40 PDT 2016
Author: rafael
Date: Tue Sep 20 15:54:39 2016
New Revision: 282015
URL: http://llvm.org/viewvc/llvm-project?rev=282015&view=rev
Log:
Only restrict order if both sections are in the script.
This matches gold and bfd behavior and is required to handle some scripts.
The script has to assume where PT_LOADs start in order to align that
spot. If we don't allow section it doesn't know about to move to the
middle, we can need more PT_LOADs and those will not be aligned.
Added:
lld/trunk/test/ELF/linkerscript/sort-non-script.s
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/test/ELF/linkerscript/orphans.s
lld/trunk/test/ELF/linkerscript/repsection-symbol.s
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=282015&r1=282014&r2=282015&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Sep 20 15:54:39 2016
@@ -664,12 +664,12 @@ template <class ELFT> int LinkerScript<E
}
// A compartor to sort output sections. Returns -1 or 1 if
-// A or B are mentioned in linker script. Otherwise, returns 0.
+// A and B are mentioned in linker script. Otherwise, returns 0.
template <class ELFT>
int LinkerScript<ELFT>::compareSections(StringRef A, StringRef B) {
int I = getSectionIndex(A);
int J = getSectionIndex(B);
- if (I == INT_MAX && J == INT_MAX)
+ if (I == INT_MAX || J == INT_MAX)
return 0;
return I < J ? -1 : 1;
}
Modified: lld/trunk/test/ELF/linkerscript/orphans.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/orphans.s?rev=282015&r1=282014&r2=282015&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/orphans.s (original)
+++ lld/trunk/test/ELF/linkerscript/orphans.s Tue Sep 20 15:54:39 2016
@@ -14,8 +14,8 @@
# TEXTORPHAN: Sections:
# TEXTORPHAN-NEXT: Idx Name
# TEXTORPHAN-NEXT: 0
-# TEXTORPHAN-NEXT: 1 .writable
-# TEXTORPHAN-NEXT: 2 .text
+# TEXTORPHAN-NEXT: 1 .text
+# TEXTORPHAN-NEXT: 2 .writable
# WRITABLEORPHAN: Sections:
# WRITABLEORPHAN-NEXT: Idx Name
Modified: lld/trunk/test/ELF/linkerscript/repsection-symbol.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/repsection-symbol.s?rev=282015&r1=282014&r2=282015&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/repsection-symbol.s (original)
+++ lld/trunk/test/ELF/linkerscript/repsection-symbol.s Tue Sep 20 15:54:39 2016
@@ -6,13 +6,13 @@
# RUN: llvm-readobj -t %t1 | FileCheck %s
# CHECK: Name: foo1
-# CHECK-NEXT: Value: 0x200
+# CHECK-NEXT: Value: 0x288
# CHECK: Name: foo2
-# CHECK-NEXT: Value: 0x208
+# CHECK-NEXT: Value: 0x290
# CHECK: Name: foo3
-# CHECK-NEXT: Value: 0x20C
+# CHECK-NEXT: Value: 0x294
.section .foo.1,"a"
.long 1
Added: 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=282015&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/sort-non-script.s (added)
+++ lld/trunk/test/ELF/linkerscript/sort-non-script.s Tue Sep 20 15:54:39 2016
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
+
+# RUN: echo "SECTIONS { foo : {*(foo)} }" > %t.script
+# 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-NEXT: .hash {{.*}} A
+# CHECK-NEXT: .dynstr {{.*}} A
+# CHECK-NEXT: .text {{.*}} AX
+# CHECK-NEXT: .dynamic {{.*}} WA
+# CHECK-NEXT: foo {{.*}} WA
+
+.section foo, "aw"
+.byte 0
More information about the llvm-commits
mailing list