[COFF] Don't export symbols that have corresponding __imp_ symbols
GNU ld has got an exception for such symbols, and mingw-w64 occasionally uses that exception to avoid exporting symbols in cases where they otherwise aren't caught by the other exclusion mechanisms. Differential Revision: https://reviews.llvm.org/D40553 llvm-svn: 319291
This commit is contained in:
parent
1b99926061
commit
0010707e1c
|
@ -8,6 +8,7 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "MinGW.h"
|
||||
#include "SymbolTable.h"
|
||||
#include "lld/Common/ErrorHandler.h"
|
||||
#include "llvm/Object/COFF.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
|
@ -100,6 +101,15 @@ bool AutoExporter::shouldExport(Defined *Sym) const {
|
|||
if (ExcludeSymbols.count(Sym->getName()))
|
||||
return false;
|
||||
|
||||
// Don't export anything that looks like an import symbol (which also can be
|
||||
// a manually defined data symbol with such a name).
|
||||
if (Sym->getName().startswith("__imp_"))
|
||||
return false;
|
||||
|
||||
// If a corresponding __imp_ symbol exists and is defined, don't export it.
|
||||
if (Symtab->find(("__imp_" + Sym->getName()).str()))
|
||||
return false;
|
||||
|
||||
// Check that file is non-null before dereferencing it, symbols not
|
||||
// originating in regular object files probably shouldn't be exported.
|
||||
if (!Sym->getFile())
|
||||
|
|
|
@ -7,8 +7,10 @@
|
|||
# RUN: llvm-readobj %t.lib | FileCheck -check-prefix=IMPLIB %s
|
||||
|
||||
# CHECK-NOT: Name: DllMainCRTStartup
|
||||
# CHECK-NOT: Name: _imp__unexported
|
||||
# CHECK: Name: dataSym
|
||||
# CHECK: Name: foobar
|
||||
# CHECK-NOT: Name: unexported
|
||||
|
||||
# IMPLIB: Symbol: __imp__dataSym
|
||||
# IMPLIB-NOT: Symbol: _dataSym
|
||||
|
@ -18,14 +20,20 @@
|
|||
.global _foobar
|
||||
.global _DllMainCRTStartup@12
|
||||
.global _dataSym
|
||||
.global _unexported
|
||||
.global __imp__unexported
|
||||
.text
|
||||
_DllMainCRTStartup@12:
|
||||
ret
|
||||
_foobar:
|
||||
ret
|
||||
_unexported:
|
||||
ret
|
||||
.data
|
||||
_dataSym:
|
||||
.int 4
|
||||
__imp__unexported:
|
||||
.int _unexported
|
||||
|
||||
# Test specifying -export-all-symbols, on an object file that contains
|
||||
# dllexport directive for some of the symbols.
|
||||
|
|
Loading…
Reference in New Issue