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

Link error compiling with gcc #234

Closed
VoxSciurorum opened this issue Jan 17, 2024 · 7 comments · Fixed by #236
Closed

Link error compiling with gcc #234

VoxSciurorum opened this issue Jan 17, 2024 · 7 comments · Fixed by #236
Labels
bug Something isn't working

Comments

@VoxSciurorum
Copy link
Contributor

Building OpenCilk with gcc (11 or 13) fails with an error linking bugpoint:

/usr/local/bin/ld: ../../lib/libLLVMTapirOpts.a(LoweringUtils.cpp.o): in function `llvm::createHelperForTaskFrame(llvm::Function&, llvm::Spindle*, llvm::SetVector<llvm::Value*, std::vector<llvm::Value*, std::allocator<llvm::Value*> >, llvm::DenseSet<llvm::Value*, llvm::DenseMapInfo<llvm::Value*, void> >, 0u>&, llvm::Module*, llvm::ValueMap<llvm::Value const*, llvm::WeakTrackingVH, llvm::ValueMapConfig<llvm::Value const*, llvm::sys::SmartMutex<false> > >&, llvm::Type*, llvm::OutlineAnalysis&) [clone .localalias]':
LoweringUtils.cpp:(.text._ZN4llvm24createHelperForTaskFrameERNS_8FunctionEPNS_7SpindleERNS_9SetVectorIPNS_5ValueESt6vectorIS6_SaIS6_EENS_8DenseSetIS6_NS_12DenseMapInfoIS6_vEEEELj0EEEPNS_6ModuleERNS_8ValueMapIPKS5_NS_14WeakTrackingVHENS_14ValueMapConfigISK_NS_3sys10SmartMutexILb0EEEEEEEPNS_4TypeERNS_15OutlineAnalysisE+0x112c): undefined reference to `llvm::computeFunctionBodyMemoryAccess(llvm::Function&, llvm::AAResults&)'
/usr/local/bin/ld: ../../lib/libLLVMTapirOpts.a(LoweringUtils.cpp.o): in function `llvm::createHelperForTask(llvm::Function&, llvm::Task*, llvm::SetVector<llvm::Value*, std::vector<llvm::Value*, std::allocator<llvm::Value*> >, llvm::DenseSet<llvm::Value*, llvm::DenseMapInfo<llvm::Value*, void> >, 0u>&, llvm::Module*, llvm::ValueMap<llvm::Value const*, llvm::WeakTrackingVH, llvm::ValueMapConfig<llvm::Value const*, llvm::sys::SmartMutex<false> > >&, llvm::Type*, llvm::OutlineAnalysis&) [clone .localalias]':
LoweringUtils.cpp:(.text._ZN4llvm19createHelperForTaskERNS_8FunctionEPNS_4TaskERNS_9SetVectorIPNS_5ValueESt6vectorIS6_SaIS6_EENS_8DenseSetIS6_NS_12DenseMapInfoIS6_vEEEELj0EEEPNS_6ModuleERNS_8ValueMapIPKS5_NS_14WeakTrackingVHENS_14ValueMapConfigISK_NS_3sys10SmartMutexILb0EEEEEEEPNS_4TypeERNS_15OutlineAnalysisE+0xa73): undefined reference to `llvm::computeFunctionBodyMemoryAccess(llvm::Function&, llvm::AAResults&)'
collect2: error: ld returned 1 exit status

The problem is libLLVMTapirOpts.a (where llvm::computeFunctionBodyMemoryAccess is used) appears on the command line after libLLVMipo.a (where it is defined). Reordering the LLVM_LINK_COMPONENTS list in llvm/tools/bugpoint/CMakeLists.txt fixes the problem. That is not really the right solution because the list is alphabetical. It may be necessary to reimplement as much of computeFunctionBodyMemoryAccess as is needed within the Tapir components. It is otherwise not called outside of the files in libLLVMipo.a.

gcc interposes the collect2 pass between command line and linker. That may explain why building with clang works.

