[lld] r363457 - [COFF] Strip section name suffix from mingw comdats

Martin Storsjo via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 14 14:02:09 PDT 2019


Author: mstorsjo
Date: Fri Jun 14 14:02:09 2019
New Revision: 363457

URL: http://llvm.org/viewvc/llvm-project?rev=363457&view=rev
Log:
[COFF] Strip section name suffix from mingw comdats

This is the second part of the fix for PR42217.

Differential Revision: https://reviews.llvm.org/D63352

Added:
    lld/trunk/test/COFF/eh_frame_suffix_sorting.s
Modified:
    lld/trunk/COFF/Writer.cpp

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=363457&r1=363456&r2=363457&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Fri Jun 14 14:02:09 2019
@@ -797,7 +797,13 @@ void Writer::createSections() {
         SC->printDiscardedMessage();
       continue;
     }
-    PartialSection *PSec = createPartialSection(C->getSectionName(),
+    StringRef Name = C->getSectionName();
+    // On MinGW, comdat groups are formed by putting the comdat group name
+    // after the '$' in the section name. Such a section name suffix shouldn't
+    // imply separate alphabetical sorting of those section chunks though.
+    if (Config->MinGW && SC && SC->isCOMDAT())
+      Name = Name.split('$').first;
+    PartialSection *PSec = createPartialSection(Name,
                                                 C->getOutputCharacteristics());
     PSec->Chunks.push_back(C);
   }

Added: lld/trunk/test/COFF/eh_frame_suffix_sorting.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/eh_frame_suffix_sorting.s?rev=363457&view=auto
==============================================================================
--- lld/trunk/test/COFF/eh_frame_suffix_sorting.s (added)
+++ lld/trunk/test/COFF/eh_frame_suffix_sorting.s Fri Jun 14 14:02:09 2019
@@ -0,0 +1,39 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -triple=i686-windows-gnu %s -filetype=obj -o %t.main.o
+# RUN: llvm-mc -filetype=obj -triple=i686-windows-gnu \
+# RUN:   %p/Inputs/eh_frame_terminator-crtend.s -o %t.crtend.o
+
+# RUN: lld-link -lldmingw -entry:main %t.main.o %t.crtend.o -out:%t.exe
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# Check that the contents of .eh_frame$foo was placed before .eh_frame from
+# crtend.o, even if the former had a section name suffix.
+
+# CHECK: Contents of section .eh_fram:
+# CHECK:  403000 4203
+
+        .text
+        .def            _main;
+        .scl            2;
+        .type           32;
+        .endef
+        .globl          _main
+        .p2align        4, 0x90
+_main:
+        call            _foo
+        ret
+
+        .section        .eh_frame$foo,"dr"
+        .linkonce       discard
+        .byte           0x42
+
+        .def            _foo;
+        .scl            2;
+        .type           32;
+        .endef
+        .section        .text$foo,"xr",discard,foo
+        .globl          _foo
+        .p2align        4
+_foo:
+        ret




More information about the llvm-commits mailing list