This is an archive of the discontinued LLVM Phabricator instance.

Fix llvm-config --link-shared --libs for mingw
Needs ReviewPublic

Authored by tkelman on Jan 7 2017, 4:05 AM.

Details

Summary

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.

Diff Detail

Event Timeline

tkelman updated this revision to Diff 83524.Jan 7 2017, 4:05 AM
tkelman retitled this revision from to Fix llvm-config --link-shared --libs for mingw.
tkelman updated this object.
tkelman added reviewers: beanz, chapuni, mgorny, compnerd.
tkelman added a subscriber: llvm-commits.
mgorny resigned from this revision.Jan 9 2017, 2:38 PM
mgorny edited reviewers, added: rnk; removed: mgorny.

Sorry, I know very little of Windows.

beanz edited edge metadata.Jan 9 2017, 4:33 PM

This looks reasonable, can you please add a test case?

Didn't get notified about your review, whoops. Where would this get tested? Won't it need one of the buildbots to be building a dll with mingw?

beanz added a comment.Jan 17 2017, 2:00 PM

I'm pretty confident we have buildbots testing mingw. You should be able to add a test case under tests/tools/llvm-config and have REQUIRES: mingw32 in it.

With shared libs enabled? That's only worked for a couple of months, since https://reviews.llvm.org/D25865. I'll try to figure out how the tests work.

beanz added a comment.Jan 17 2017, 2:46 PM

Ah... don't know if we have one with shared libs enabled, but adding a test is still good. You probably need a new available feature added to lit for checking the dylib. In case you're unsure how to do that I wrote it up real quick and put it in a paste (https://reviews.llvm.org/P7962).

Basically with that you can write a test that has REQUIRES: mingw32,libllvm and it should only run when the dll is generated on mingw build hosts. Hope that helps.