[PATCH] D13763: [lld][elf2] Sort allocated TLS sections at the start of the R/W PT_LOAD.

Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 16 16:13:17 PDT 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL250572: [elf2] Sort allocated TLS sections at the start of the R/W PT_LOAD. (authored by mspencer).

Changed prior to commit:
  http://reviews.llvm.org/D13763?vs=37442&id=37651#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D13763

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

Index: lld/trunk/test/elf2/section-layout.s
===================================================================
--- lld/trunk/test/elf2/section-layout.s
+++ lld/trunk/test/elf2/section-layout.s
@@ -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 @@
 // 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
Index: lld/trunk/ELF/Writer.cpp
===================================================================
--- lld/trunk/ELF/Writer.cpp
+++ lld/trunk/ELF/Writer.cpp
@@ -317,6 +317,16 @@
     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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13763.37651.patch
Type: text/x-patch
Size: 2009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151016/ffc74d14/attachment.bin>


More information about the llvm-commits mailing list