diff options
author | Martin Storsjo <martin@martin.st> | 2018-08-29 17:24:10 +0000 |
---|---|---|
committer | Martin Storsjo <martin@martin.st> | 2018-08-29 17:24:10 +0000 |
commit | cfbbb707f539feed15bc35ecd44a095688d5b27a (patch) | |
tree | 258c1b1f76d9e432f52872e66618dbeafeba3539 | |
parent | 2bcb1eeee15f867439d937d7c68a297544765cd4 (diff) | |
download | bcm5719-llvm-cfbbb707f539feed15bc35ecd44a095688d5b27a.tar.gz bcm5719-llvm-cfbbb707f539feed15bc35ecd44a095688d5b27a.zip |
[COFF] Merge the .ctors, .dtors and .CRT sections into .rdata for MinGW
There's no point in keeping them as separate sections.
This differs from GNU ld, which places .ctors and .dtors 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.
GNU ld also leaves .CRT separate as its own standalone section.
MSVC merges .CRT into .rdata similarly, with a directive embedded in
an object file in msvcrt.lib or libcmt.lib.
Differential Revision: https://reviews.llvm.org/D51414
llvm-svn: 340940
-rw-r--r-- | lld/COFF/Driver.cpp | 6 | ||||
-rw-r--r-- | lld/test/COFF/ctors_dtors_priority.s | 24 |
2 files changed, 20 insertions, 10 deletions
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 000ef59f7fa..5a0ce05a30e 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -1107,6 +1107,12 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) { parseMerge(".xdata=.rdata"); parseMerge(".bss=.data"); + if (Config->MinGW) { + parseMerge(".ctors=.rdata"); + parseMerge(".dtors=.rdata"); + parseMerge(".CRT=.rdata"); + } + // Handle /section for (auto *Arg : Args.filtered(OPT_section)) parseSection(Arg->getValue()); diff --git a/lld/test/COFF/ctors_dtors_priority.s b/lld/test/COFF/ctors_dtors_priority.s index efa03543027..55c7eea989d 100644 --- a/lld/test/COFF/ctors_dtors_priority.s +++ b/lld/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,20 @@ main: .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 + +# Also test that the .CRT section is merged into .rdata -# CHECK: Contents of section .ctors: -# CHECK-NEXT: 140002000 01000000 00000000 02000000 00000000 -# CHECK-NEXT: 140002010 03000000 00000000 +.section .CRT$XCA, "dw" + .quad 7 + .quad 8 -# CHECK: Contents of section .dtors: -# CHECK-NEXT: 140003000 01000000 00000000 02000000 00000000 -# CHECK-NEXT: 140003010 03000000 00000000 +# CHECK: Contents of section .rdata: +# CHECK-NEXT: 140002000 07000000 00000000 08000000 00000000 +# CHECK-NEXT: 140002010 01000000 00000000 02000000 00000000 +# CHECK-NEXT: 140002020 03000000 00000000 04000000 00000000 +# CHECK-NEXT: 140002030 05000000 00000000 06000000 00000000 |