llvm / llvm-project

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

Inconsistent `clang --target` behavior across musl archs #89146

Open am11 opened 7 months ago

am11 commented 7 months ago

It appears clang is able to locate the gcc toolchain from triplet without distro name for aarch64, but not armv7: Setup:

# aarch64 gcc toolchain
$ ls /crossrootfs/arm64/usr/lib/gcc
aarch64-alpine-linux-musl

# armv7 gcc toolchain
$ ls /crossrootfs/arm/usr/lib/gcc
armv7-alpine-linux-musleabihf

Test:

✅ aarch64-alpine-linux-musl
$ echo "int main(void) { }" | clang-18 -xc - --sysroot="/crossrootfs/arm64" --target=aarch64-alpine-linux-musl

✅ aarch64-linux-musl
$ echo "int main(void) { }" | clang-18 -xc - --sysroot="/crossrootfs/arm64" --target=aarch64-linux-musl

✅ armv7-alpine-linux-musleabihf
$ echo "int main(void) { }" | clang-18 -xc - --sysroot="/crossrootfs/arm" --target=armv7-alpine-linux-musleabihf

❌ armv7-linux-musleabihf
$ echo "int main(void) { }" | clang-18 -xc - --sysroot="/crossrootfs/arm" --target=armv7-linux-musleabihf
/usr/bin/ld: cannot find crtbeginS.o: No such file or directory
/usr/bin/ld: cannot find -lgcc: No such file or directory
/usr/bin/ld: cannot find -lgcc: No such file or directory
clang-18: error: linker command failed with exit code 1 (use -v to see invocation)

Other musllibc-based distros use neutral names for gcc toolchain: ${arch}-linux-musl. Due to this disparity in identifying gcc toolchain, we would need to special case musleabihf for Alpine Linux.

llvmbot commented 7 months ago

@llvm/issue-subscribers-clang-driver

Author: Adeel Mujahid (am11)

It appears clang is able to locate the gcc toolchain from triplet without distro name for aarch64, but not armv7: Setup: ```sh # aarch64 gcc toolchain $ ls /crossrootfs/arm64/usr/lib/gcc aarch64-alpine-linux-musl # armv7 gcc toolchain $ ls /crossrootfs/arm/usr/lib/gcc armv7-alpine-linux-musleabihf ``` Test: ```sh ✅ aarch64-alpine-linux-musl $ echo "int main(void) { }" | clang-18 -xc - --sysroot="/crossrootfs/arm64" --target=aarch64-alpine-linux-musl ✅ aarch64-linux-musl $ echo "int main(void) { }" | clang-18 -xc - --sysroot="/crossrootfs/arm64" --target=aarch64-linux-musl ✅ armv7-alpine-linux-musleabihf $ echo "int main(void) { }" | clang-18 -xc - --sysroot="/crossrootfs/arm" --target=armv7-alpine-linux-musleabihf ❌ armv7-linux-musleabihf $ echo "int main(void) { }" | clang-18 -xc - --sysroot="/crossrootfs/arm" --target=armv7-linux-musleabihf /usr/bin/ld: cannot find crtbeginS.o: No such file or directory /usr/bin/ld: cannot find -lgcc: No such file or directory /usr/bin/ld: cannot find -lgcc: No such file or directory clang-18: error: linker command failed with exit code 1 (use -v to see invocation) ``` Other musllibc-based distros use neutral names for gcc toolchain: `${arch}-linux-musl`. Due to this disparity in identifying gcc toolchain, we would need to special case musleabihf for Alpine Linux.