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

Rafael Espíndola via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 16 15:49:06 PDT 2015


In summary, this is what I think we should do.

On 16 October 2015 at 15:30, Rafael Ávila de Espíndola
<llvm-commits at lists.llvm.org> wrote:
> rafael added a comment.
>
> Also please remove the "don't care" sections from the test:
>
> .section v,"T", at nobits
> .section u,"T"
> section h,"aT", at nobits
> .section f,"aT"
>
> We only really care how we sort tls sections that are aw
>
>
> ================
> Comment at: ELF/Writer.cpp:327
> @@ -318,1 +326,3 @@
>
> +  // 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
> ----------------
> Move this past the comment
>
>  // If we got here we know that both A and B are in the same PT_LOAD.
>
>
> http://reviews.llvm.org/D13763
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
-------------- next part --------------
diff --git a/ELF/Writer.cpp b/ELF/Writer.cpp
index 2a910c1..1929288 100644
--- a/ELF/Writer.cpp
+++ b/ELF/Writer.cpp
@@ -318,6 +318,16 @@ static bool compareOutputSections(OutputSectionBase<ELFT> *A,
     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
diff --git a/test/elf2/section-layout.s b/test/elf2/section-layout.s
index 5a28800..77ac72a 100644
--- a/test/elf2/section-layout.s
+++ b/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 @@ _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