llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.98k stars 11.95k forks source link

Backport 73d862e478738675f5d919c6a196429acd7b5f50 to release/19.x #102473

Closed peterwaller-arm closed 3 months ago

peterwaller-arm commented 3 months ago

This is a backport request for 73d862e478738675f5d919c6a196429acd7b5f50 which is a revert for f6f88f4b99638821af803d1911ab6a7dac04880b. The latter unfortunately breaks cross compiled ENABLE_RUNTIMES=compiler-rt. It has been fixed on main in the commit requested for backport. If I diff the CMakeCache within the runtimes-bins dir of the bad commit, then I see that with LLVM_CMAKE_DIR passed, it results in various details of the runtimes build not being correct - we see LLVM_DIR=/usr/lib/llvm-14 in the CMakeCache for example, rather than path/to/build/lib/cmake/llvm for the working version.

The below cmake line on a x86 ubuntu 2204 or 2404 machine targetting aarch64-none-linux-gnu reproduces the issue.

sudo apt install -y cmake ninja-build clang lld g++-aarch64-linux-gnu qemu-user
git clone --depth=1 https://github.com/llvm/llvm-project
CC=clang CXX=clang++ cmake -Bbld -Sllvm-project/llvm -DLLVM_ENABLE_PROJECTS='clang;lld;clang-tools-extra' -DCMAKE_BUILD_TYPE=Release -DLLVM_RUNTIME_TARGETS="aarch64-none-linux-gnu" -DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-none-linux-gnu -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind;compiler-rt" -DLLVM_USE_LINKER=lld -GNinja
ninja -C bld compiler-rt
echo $'#include <iostream>\nint main(int argc, char *argv[]) { std::cout << "lo\\n"; return 0; }' > test.cxx
bld/bin/clang++ -rtlib=compiler-rt test.cxx
qemu-aarch64 -L /usr/aarch64-linux-gnu ./a.out

# outputs: "lo"

In the bad case this fails with something like this, because the broken compiler-rt build does not produce a builtins build:

/usr/lib/gcc-cross/aarch64-linux-gnu/11/../../../../aarch64-linux-gnu/bin/ld: cannot find /home/ubuntu/bld/lib/clang/19/lib/aarch64-none-linux-gnu/libclang_rt.builtins.a

cc @tru for release manager cc @omjavaid @jhuber6 for involvement in patches.

peterwaller-arm commented 3 months ago

/cherry-pick 73d862e478738675f5d919c6a196429acd7b5f50

llvmbot commented 3 months ago

/pull-request llvm/llvm-project#102475