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

[CIR] Fix tests with LLVM_LINK_LLVM_DYLIB #1222

Merged
merged 2 commits into from
Dec 12, 2024
Merged

Conversation

smeenai
Copy link
Collaborator

@smeenai smeenai commented Dec 11, 2024

This option creates and links all tools against a single libLLVM shared
library (and the corresponding CLANG_LINK_CLANG_DYLIB option also gets
turned on by default). In order for this to work, we need to use
LINK_COMPONENTS instead of LINK_LIBS for all LLVM dependencies, and
clang_target_link_libraries for all Clang dependencies, so that they get
rewritten to use the dylib. Remove llvm_update_compile_flags while I'm
here, since the build macros handle that internally. Before this change,
we'd link against certain LLVM libraries both statically and
dynamically, leading to test failures from duplicate singletons.

The way this works for MLIR is fragile right now: MLIR can create its
own dylib as well but doesn't have build system support for linking
against that dylib. We end up folding the MLIR libraries into
libclang-cpp.so (because all Clang dependencies get pulled into it), but
MLIR tools still link the MLIR libraries statically. It'll still work,
but BUILD_SHARED_LIBS is possibly a better alternative for development.
Distributions like Fedora build their LLVM packages with
LLVM_LINK_LLVM_DYLIB, so we'll want to eventually have good MLIR support
for that setup too.

This option creates and links all tools against a single libLLVM shared
library (and the corresponding CLANG_LINK_CLANG_DYLIB option also gets
turned on by default). In order for this to work, we need to use
LINK_COMPONENTS instead of LINK_LIBS for all LLVM dependencies, and
clang_target_link_libraries for all Clang dependencies, so that they get
rewritten to use the dylib. Remove llvm_update_compile_flags while I'm
here, since the build macros handle that internally. Before this change,
we'd link against certain LLVM libraries both statically and
dynamically, leading to test failures from duplicate singletons.

The way this works for MLIR is fragile right now: MLIR can create its
own dylib as well but doesn't have build system support for linking
against that dylib. We end up folding the MLIR libraries into
libclang-cpp.so (because all Clang dependencies get pulled into it), but
MLIR tools still link the MLIR libraries statically. It'll still work,
but BUILD_SHARED_LIBS is possibly a better alternative for development.
Distributions like Fedora build their LLVM packages with
LLVM_LINK_LLVM_DYLIB, so we'll want to eventually have good MLIR support
for that setup too.
@smeenai
Copy link
Collaborator Author

smeenai commented Dec 11, 2024

CC @keryell

Copy link
Collaborator

@keryell keryell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@bcardosolopes bcardosolopes merged commit d1d43f0 into llvm:main Dec 12, 2024
6 checks passed
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.

3 participants