[PATCH] D19107: [ELF] - Tweak sorting rules for output sections to place orphan sections at end.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 15 03:00:54 PDT 2016


grimar updated this revision to Diff 53864.
grimar added a comment.

- Updated comment.
- Fixed name of check prefix in testcase.


http://reviews.llvm.org/D19107

Files:
  ELF/LinkerScript.cpp
  test/ELF/linkerscript-orphans.s

Index: test/ELF/linkerscript-orphans.s
===================================================================
--- test/ELF/linkerscript-orphans.s
+++ test/ELF/linkerscript-orphans.s
@@ -0,0 +1,31 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+
+# RUN: echo "SECTIONS { .writable : { *(.writable) } }" > %t.script
+# RUN: ld.lld -o %t.out --script %t.script %t
+# RUN: llvm-objdump -section-headers %t.out | \
+# RUN:   FileCheck -check-prefix=TEXTORPHAN %s
+
+# RUN: echo "SECTIONS { .text : { *(.text) } }" > %t.script
+# RUN: ld.lld -o %t.out --script %t.script %t
+# RUN: llvm-objdump -section-headers %t.out | \
+# RUN:   FileCheck -check-prefix=WRITABLEORPHAN %s
+
+# TEXTORPHAN:      Sections:
+# TEXTORPHAN-NEXT: Idx Name          Size      Address          Type
+# TEXTORPHAN-NEXT:   0               00000000 0000000000000000
+# TEXTORPHAN-NEXT:   1 .writable     00000004 0000000000011000 DATA
+# TEXTORPHAN-NEXT:   2 .text         00000001 0000000000012000 TEXT DATA
+
+# WRITABLEORPHAN:      Sections:
+# WRITABLEORPHAN-NEXT: Idx Name          Size      Address          Type
+# WRITABLEORPHAN-NEXT:   0               00000000 0000000000000000
+# WRITABLEORPHAN-NEXT:   1 .text         00000001 0000000000011000 TEXT DATA
+# WRITABLEORPHAN-NEXT:   2 .writable     00000004 0000000000012000 DATA
+
+.global _start
+_start:
+ nop
+
+.section .writable,"aw"
+ .zero 4
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -62,14 +62,14 @@
   return I->second;
 }
 
-// A compartor to sort output sections. Returns -1 or 1 if both
-// A and B are mentioned in linker scripts. Otherwise, returns 0
+// A compartor to sort output sections. Returns -1 or 1 if
+// A or B are mentioned in linker script. Otherwise, returns 0
 // to use the default rule which is implemented in Writer.cpp.
 int LinkerScript::compareSections(StringRef A, StringRef B) {
   auto E = SectionOrder.end();
   auto I = std::find(SectionOrder.begin(), E, A);
   auto J = std::find(SectionOrder.begin(), E, B);
-  if (I == E || J == E)
+  if (I == E && J == E)
     return 0;
   return I < J ? -1 : 1;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19107.53864.patch
Type: text/x-patch
Size: 2217 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160415/5b63f44c/attachment.bin>


More information about the llvm-commits mailing list