Index: lld/trunk/COFF/Driver.h =================================================================== --- lld/trunk/COFF/Driver.h +++ lld/trunk/COFF/Driver.h @@ -89,6 +89,7 @@ Optional findLib(StringRef Filename); StringRef doFindFile(StringRef Filename); StringRef doFindLib(StringRef Filename); + StringRef doFindLibMinGW(StringRef Filename); // Parses LIB environment which contains a list of search paths. void addLibSearchPaths(); Index: lld/trunk/COFF/Driver.cpp =================================================================== --- lld/trunk/COFF/Driver.cpp +++ lld/trunk/COFF/Driver.cpp @@ -371,13 +371,30 @@ return Path; } +// MinGW specific. If an embedded directive specified to link to +// foo.lib, but it isn't found, try libfoo.a instead. +StringRef LinkerDriver::doFindLibMinGW(StringRef Filename) { + if (Filename.contains('/') || Filename.contains('\\')) + return Filename; + + SmallString<128> S = Filename; + sys::path::replace_extension(S, ".a"); + StringRef LibName = Saver.save("lib" + S.str()); + return doFindFile(LibName); +} + // Find library file from search path. StringRef LinkerDriver::doFindLib(StringRef Filename) { // Add ".lib" to Filename if that has no file extension. bool HasExt = Filename.contains('.'); if (!HasExt) Filename = Saver.save(Filename + ".lib"); - return doFindFile(Filename); + StringRef Ret = doFindFile(Filename); + // For MinGW, if the find above didn't turn up anything, try + // looking for a MinGW formatted library name. + if (Config->MinGW && Ret == Filename) + return doFindLibMinGW(Filename); + return Ret; } // Resolves a library path. /nodefaultlib options are taken into Index: lld/trunk/test/COFF/libname-mingw.test =================================================================== --- lld/trunk/test/COFF/libname-mingw.test +++ lld/trunk/test/COFF/libname-mingw.test @@ -0,0 +1,8 @@ +# RUN: mkdir -p %t/a +# RUN: cp %p/Inputs/std64.lib %t/a/libstd64.a + +# RUN: lld-link /lldmingw /out:%t.exe /entry:main /verbose \ +# RUN: /defaultlib:std64.lib /subsystem:console %p/Inputs/hello64.obj \ +# RUN: /libpath:%t/a 2>&1 | FileCheck %s + +CHECK: a{{[/\\]}}libstd64.a