[PATCH] D40408: [LLD] [COFF] Interpret a period as a separator for section suffix just like '$'

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 26 14:16:18 PST 2017


mstorsjo updated this revision to Diff 124316.
mstorsjo retitled this revision from "[LLD] [COFF] Implement numerical sorting of constructors with priority" to "[LLD] [COFF] Interpret a period as a separator for section suffix just like '$'".
mstorsjo edited the summary of this revision.
mstorsjo added a comment.

I noticed that GCC actually does zero pad these, and GNU ld expects them zero padded, so this simplifies this patch quite significantly. The `.ctors$zzz` part is only used in the llvm/lld specific parts of mingw-w64, and can be replaced with `.ctors.99999` or something similar once this goes in, to avoid the need for the special sorting of them.


https://reviews.llvm.org/D40408

Files:
  COFF/Writer.cpp
  test/COFF/ctors_dtors_priority.s


Index: test/COFF/ctors_dtors_priority.s
===================================================================
--- /dev/null
+++ test/COFF/ctors_dtors_priority.s
@@ -0,0 +1,30 @@
+# REQUIRES: x86
+# RUN: llvm-mc -triple=x86_64-windows-gnu -filetype=obj -o %t.obj %s
+# RUN: lld-link -entry:main %t.obj -out:%t.exe
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+.globl main
+main:
+  nop
+
+.section .ctors.00005, "w"
+  .quad 2
+.section .ctors, "w"
+  .quad 1
+.section .ctors.00100, "w"
+  .quad 3
+
+.section .dtors, "w"
+  .quad 1
+.section .dtors.00100, "w"
+  .quad 3
+.section .dtors.00005, "w"
+  .quad 2
+
+# CHECK:      Contents of section .ctors:
+# CHECK-NEXT: 140001000 01000000 00000000 02000000 00000000
+# CHECK-NEXT: 140001010 03000000 00000000
+
+# CHECK:      Contents of section .dtors:
+# CHECK-NEXT: 140002000 01000000 00000000 02000000 00000000
+# CHECK-NEXT: 140002010 03000000 00000000
Index: COFF/Writer.cpp
===================================================================
--- COFF/Writer.cpp
+++ COFF/Writer.cpp
@@ -319,6 +319,7 @@
 
 static StringRef getOutputSection(StringRef Name) {
   StringRef S = Name.split('$').first;
+  S = S.substr(0, S.find('.', 1));
   auto It = Config->Merge.find(S);
   if (It == Config->Merge.end())
     return S;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40408.124316.patch
Type: text/x-patch
Size: 1277 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171126/b78674e1/attachment.bin>


More information about the llvm-commits mailing list