Index: COFF/MinGW.cpp =================================================================== --- COFF/MinGW.cpp +++ COFF/MinGW.cpp @@ -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" @@ -99,6 +100,13 @@ return false; 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. Index: test/COFF/export-all.s =================================================================== --- test/COFF/export-all.s +++ test/COFF/export-all.s @@ -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.