[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
This commit is contained in:
Martin Storsjö 2021-04-29 11:57:33 +03:00
parent 8f5a2a5836
commit 2b01a417d7
2 changed files with 8 additions and 1 deletions

View File

@ -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,

View File

@ -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@12:
ret
@ -29,6 +33,9 @@ _foobar:
ret
_unexported:
ret
.section .text@_comdatFunc,"xr",one_only,_comdatFunc
_comdatFunc:
ret
.data
_dataSym:
.int 4