diff options
| author | Martin Storsjo <martin@martin.st> | 2017-11-28 08:08:37 +0000 |
|---|---|---|
| committer | Martin Storsjo <martin@martin.st> | 2017-11-28 08:08:37 +0000 |
| commit | f2508f46cae499270d8e36c136f576f4849456b0 (patch) | |
| tree | 678ef54e9dd8ca3edf92ee0e6d0c14e9e43da1a2 | |
| parent | 04b68446eb13920e672d5a21acfeec51583521bf (diff) | |
| download | bcm5719-llvm-f2508f46cae499270d8e36c136f576f4849456b0.tar.gz bcm5719-llvm-f2508f46cae499270d8e36c136f576f4849456b0.zip | |
[COFF] Interpret a period as a separator for section suffix just like '$'
This allows grouping all sections like ".ctors.12345" into ".ctors".
For MinGW, the numerical values for such ctors are all zero-padded,
so a lexical sort is good enough.
Differential Revision: https://reviews.llvm.org/D40408
llvm-svn: 319151
| -rw-r--r-- | lld/COFF/Writer.cpp | 5 | ||||
| -rw-r--r-- | lld/test/COFF/ctors_dtors_priority.s | 30 |
2 files changed, 35 insertions, 0 deletions
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index f071fd2e2bf..f76d7d7e075 100644 --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -322,6 +322,11 @@ void Writer::run() { static StringRef getOutputSection(StringRef Name) { StringRef S = Name.split('$').first; + + // Treat a later period as a separator for MinGW, for sections like + // ".ctors.01234". + S = S.substr(0, S.find('.', 1)); + auto It = Config->Merge.find(S); if (It == Config->Merge.end()) return S; diff --git a/lld/test/COFF/ctors_dtors_priority.s b/lld/test/COFF/ctors_dtors_priority.s new file mode 100644 index 00000000000..60562ba57a5 --- /dev/null +++ b/lld/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 |

