[PATCH] D28446: Fix llvm-config --link-shared --libs for mingw

Tony Kelman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 7 04:05:49 PST 2017


tkelman created this revision.
tkelman added reviewers: beanz, chapuni, mgorny, compnerd.
tkelman added a subscriber: llvm-commits.

On mingw, the llvm shlib gets built without a prefix or version suffix as just LLVM.dll, see
https://github.com/llvm-mirror/llvm/blob/edd4534a45df348c4ae87cfa8d08e719ae0c7085/cmake/modules/AddLLVM.cmake#L453-L471

llvm-config looks for and fails to find LLVM-3.9.dll, giving
$ ./llvm-config.exe --link-shared --libs
llvm-config: error: LLVM-3.9.dll is missing

I've fixed this by modifying SharedVersionedExt (and moving where the "-" for the version gets set).
That makes llvm-config look for the right file name and find it, but because the
GetComponentLibraryNameSlice function only checks Lib.startswith("lib") to determine
whether or not to remove both prefix and extension, it would output -lLLVM.dll which the
mingw linker doesn't handle correctly. Fixed that by making GetComponentLibraryNameSlice
check Lib.startswith(SharedPrefix), so now the output is just -lLLVM which links correctly.


https://reviews.llvm.org/D28446

Files:
  tools/llvm-config/llvm-config.cpp


Index: tools/llvm-config/llvm-config.cpp
===================================================================
--- tools/llvm-config/llvm-config.cpp
+++ tools/llvm-config/llvm-config.cpp
@@ -351,7 +351,7 @@
   const Triple HostTriple(Triple::normalize(LLVM_HOST_TRIPLE));
   if (HostTriple.isOSWindows()) {
     SharedExt = "dll";
-    SharedVersionedExt = LLVM_DYLIB_VERSION ".dll";
+    SharedVersionedExt = ".dll";
     if (HostTriple.isOSCygMing()) {
       StaticExt = "a";
       StaticPrefix = "lib";
@@ -370,14 +370,14 @@
     StaticDir = ActiveLibDir;
   } else if (HostTriple.isOSDarwin()) {
     SharedExt = "dylib";
-    SharedVersionedExt = LLVM_DYLIB_VERSION ".dylib";
+    SharedVersionedExt = "-" LLVM_DYLIB_VERSION ".dylib";
     StaticExt = "a";
     StaticDir = SharedDir = ActiveLibDir;
     StaticPrefix = SharedPrefix = "lib";
   } else {
     // default to the unix values:
     SharedExt = "so";
-    SharedVersionedExt = LLVM_DYLIB_VERSION ".so";
+    SharedVersionedExt = "-" LLVM_DYLIB_VERSION ".so";
     StaticExt = "a";
     StaticDir = SharedDir = ActiveLibDir;
     StaticPrefix = SharedPrefix = "lib";
@@ -390,7 +390,7 @@
 
   bool DyLibExists = false;
   const std::string DyLibName =
-      (SharedPrefix + "LLVM-" + SharedVersionedExt).str();
+      (SharedPrefix + "LLVM" + SharedVersionedExt).str();
 
   // If LLVM_LINK_DYLIB is ON, the single shared library will be returned
   // for "--libs", etc, if they exist. This behaviour can be overridden with
@@ -416,7 +416,7 @@
   /// extension. Returns true if Lib is in a recognized format.
   auto GetComponentLibraryNameSlice = [&](const StringRef &Lib,
                                           StringRef &Out) {
-    if (Lib.startswith("lib")) {
+    if (Lib.startswith(SharedPrefix)) {
       unsigned FromEnd;
       if (Lib.endswith(StaticExt)) {
         FromEnd = StaticExt.size() + 1;
@@ -427,7 +427,7 @@
       }
 
       if (FromEnd != 0) {
-        Out = Lib.slice(3, Lib.size() - FromEnd);
+        Out = Lib.slice(SharedPrefix.size(), Lib.size() - FromEnd);
         return true;
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28446.83524.patch
Type: text/x-patch
Size: 2097 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170107/c014983d/attachment.bin>


More information about the llvm-commits mailing list