This is an archive of the discontinued LLVM Phabricator instance.

[cmake] Restrict symbols exported from libclang-cpp
AbandonedPublic

Authored by pirama on Apr 13 2020, 9:49 AM.

Details

Reviewers
beanz
mgorny
Summary

In libclang-cpp, export only symbols from the clang namespace or clang_*
(functions for the C interface). This fixes the use case where a tool
depends on both libclang-cpp and libLLVM. Without this change,
command-line registries from libLLVMSupport are exported by libclang-cpp
and gets deduped with symbols of the same name from libLLVM . But, the
arguments get registered separately from both the libraries during
startup, resulting in an error.

Diff Detail

Event Timeline

pirama created this revision.Apr 13 2020, 9:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 13 2020, 9:49 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I think this has some unintended consequences. If your tool wants to use libLLVM and libClang you really need libClang to be linked against libLLVM, otherwise you're actually just hiding the problem.

I think this has some unintended consequences. If your tool wants to use libLLVM and libClang you really need libClang to be linked against libLLVM, otherwise you're actually just hiding the problem.

I wanted to avoid this since libLLVM is an optional target but libclang-cpp is built by default. Maybe I didn't think through all options in this regard.

  1. We could build libLLVM by default, but don't install it unless requested.
  2. Or link libclang-cpp against libLLVM iff the latter is built.

Either option would require a CMake change that I am not sure how to make. We would need to remove LLVM static libraries from libclang-cpp's link command but I cannot figure out how to accomplish this. They are getting included transitively via CMake's dependency graph.

Another option is to make libclang-cpp a superset of Clang and LLVM libraries. This would however require using --whole-archive similar to libLLVM.so.

Do you have any preferred solution and pointers on how to filter out some dependencies in CMake? One hacky way could be to add a special-case in AddLLVM.cmake and dedup right before target_link_libraries().

pirama abandoned this revision.Dec 2 2022, 9:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 2 2022, 9:50 PM