Page MenuHomePhabricator

CMake: Add LLVM_DYLIB_SYMBOL_VERSIONING option
ClosedPublic

Authored by tstellar on Mar 15 2017, 1:19 PM.

Details

Summary

When apps or other libraries link against a library with symbol
versions, the version string is recorded in the import table, and used
at runtime to resolve the symbol back to a library that provides that
version (vaguely like how two-level namespaces work in Mach-O). ld's
--default-symver flag tags every exported symbol with a symbol version
string equal to the library's soname. Using --default-symver means
multiple versions of libLLVM can coexist within the same process, at
least to the extent that they don't try to pass data between each
other's llvms.

As an example, imagine a language like Rust using llvm for CPU codegen,
binding to OpenGL, with Mesa as the OpenGL implementation using llvm for
R600 codegen. With --default-symver Rust and Mesa will resolve their
llvm usage to the version each was linked against, which need not match.

(Other ELF platforms like BSD and Solaris might have similar semantics,
I've not checked.)

This is based on an autoconf version of this patch by Adam Jackson.

This new option can be used to add --default-symver to the linker flags
for libLLVM.so.

Diff Detail

Repository
rL LLVM

Event Timeline

tstellar created this revision.Mar 15 2017, 1:19 PM
  1. Any reason not to use this for all shared libraries?
  2. AFAICS --default-symver is present on FreeBSD as well.
beanz accepted this revision.Mar 17 2017, 3:36 PM

@mgorny, we should only support this on shared libraries that we intend as vended libraries, not all libraries. For example we don't really want to support the CMake BUILD_SHARED_LIBS option's libraries as vended libraries on any platform.

This patch LGTM as-is.

This revision is now accepted and ready to land.Mar 17 2017, 3:36 PM

@mgorny, we should only support this on shared libraries that we intend as vended libraries, not all libraries. For example we don't really want to support the CMake BUILD_SHARED_LIBS option's libraries as vended libraries on any platform.

Would it hurt to have it there? Now that Gentoo slots all the shared libraries, I guess we could end up in a corner case like the one mentioned.

This revision was automatically updated to reflect the committed changes.
foutrelis added a subscriber: foutrelis.EditedMay 10 2018, 6:51 PM

Apologies for the random a-year-later comment, but how does this relate to D31524 (which already seems to version libLLVM.so's symbols)?

(Inquiring because I was asked to enable this option downstream in Arch Linux, but AFAICS our libLLVM.so has been versioned since LLVM 5.)

Apologies for the random a-year-later comment, but how does this relate to D31524 (which already seems to version libLLVM.so's symbols)?

(Inquiring because I was asked to enable this option downstream in Arch Linux, but AFAICS our libLLVM.so has been versioned since LLVM 5.)

I think this option should be dropped. When I added it, I was unaware of D31524, which was being developed at the same time.

I think this option should be dropped. When I added it, I was unaware of D31524, which was being developed at the same time.

Thanks for clarifying that it's not needed; I thought I could be missing some use case for it (e.g. platforms other than Linux, BSD).

Removing it would be great so as to avoid confusion about it (and possibly libLLVM.so symbols being versioned differently than LLVM_x.y if the option is enabled).