[ELF] - Do not put non exec sections first when -no-rosegment
authorGeorge Rimar <grimar@accesssoftek.com>
Mon, 28 Nov 2016 10:26:21 +0000 (10:26 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Mon, 28 Nov 2016 10:26:21 +0000 (10:26 +0000)
That unifies handling cases when we have SECTIONS and when
-no-rosegment is given in compareSectionsNonScript()

Now Config->SingleRoRx is used for check, testcase is provided.

llvm-svn: 288022

lld/ELF/Writer.cpp
lld/test/ELF/sort-norosegment.s [new file with mode: 0644]

index 39b8a24..c7fc9a8 100644 (file)
@@ -492,12 +492,12 @@ static bool compareSectionsNonScript(const OutputSectionBase *A,
   if (AIsWritable != BIsWritable)
     return BIsWritable;
 
-  if (!ScriptConfig->HasSections) {
+  if (!Config->SingleRoRx) {
     // 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.
+    // order is not important. The same applies for -no-rosegment.
     bool AIsExec = A->Flags & SHF_EXECINSTR;
     bool BIsExec = B->Flags & SHF_EXECINSTR;
     if (AIsExec != BIsExec)
diff --git a/lld/test/ELF/sort-norosegment.s b/lld/test/ELF/sort-norosegment.s
new file mode 100644 (file)
index 0000000..3026bb2
--- /dev/null
@@ -0,0 +1,15 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
+
+# RUN: ld.lld -no-rosegment -o %t1  %t -shared
+# RUN: llvm-readobj -elf-output-style=GNU -s %t1 | FileCheck %s
+
+# CHECK:      .text    {{.*}}   AX
+# CHECK-NEXT: .dynsym  {{.*}}   A
+# CHECK-NEXT: .hash    {{.*}}   A
+# CHECK-NEXT: .dynstr  {{.*}}   A
+# CHECK-NEXT: .dynamic {{.*}}  WA
+# CHECK-NEXT: foo      {{.*}}  WA
+
+.section foo, "aw"
+.byte 0