[lld] 2b01a41 - [LLD] [COFF] Fix the mingw --export-all-symbols behaviour with comdat symbols

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 29 13:35:37 PDT 2021


Author: Martin Storsjö
Date: 2021-04-29T23:35:10+03:00
New Revision: 2b01a417d7ccb001ccc1185ef5fdc967c9fac8d7

URL: https://github.com/llvm/llvm-project/commit/2b01a417d7ccb001ccc1185ef5fdc967c9fac8d7
DIFF: https://github.com/llvm/llvm-project/commit/2b01a417d7ccb001ccc1185ef5fdc967c9fac8d7.diff

LOG: [LLD] [COFF] Fix the mingw --export-all-symbols behaviour with comdat symbols

When looking for the "all" symbols that are supposed to be exported,
we can't look at the live flag - the symbols we mark as to be
exported will become GC roots even if they aren't yet marked as live.

With this in place, building an LLVM library with BUILD_SHARED_LIBS
produces the same set of symbols exported regardless of whether the
--gc-sections flag is specified, both with and without being built
with -ffunction-sections.

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

Added: 
    

Modified: 
    lld/COFF/MinGW.cpp
    lld/test/COFF/export-all.s

Removed: 
    


################################################################################
diff  --git a/lld/COFF/MinGW.cpp b/lld/COFF/MinGW.cpp
index 5bb7467afe5e9..7c1891e67d45e 100644
--- a/lld/COFF/MinGW.cpp
+++ b/lld/COFF/MinGW.cpp
@@ -123,7 +123,7 @@ void AutoExporter::addWholeArchive(StringRef path) {
 }
 
 bool AutoExporter::shouldExport(Defined *sym) const {
-  if (!sym || !sym->isLive() || !sym->getChunk())
+  if (!sym || !sym->getChunk())
     return false;
 
   // Only allow the symbol kinds that make sense to export; in particular,

diff  --git a/lld/test/COFF/export-all.s b/lld/test/COFF/export-all.s
index 42bcbbc49e398..ff0f087a84adc 100644
--- a/lld/test/COFF/export-all.s
+++ b/lld/test/COFF/export-all.s
@@ -7,10 +7,13 @@
 # RUN: llvm-readobj %t.lib | FileCheck -check-prefix=IMPLIB %s
 
 # CHECK: Name:
+# CHECK-NEXT: Name: comdatFunc
 # CHECK-NEXT: Name: dataSym
 # CHECK-NEXT: Name: foobar
 # CHECK-EMPTY:
 
+# IMPLIB: Symbol: __imp__comdatFunc
+# IMPLIB: Symbol: _comdatFunc
 # IMPLIB: Symbol: __imp__dataSym
 # IMPLIB-NOT: Symbol: _dataSym
 # IMPLIB: Symbol: __imp__foobar
@@ -22,6 +25,7 @@
 .global _unexported
 .global __imp__unexported
 .global .refptr._foobar
+.global _comdatFunc
 .text
 _DllMainCRTStartup at 12:
   ret
@@ -29,6 +33,9 @@ _foobar:
   ret
 _unexported:
   ret
+.section .text at _comdatFunc,"xr",one_only,_comdatFunc
+_comdatFunc:
+  ret
 .data
 _dataSym:
   .int 4


        


More information about the llvm-commits mailing list