Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport symbol versioning patch from LLVM 4.0 #24890

Closed

Conversation

ihnorton
Copy link
Member

@ihnorton ihnorton commented Dec 3, 2017

Should help with crashes when loading multiple libLLVM versions in
the same process, as happens with mesa/llvmpipe when mesa is
dynamically linked against libLLVM. See

#19606

patch: https://reviews.llvm.org/D31524
commit: https://reviews.llvm.org/rL300496

@vchuravy
Copy link
Member

vchuravy commented Dec 4, 2017

Fantastic! This should help to alleviate issues we have been encountering in OpenCL.jl and other packages, when they loaded libraries that were using a different version of LLVM. I don't think it solves the issue of loading two versions of LLVM that are the same base version (one Julia build with patches, the other one vanilla) so maybe we can use a similar mechanism to add a jl-(pre|suf)fix.

@ihnorton
Copy link
Member Author

ihnorton commented Dec 4, 2017

maybe we can use a similar mechanism to add a jl-(pre|suf)fix.

I think it could be as simple as adding JL_ here:

+--- /dev/null
 ++++ b/tools/llvm-shlib/simple_version_script.map.in
 +@@ -0,0 +1 @@
 ++LLVM_@LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@ { global: *; };

Btw

  • this only helps on GNU LD platforms (which is ok for now, as I believe the problem only manifests there too)
  • RTLD_LOCAL might help in situations where you control dlopen

@maleadt
Copy link
Member

maleadt commented Dec 4, 2017

If it's going to differ between platforms, depending on eg. the linker, we should have a way of accessing the prefix for packages like LLVM.jl to be able to call into Julia's libLLVM.
EDIT: not strictly necessary though, I could just do a bunch of dlsyms to detect the prefix.

@vtjnash
Copy link
Member

vtjnash commented Dec 4, 2017

as I believe the problem only manifests there too

I also believe this is correct. Windows and macOS always identifies symbols by library id (typically equal to the file base name), for performance, and thereby generally avoiding this problem.

@ihnorton ihnorton requested a review from Keno December 6, 2017 18:11
@ihnorton
Copy link
Member Author

ihnorton commented Dec 6, 2017

@Keno this might have implications for Cxx.

@vchuravy
Copy link
Member

I forgot that this patch existed and was about to open my own PR, but instead with https://reviews.llvm.org/D30997 at https://github.com/JuliaLang/julia/tree/vc/vendorllvm

I don't know why LLVM introduced two options to solve the same problem, but my instinct is to prefer this one (#24890) over my patch since it allows us more flexibility.

In any case we should have this for 1.0 since it is a general nuisance on any system that uses LLVM in mesa.

@StefanKarpinski
Copy link
Member

Seems like it just needs a rebase and a review by @vchuravy and it should be good to go.

Should help with crashes when loading multiple libLLVM versions in
the same process, as happens with mesa/llvmpipe when mesa is
dynamically linked against libLLVM. See

  JuliaLang#19606

patch: https://reviews.llvm.org/D31524
commit: https://reviews.llvm.org/rL300496
@ihnorton ihnorton force-pushed the LLVM_D31524_symbolversion_backport branch from 10ce1cc to 912ea1e Compare January 16, 2018 02:14
@ihnorton
Copy link
Member Author

Rebased.

@maleadt
Copy link
Member

maleadt commented Jan 16, 2018

Shouldn't we prefix with JL_LLVM_$X.$Y just to be sure? Given that this is part of upstream, chances are Mesa/... also use this mechanic to prefix with LLVM_$X.$Y

I don't think it solves the issue of loading two versions of LLVM that are the same base version (one Julia build with patches, the other one vanilla) so maybe we can use a similar mechanism to add a jl-(pre|suf)fix.

@ihnorton
Copy link
Member Author

ihnorton commented Jan 16, 2018 via email

@vchuravy
Copy link
Member

vchuravy commented Jan 16, 2018 via email

@vchuravy
Copy link
Member

Ok this is looking good:

> nm -D --with-symbol-versions usr/lib/libjulia.so
...
                 U LLVMInitializeX86AsmParser@LLVM_3.9
                 U LLVMInitializeX86AsmPrinter@LLVM_3.9
                 U LLVMInitializeX86Disassembler@LLVM_3.9
                 U LLVMInitializeX86Target@LLVM_3.9
                 U LLVMInitializeX86TargetInfo@LLVM_3.9
                 U LLVMInitializeX86TargetMC@LLVM_3.9
...

Libraries that are using dynamic symbol lookup are unaffected since it is a version suffix.
So LLVM.jl works out of the box (Cxx.jl isn't working on 0.7 right now) and testing with OpenCL.jl and a LLVM based OpenCL implementation also shows that the common clash is hopefully solved.
JuliaGPU/OpenCL.jl#137 (comment)

I have a patch that adds the JL prefix and will open a new PR with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants