Skip to content

[Polly] Build failure with shared lib at -O0 and lld #134393

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

Open
aengelke opened this issue Apr 4, 2025 · 3 comments
Open

[Polly] Build failure with shared lib at -O0 and lld #134393

aengelke opened this issue Apr 4, 2025 · 3 comments

Comments

@aengelke
Copy link
Contributor

aengelke commented Apr 4, 2025

Polly uses AllAnalysesOn<Loop>, which has an explicit template instantiation in LoopAnalysisManager.cpp/h. Therefore, there are multiple (weak) definitions for libLLVM.so, the Polly ones are hidden (STV_HIDDEN) due to -fvisibility-inlines-hidden while the explicit instantiation has default visibility. According to the gABI, the non-default visibility wins (implemented by LLD/Gold; with BFD, default wins). The symbol ends up with STV_HIDDEN in libLLVM.so and linking the unit tests therefore fails with undefined symbol: llvm::AllAnalysesOn<llvm::Loop>::ID().

(FWIW, this behavior was implemented in LLD in 78471f0 (2015).)

CMake command: cmake -DLLVM_ENABLE_PROJECTS="polly" -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_BUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE=-O0 -DCMAKE_CXX_FLAGS_RELEASE=-O0 -G Ninja -DLLVM_ENABLE_ASSERTIONS=OFF -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON -DCMAKE_C_COMPILER=clang-19 -DCMAKE_CXX_COMPILER=clang++-19 -DLLVM_USE_LINKER=lld -B llvm-build-tmp -S llvm-project/llvm.

(cc @MaskRay – could we get a warning when a previously default-visible symbol gets hidden? Or are there cases where this is intended?)

@llvmbot
Copy link
Member

llvmbot commented Apr 4, 2025

@llvm/issue-subscribers-polly

Author: Alexis Engelke (aengelke)

Polly uses `AllAnalysesOn<Loop>`, which has an explicit template instantiation in LoopAnalysisManager.cpp/h. Therefore, there are multiple (weak) definitions for libLLVM.so, the Polly ones are hidden (`STV_HIDDEN`) due to `-fvisibility-inlines-hidden` while the explicit instantiation has default visibility. According to the gABI, the non-default visibility wins (implemented by LLD/Gold; with BFD, default wins). The symbol ends up with `STV_HIDDEN` in libLLVM.so and linking the unit tests therefore fails with `undefined symbol: llvm::AllAnalysesOn<llvm::Loop>::ID()`.

(FWIW, this behavior was implemented in LLD in 78471f0 (2015).)

CMake command: cmake -DLLVM_ENABLE_PROJECTS="polly" -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_BUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE=-O0 -DCMAKE_CXX_FLAGS_RELEASE=-O0 -G Ninja -DLLVM_ENABLE_ASSERTIONS=OFF -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON -DCMAKE_C_COMPILER=clang-19 -DCMAKE_CXX_COMPILER=clang++-19 -DLLVM_USE_LINKER=lld -B llvm-build-tmp -S llvm-project/llvm.

(cc @MaskRay – could we get a warning when a previously default-visible symbol gets hidden? Or are there cases where this is intended?)

@MaskRay
Copy link
Member

MaskRay commented Apr 6, 2025

According to the gABI, the non-default visibility wins (implemented by LLD/Gold; with BFD, default wins).

GNU ld doesn't behave differently from gold / LLD. The non-default visibility wins per gABI

If different visibility attributes are specified for distinct references to or definitions of a symbol, the most constraining visibility attribute must be propagated to the resolving symbol in the linked object. The attributes, ordered from least to most constraining, are: STV_PROTECTED, STV_HIDDEN and STV_INTERNAL.

This is an intended behavior and allows users to constrain a symbol. I don't think we could implement a warning...

@Meinersbur
Copy link
Member

This problem doesn't seem Polly-specific, but applies to any NPM pass plugin.

Anyway, use of AllAnalysisOn<Loop> in Polly will be removed in #125783.

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

No branches or pull requests

5 participants
@MaskRay @Meinersbur @aengelke @llvmbot and others