[lld] r250572 - [elf2] Sort allocated TLS sections at the start of the R/W PT_LOAD.

Michael J. Spencer via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 16 16:11:07 PDT 2015


Author: mspencer
Date: Fri Oct 16 18:11:07 2015
New Revision: 250572

URL: http://llvm.org/viewvc/llvm-project?rev=250572&view=rev
Log:
[elf2] Sort allocated TLS sections at the start of the R/W PT_LOAD.

Differential Revision: http://reviews.llvm.org/D13763

Modified:
    lld/trunk/ELF/Writer.cpp
    lld/trunk/test/elf2/section-layout.s

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=250572&r1=250571&r2=250572&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Oct 16 18:11:07 2015
@@ -317,6 +317,16 @@ static bool compareOutputSections(Output
     return BIsExec;
 
   // If we got here we know that both A and B are in the same PT_LOAD.
+
+  // The TLS initialization block needs to be a single contiguous block in a R/W
+  // PT_LOAD, so stick TLS sections directly before R/W sections. The TLS NOBITS
+  // sections are placed here as they don't take up virtual address space in the
+  // PT_LOAD.
+  bool AIsTLS = AFlags & SHF_TLS;
+  bool BIsTLS = BFlags & SHF_TLS;
+  if (AIsTLS != BIsTLS)
+    return AIsTLS;
+
   // The next requirement we have is to put nobits sections last. The
   // reason is that the only thing the dynamic linker will see about
   // them is a p_memsz that is larger than p_filesz. Seeing that it

Modified: lld/trunk/test/elf2/section-layout.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/section-layout.s?rev=250572&r1=250571&r2=250572&view=diff
==============================================================================
--- lld/trunk/test/elf2/section-layout.s (original)
+++ lld/trunk/test/elf2/section-layout.s Fri Oct 16 18:11:07 2015
@@ -9,10 +9,21 @@
 .text
 _start:
 
-.section h,""
-.section g,"", at nobits
-.section f,"aw", at nobits
-.section e,"aw"
+.section t,"x", at nobits
+.section s,"x"
+.section r,"w", at nobits
+.section q,"w"
+.section p,"wx", at nobits
+.section o,"wx"
+.section n,"", at nobits
+.section m,""
+
+.section l,"awx", at nobits
+.section k,"awx"
+.section j,"aw", at nobits
+.section i,"aw"
+.section g,"awT", at nobits
+.section e,"awT"
 .section d,"ax", at nobits
 .section c,"ax"
 .section b,"a", at nobits
@@ -22,7 +33,22 @@ _start:
 // CHECK: Name: b
 // CHECK: Name: c
 // CHECK: Name: d
+
+// TLS sections are only sorted on NOBITS.
 // CHECK: Name: e
-// CHECK: Name: f
-// CHECK: Name: h
 // CHECK: Name: g
+
+// CHECK: Name: i
+// CHECK: Name: j
+// CHECK: Name: k
+// CHECK: Name: l
+
+// Non allocated sections are in input order.
+// CHECK: Name: t
+// CHECK: Name: s
+// CHECK: Name: r
+// CHECK: Name: q
+// CHECK: Name: p
+// CHECK: Name: o
+// CHECK: Name: n
+// CHECK: Name: m




More information about the llvm-commits mailing list