[PATCH] D51414: [LLD] [COFF] Merge the .ctors and .dtors sections into .rdata for MinGW

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 29 04:21:11 PDT 2018


mstorsjo created this revision.
mstorsjo added reviewers: rnk, ruiu, pcc.

There's no point in keeping them as separate sections.

This differs from GNU ld, which places this content in .text (implemented by a built-in linker script). But since the content only is pointers, there's no need to have it executable.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D51414

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


Index: test/COFF/ctors_dtors_priority.s
===================================================================
--- test/COFF/ctors_dtors_priority.s
+++ test/COFF/ctors_dtors_priority.s
@@ -1,6 +1,6 @@
 # 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: lld-link -lldmingw -entry:main %t.obj -out:%t.exe
 # RUN: llvm-objdump -s %t.exe | FileCheck %s
 
 .globl main
@@ -15,16 +15,13 @@
   .quad 3
 
 .section .dtors, "w"
-  .quad 1
+  .quad 4
 .section .dtors.00100, "w"
-  .quad 3
+  .quad 6
 .section .dtors.00005, "w"
-  .quad 2
+  .quad 5
 
-# CHECK:      Contents of section .ctors:
+# CHECK:      Contents of section .rdata:
 # CHECK-NEXT: 140002000 01000000 00000000 02000000 00000000
-# CHECK-NEXT: 140002010 03000000 00000000
-
-# CHECK:      Contents of section .dtors:
-# CHECK-NEXT: 140003000 01000000 00000000 02000000 00000000
-# CHECK-NEXT: 140003010 03000000 00000000
+# CHECK-NEXT: 140002010 03000000 00000000 04000000 00000000
+# CHECK-NEXT: 140002020 05000000 00000000 06000000 00000000
Index: COFF/Driver.cpp
===================================================================
--- COFF/Driver.cpp
+++ COFF/Driver.cpp
@@ -1112,6 +1112,11 @@
   parseMerge(".xdata=.rdata");
   parseMerge(".bss=.data");
 
+  if (Config->MinGW) {
+    parseMerge(".ctors=.rdata");
+    parseMerge(".dtors=.rdata");
+  }
+
   // Handle /section
   for (auto *Arg : Args.filtered(OPT_section))
     parseSection(Arg->getValue());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51414.163047.patch
Type: text/x-patch
Size: 1514 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180829/0ff198fe/attachment.bin>


More information about the llvm-commits mailing list