This is an archive of the discontinued LLVM Phabricator instance.

Add version to libLLVM also on non-UNIX
ClosedPublic

Authored by mati865 on Oct 7 2020, 2:25 PM.

Details

Reviewers
hans
mstorsjo
Group Reviewers
Restricted Project
Commits
rGb22bf7e82ae0: [CMake] Add version to libLLVM also on non-UNIX
Summary

As discussed in https://reviews.llvm.org/D87521

llvm-config expects versioned library regardless of platform.

Diff Detail

Event Timeline

mati865 created this revision.Oct 7 2020, 2:25 PM
mati865 requested review of this revision.Oct 7 2020, 2:25 PM
mati865 retitled this revision from Add version to libLLVM also on non UNIX to Add version to libLLVM also on non-UNIX.Oct 7 2020, 3:06 PM
mstorsjo accepted this revision.Jul 3 2021, 2:50 PM

This looks sensible to me (sorry for losing track of it earlier) as discussed in D87521.

I tried it out in a few setups to study it closer and it does seem to work safely. In practice no libraries that are built in MSVC configuration have ARG_SONAME set so this should have little to no effect on those configurations.

I can try to get it pushed in a couple days.

This revision is now accepted and ready to land.Jul 3 2021, 2:50 PM

Thank you for returning to this.
I'd love to get confirmation from @hans who suggested it in https://reviews.llvm.org/D87521 that this still seems like the best approach.

I'll also need to recheck because I have no idea after all this time if import libraries have correct name (without the version) and do work.

Thank you for returning to this.
I'd love to get confirmation from @hans who suggested it in https://reviews.llvm.org/D87521 that this still seems like the best approach.

I'll also need to recheck because I have no idea after all this time if import libraries have correct name (without the version) and do work.

The import libraries do seem to use the right name as far as I can see, but there's another aspect I remembered now: This does create unversioned symlinks too (not while building but once you do ninja install). This probably is neat to have, but for cases when things are packaged up in e.g. zip files or something else that doesn't handle symlinks, one might want not to have them. Within llvm-mingw I guess I can have them stripped out before packaging though.

The import libraries do seem to use the right name as far as I can see, but there's another aspect I remembered now: This does create unversioned symlinks too (not while building but once you do ninja install). This probably is neat to have, but for cases when things are packaged up in e.g. zip files or something else that doesn't handle symlinks, one might want not to have them. Within llvm-mingw I guess I can have them stripped out before packaging though.

Oh, nice. As for unversioned symlinks they would be changed into copies when packaging so we will remove them as well.

The import libraries do seem to use the right name as far as I can see, but there's another aspect I remembered now: This does create unversioned symlinks too (not while building but once you do ninja install). This probably is neat to have, but for cases when things are packaged up in e.g. zip files or something else that doesn't handle symlinks, one might want not to have them. Within llvm-mingw I guess I can have them stripped out before packaging though.

Oh, nice. As for unversioned symlinks they would be changed into copies when packaging so we will remove them as well.

Yep. I guess the question mainly is if we'd want to make this an upstream thing, adding an if(UNIX) around the symlinks on lines 608-613 here, if windows packaging cases would want to omit them anyway?

Yep. I guess the question mainly is if we'd want to make this an upstream thing, adding an if(UNIX) around the symlinks on lines 608-613 here, if windows packaging cases would want to omit them anyway?

I have no idea about guidelines for Windows but it'd make sense for me.

hans added a comment.Jul 5 2021, 5:08 AM

Yep. I guess the question mainly is if we'd want to make this an upstream thing, adding an if(UNIX) around the symlinks on lines 608-613 here, if windows packaging cases would want to omit them anyway?

I have no idea about guidelines for Windows but it'd make sense for me.

I don't know the details of this well enough. How many/what symlinks are we talking about here? If it would add a lot of binary size to the install (since the symlinks would end up being full copies on Windows) it would be nice to avoid, but if it's not big then it's not a problem.

Yep. I guess the question mainly is if we'd want to make this an upstream thing, adding an if(UNIX) around the symlinks on lines 608-613 here, if windows packaging cases would want to omit them anyway?

I have no idea about guidelines for Windows but it'd make sense for me.

I don't know the details of this well enough. How many/what symlinks are we talking about here? If it would add a lot of binary size to the install (since the symlinks would end up being full copies on Windows) it would be nice to avoid, but if it's not big then it's not a problem.

I think in practice, right now no files are affected in MSVC builds at all, as libLLVM isn’t built there. (But there are plans to make it buildable for MSVC configs so it might matter in the future.) The symlinked files are largish, ~50-100 MB. So maybe we should opt out from those symlinks for now, and reconsider if there’s a concrete case where they are needed?

hans added a comment.Jul 5 2021, 5:43 AM

