[PATCH] D49757: [COFF] Keep using associative comdats for xdata/pdata for MinGW

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 24 13:59:31 PDT 2018


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

Using the symbol name as suffix for the section name is enough to keep things working for ld.bfd, but making them proper associative comdats helps LLD to bring them in when necessary.


Repository:
  rL LLVM

https://reviews.llvm.org/D49757

Files:
  lib/MC/MCStreamer.cpp
  test/CodeGen/X86/mingw-comdats-xdata.ll
  test/CodeGen/X86/mingw-comdats.ll


Index: test/CodeGen/X86/mingw-comdats.ll
===================================================================
--- test/CodeGen/X86/mingw-comdats.ll
+++ test/CodeGen/X86/mingw-comdats.ll
@@ -60,8 +60,8 @@
 ; Make sure the assembler puts the .xdata and .pdata in sections with the right
 ; names.
 ; GNUOBJ: .text$_Z3fooi
-; GNUOBJ: .xdata$_Z3fooi
 ; GNUOBJ: .data$gv
+; GNUOBJ: .xdata$_Z3fooi
 ; GNUOBJ: .pdata$_Z3fooi
 
 declare dso_local i32 @_Z3bari(i32)
Index: test/CodeGen/X86/mingw-comdats-xdata.ll
===================================================================
--- test/CodeGen/X86/mingw-comdats-xdata.ll
+++ test/CodeGen/X86/mingw-comdats-xdata.ll
@@ -54,18 +54,17 @@
 
 ; GNU: .section        .text$_Z3fooi,"xr",discard,_Z3fooi
 ; GNU: _Z3fooi:
-; GNU: .section        .xdata$_Z3fooi,"dr"
-; GNU: .linkonce       discard
+; GNU: .section        .xdata$_Z3fooi,"dr",associative,_Z3fooi
 ; GNU: GCC_except_table1:
 ; GNU: .section        .data$gv,"dw",discard,gv
 ; GNU: gv:
 ; GNU: .long 42
 
 ; Make sure the assembler puts the .xdata and .pdata in sections with the right
 ; names.
 ; GNUOBJ: .text$_Z3fooi
-; GNUOBJ: .xdata$_Z3fooi
 ; GNUOBJ: .data$gv
+; GNUOBJ: .xdata$_Z3fooi
 ; GNUOBJ: .pdata$_Z3fooi
 
 declare dso_local i32 @_Z3bari(i32)
Index: lib/MC/MCStreamer.cpp
===================================================================
--- lib/MC/MCStreamer.cpp
+++ lib/MC/MCStreamer.cpp
@@ -682,18 +682,21 @@
   if (TextSecCOFF->getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
     KeySym = TextSecCOFF->getCOMDATSymbol();
 
-    // In a GNU environment, we can't use associative comdats. Instead, do what
-    // GCC does, which is to make plain comdat selectany section named like
-    // ".[px]data$_Z3foov".
+    // In a GNU environment, we can't rely on associative comdats. Instead, do
+    // almost what GCC does, which is to make plain comdat selectany section
+    // named like ".[px]data$_Z3foov". We make them associative though, to help
+    // LLD keep them if the function itself is kept, while the symbol suffixed
+    // section name is enough for make things work for ld.bfd.
     if (!Context.getAsmInfo()->hasCOFFAssociativeComdats()) {
       std::string SectionName =
           (MainCFISecCOFF->getSectionName() + "$" +
            TextSecCOFF->getSectionName().split('$').second)
               .str();
       return Context.getCOFFSection(
           SectionName,
           MainCFISecCOFF->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT,
-          MainCFISecCOFF->getKind(), "", COFF::IMAGE_COMDAT_SELECT_ANY);
+          MainCFISecCOFF->getKind(), KeySym->getName(),
+          COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE);
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49757.157122.patch
Type: text/x-patch
Size: 2688 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180724/3ffd723d/attachment-0001.bin>


More information about the llvm-commits mailing list