OpenCilk / opencilk-project

Monorepo for the OpenCilk compiler. Forked from llvm/llvm-project and based on Tapir/LLVM.
Other
89 stars 29 forks source link

Link error compiling with gcc #234

Closed VoxSciurorum closed 7 months ago

VoxSciurorum commented 7 months ago

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.

neboat commented 7 months ago

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 commented 7 months ago

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 14f9bbefb46c4662b3b5e9f9cf5da57b43f27d86 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 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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

neboat commented 7 months ago

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