Yep. I guess the question mainly is if we'd want to make this an upstream thing, adding an if(UNIX) around the symlinks on lines 608-613 here, if windows packaging cases would want to omit them anyway?

I have no idea about guidelines for Windows but it'd make sense for me.

I don't know the details of this well enough. How many/what symlinks are we talking about here? If it would add a lot of binary size to the install (since the symlinks would end up being full copies on Windows) it would be nice to avoid, but if it's not big then it's not a problem.

I think in practice, right now no files are affected in MSVC builds at all, as libLLVM isn’t built there. (But there are plans to make it buildable for MSVC configs so it might matter in the future.) The symlinked files are largish, ~50-100 MB. So maybe we should opt out from those symlinks for now, and reconsider if there’s a concrete case where they are needed?

Sounds good to me.

Yep. I guess the question mainly is if we'd want to make this an upstream thing, adding an if(UNIX) around the symlinks on lines 608-613 here, if windows packaging cases would want to omit them anyway?

I have no idea about guidelines for Windows but it'd make sense for me.

@mati865 - Do you want to update the patch with an if(UNIX) around the symlink lines? I think we've got agreement that we can move forward with this, and it'd be nice to have it in before the 13.x branch in a couple weeks.

Yep. I guess the question mainly is if we'd want to make this an upstream thing, adding an if(UNIX) around the symlinks on lines 608-613 here, if windows packaging cases would want to omit them anyway?

I have no idea about guidelines for Windows but it'd make sense for me.

@mati865 - Do you want to update the patch with an if(UNIX) around the symlink lines? I think we've got agreement that we can move forward with this, and it'd be nice to have it in before the 13.x branch in a couple weeks.

Sorry, I have forgotten to add this to my TODO.
I can do it over the weekend, ofc I won't mind if somebody beats it to me.

I had no internet during the weekend (massive storms over here) but so I returned to it yesterday.
I'm unable to build clean main branch at the moment:

`
[2972/3064] Linking CXX shared library bin\libLLVM.dll
FAILED: bin/libLLVM.dll lib/libLLVM.dll.a
cmd.exe /C "cd . && D:\msys64\clang64\bin\c++.exe -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -ffunction-sections -fdata-sections -O3 -DNDEBUG  -Wl,--gc-sections -shared -o bin\libLLVM.dll -Wl,--out-implib,lib\libLLVM.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\LLVM.rsp  && cd ."
lld-link: error: too many exported symbols (max 65535)
`

It's simple change though, should I update diff without testing?

I had no internet during the weekend (massive storms over here) but so I returned to it yesterday.
I'm unable to build clean main branch at the moment:

`
[2972/3064] Linking CXX shared library bin\libLLVM.dll
FAILED: bin/libLLVM.dll lib/libLLVM.dll.a
cmd.exe /C "cd . && D:\msys64\clang64\bin\c++.exe -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -ffunction-sections -fdata-sections -O3 -DNDEBUG  -Wl,--gc-sections -shared -o bin\libLLVM.dll -Wl,--out-implib,lib\libLLVM.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\LLVM.rsp  && cd ."
lld-link: error: too many exported symbols (max 65535)
`

Hmm, that’s a bit of a problem… Such a build does succeed for me at the moment, but I only have the x86, arm and aarch64 targets enabled. Then I end up with around 57k exported symbols from that DLL.

It's simple change though, should I update diff without testing?

That’d be fine with me, I could test building with it.

I don’t have any testcase that would use llvm-config for finding the libs to link though (which is the case that this tries to fix, right?).

mati865 updated this revision to Diff 361256.Jul 23 2021, 9:20 AM

Building only X86 target did the trick and it looks good:

$ ls bin/ | rg libLLVM.*dll
libLLVM-13git.dll

$ ls lib/ | rg libLLVM.*dll
libLLVM-13git.dll.a

$ bin/llvm-config --libs
-lLLVM-13git

Example:

$ cat llvm.cpp
#include <llvm/Target/TargetOptions.h>

void foo() {
    llvm::TargetOptions();
}

$ PATH=/e/tmp/build/bin:$PATH

$ clang++ -shared $(llvm-config --cxxflags --ldflags --libs) llvm.cpp -o llvm.dll

$ ntldd llvm.dll
        libLLVM-13git.dll => E:\tmp\build\bin\libLLVM-13git.dll (0x0000000000830000)
        libc++.dll => D:\msys64\clang64\bin\libc++.dll (0x0000000005b80000)
        KERNEL32.dll => C:\Windows\SYSTEM32\KERNEL32.dll (0x00000000062d0000)
mstorsjo accepted this revision.Jul 23 2021, 9:33 AM

LGTM, I can try to push this a bit later. Thanks for testing!

This revision was landed with ongoing or failed builds.Jul 23 2021, 1:06 PM
This revision was automatically updated to reflect the committed changes.