Index: COFF/MinGW.cpp =================================================================== --- COFF/MinGW.cpp +++ COFF/MinGW.cpp @@ -91,8 +91,12 @@ bool AutoExporter::shouldExport(Defined *Sym) const { if (!Sym || !Sym->isLive() || !Sym->getChunk()) return false; + if (!isa(Sym) && !isa(Sym)) + return false; if (ExcludeSymbols.count(Sym->getName())) return false; + if (!Sym->getFile()) + return false; StringRef LibName = sys::path::filename(Sym->getFile()->ParentName); // Drop the file extension. LibName = LibName.substr(0, LibName.rfind('.')); Index: test/COFF/export-all.s =================================================================== --- test/COFF/export-all.s +++ test/COFF/export-all.s @@ -65,3 +65,14 @@ # CHECK-EXCLUDE: EXPORTS # CHECK-EXCLUDE-NEXT: foobar @1 # CHECK-EXCLUDE-NEXT: EOF + +# Test that we handle import libraries together with -opt:noref. + +# RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj +# RUN: lld-link -lldmingw -dll -out:%t.dll -entry:main@0 %t.obj -implib:%t.lib -opt:noref %p/Inputs/std32.lib -output-def:%t.def +# RUN: echo "EOF" >> %t.def +# RUN: cat %t.def | FileCheck -check-prefix=CHECK-IMPLIB %s + +# CHECK-IMPLIB: EXPORTS +# CHECK-IMPLIB-NEXT: main@0 @1 +# CHECK-IMPLIB-NEXT: EOF