[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
Thu Apr 14 04:31:50 PDT 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.

During discussion of D18499 was stated:
"Orphan sections are sections present in the input files which are not explicitly placed into the output file by the linker script. We place orphan sections at end of file."
This patch does not really affect D18499 because order of OutputSections in D18499 patch does not make sence anymore (script do all layout stuff).

But this patch changes sorting predicate to place orphans to the end. At least that is needed to keep OutputSections in sync with output to
set Sec->SectionIndex correctly for futher finalization.

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=BSSORPHAN %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
+
+# BSSORPHAN:      Sections:
+# BSSORPHAN-NEXT: Idx Name          Size      Address          Type
+# BSSORPHAN-NEXT:   0               00000000 0000000000000000
+# BSSORPHAN-NEXT:   1 .text         00000001 0000000000011000 TEXT DATA
+# BSSORPHAN-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
@@ -69,7 +69,7 @@
   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.53690.patch
Type: text/x-patch
Size: 1777 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160414/95d9dfba/attachment.bin>


More information about the llvm-commits mailing list