[PATCH] D53017: [LLD] [COFF] Look for libfoo.a and libfoo.dll.a, if foo.lib is specified as defaultlibrary, for MinGW
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 9 01:26:46 PDT 2018
mstorsjo created this revision.
mstorsjo added reviewers: rnk, smeenai, ruiu.
This allows using #pragma comment(lib, "foo") in MinGW built code, if built with -fms-extensions.
This is an alternative to the mingw specific logic in https://reviews.llvm.org/D53013 or https://reviews.llvm.org/D53015. This currently tries to check for both libfoo.dll.a and libfoo.a; ideally we should maybe pass an indication from the MinGW frontend about whether we want to only link statically or not.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D53017
Files:
COFF/Driver.cpp
test/COFF/libname-mingw.test
Index: test/COFF/libname-mingw.test
===================================================================
--- /dev/null
+++ test/COFF/libname-mingw.test
@@ -0,0 +1,15 @@
+# RUN: mkdir -p %t/a
+# RUN: cp %p/Inputs/std64.lib %t/a/libstd64.a
+# RUN: cp %p/Inputs/std64.lib %t/a/libdynamic.dll.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
+
+# RUN: lld-link /lldmingw /out:%t.exe /entry:main /verbose \
+# RUN: /defaultlib:dynamic.lib /subsystem:console %p/Inputs/hello64.obj \
+# RUN: /libpath:%t/a 2>&1 | FileCheck -check-prefix DYNAMIC %s
+
+DYNAMIC: a{{[/\\]}}libdynamic.dll.a
Index: COFF/Driver.cpp
===================================================================
--- COFF/Driver.cpp
+++ COFF/Driver.cpp
@@ -377,7 +377,27 @@
bool HasExt = Filename.contains('.');
if (!HasExt)
Filename = Saver.save(Filename + ".lib");
- return doFindFile(Filename);
+ StringRef Ret = doFindFile(Filename);
+ if (Config->MinGW && Ret == Filename && HasExt && !Filename.contains('/') &&
+ !Filename.contains('\\')) {
+ std::string LibName = "lib";
+ LibName += Filename.substr(0, Filename.rfind('.'));
+ LibName += ".dll.a";
+ StringRef LibNameRef = Saver.save(LibName);
+ StringRef Ret2 = doFindFile(LibNameRef);
+ // TODO: If the user passed -static to the MinGW frontend, we shouldn't
+ // check for .dll.a.
+ if (Ret2 != LibNameRef)
+ return Ret2;
+ LibName = "lib";
+ LibName += Filename.substr(0, Filename.rfind('.'));
+ LibName += ".a";
+ LibNameRef = Saver.save(LibName);
+ Ret2 = doFindFile(LibNameRef);
+ if (Ret2 != LibNameRef)
+ return Ret2;
+ }
+ return Ret;
}
// Resolves a library path. /nodefaultlib options are taken into
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53017.168757.patch
Type: text/x-patch
Size: 1874 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181009/b8662ff0/attachment.bin>
More information about the llvm-commits
mailing list