@VoxSciurorum VoxSciurorum added the bug Something isn't working label Jan 17, 2024
@neboat
Copy link
Collaborator

neboat commented Jan 17, 2024

I think there's something else going on on your system that's triggering this link error. I just built OpenCilk on two different Linux systems, using gcc 11 on one and gcc 13 on the other. Both builds completed without issue.

@VoxSciurorum
Copy link
Contributor Author

I can reproduce this on two Linux systems including SuperCloud. It is enough to use the system linker. I reproduced the failure with clang.

On a Linux virtual machine running

$ uname -a
Linux monax-ubuntu 5.15.0-76-generic #83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
$ ld --version
GNU ld (GNU Binutils for Ubuntu) 2.38

configured like

cmake -DCMAKE_C_COMPILER=clang-15 -DCMAKE_CXX_COMPILER=clang++-15 -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_ENABLE_RUNTIMES=compiler-rt\;cheetah\;cilktools -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;PowerPC;RISCV;X86" -DLLVM_ENABLE_ASSERTIONS=On -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS='-march=znver2 -mtune=znver2' /home/jfc/Cilk/opencilk-project/llvm

and opencilk-project at revision 14f9bbe
my build fails with

LoweringUtils.cpp:(.text._ZN4llvm24createHelperForTaskFrameERNS_8FunctionEPNS_7SpindleERNS_9SetVectorIPNS_5ValueESt6vectorIS6_SaIS6_EENS_8DenseSetIS6_NS_12DenseMapInfoIS6_vEEEELj0EEEPNS_6ModuleERNS_8ValueMapIPKS5_NS_14WeakTrackingVHENS_14ValueMapConfigISK_NS_3sys10SmartMutexILb0EEEEEEEPNS_4TypeERNS_15OutlineAnalysisE+0x1cf0): undefined reference to `llvm::computeFunctionBodyMemoryAccess(llvm::Function&, llvm::AAResults&)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [tools/bugpoint/CMakeFiles/bugpoint.dir/build.make:306: bin/bugpoint] Error 1

@neboat
Copy link
Collaborator

neboat commented Jan 22, 2024

I also tested things on Supercloud, using the default GCC version and system linker there, and I encountered no issues.

On Supercloud, did you configure your CMake build the same way as you described in your previous message?

@VoxSciurorum
Copy link
Contributor Author

I ran this command on a SuperCloud compute node:

cmake -DCMAKE_C_COMPILER=clang-14 -DCMAKE_CXX_COMPILER=clang++-14 -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_ENABLE_RUNTIMES=compiler-rt\;cheetah\;cilktools -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;PowerPC;RISCV;X86" -DLLVM_ENABLE_ASSERTIONS=On -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS='-march=skylake -mtune=skylake' /home/gridsan/jfc/Cilk/opencilk-project/llvm

and the error repeated. Differences are clang 14 instead of clang 15 (which is not on the compute nodes, only the login node) and architecture-specific tuning flags.

@neboat
Copy link
Collaborator

neboat commented Jan 22, 2024

While I try and replicate the error on my end, can you see whether this patch resolves the issue on your end?

diff --git a/llvm/lib/Transforms/Tapir/CMakeLists.txt b/llvm/lib/Transforms/Tapir/CMakeLists.txt
index b7b4cbe9af5f..43a684436bd5 100644
--- a/llvm/lib/Transforms/Tapir/CMakeLists.txt
+++ b/llvm/lib/Transforms/Tapir/CMakeLists.txt
@@ -31,6 +31,7 @@ add_llvm_component_library(LLVMTapirOpts
   LINK_COMPONENTS
   Analysis
   Core
+  IPO
   IRReader
   Linker
   MC

@VoxSciurorum
Copy link
Contributor Author

Adding IPO to the component list fixes compilation for me on all three OS+cmake argument combinations that had been failing before.

@neboat
Copy link
Collaborator

neboat commented Jan 23, 2024

Glad to hear it! I'll make a PR with the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants