[lld] r344124 - [COFF] Look for libfoo.a if foo.lib is specified, for MinGW
Martin Storsjo via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 10 02:00:11 PDT 2018
Author: mstorsjo
Date: Wed Oct 10 02:00:10 2018
New Revision: 344124
URL: http://llvm.org/viewvc/llvm-project?rev=344124&view=rev
Log:
[COFF] Look for libfoo.a if foo.lib is specified, for MinGW
This allows using #pragma comment(lib, "foo") in MinGW built code,
if built with -fms-extensions. (This works for system libraries and
static libraries only, as it doesn't try to look for .dll.a. As
ld.bfd doesn't support embedded defaultlib directives, this isn't
in widespread use among mingw users.)
Differential Revision: https://reviews.llvm.org/D53017
Added:
lld/trunk/test/COFF/libname-mingw.test
Modified:
lld/trunk/COFF/Driver.cpp
lld/trunk/COFF/Driver.h
Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=344124&r1=344123&r2=344124&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Wed Oct 10 02:00:10 2018
@@ -371,13 +371,30 @@ Optional<StringRef> LinkerDriver::findFi
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
Modified: lld/trunk/COFF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.h?rev=344124&r1=344123&r2=344124&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.h (original)
+++ lld/trunk/COFF/Driver.h Wed Oct 10 02:00:10 2018
@@ -89,6 +89,7 @@ private:
Optional<StringRef> 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();
Added: lld/trunk/test/COFF/libname-mingw.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/libname-mingw.test?rev=344124&view=auto
==============================================================================
--- lld/trunk/test/COFF/libname-mingw.test (added)
+++ lld/trunk/test/COFF/libname-mingw.test Wed Oct 10 02:00:10 2018
@@ -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
More information about the llvm-commits
mailing list