commit:     f4e632a335124d01497ead01ae93855c5d6c4c21
Author:     Michal Rostecki <vadorovsky <AT> protonmail <DOT> com>
AuthorDate: Mon Aug  4 11:55:09 2025 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Wed Aug  6 12:29:20 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f4e632a3

llvm-runtimes/libgcc: Support build with cross emerge wrapper

When cross emerge wrapper is used, using `llvm_prepend_path` without
any options, results in prepending the following path:

```
${ESYSROOT}/usr/lib/llvm/${slot}/bin
```

For example:

```
/usr/aarch64-unknown-linux-musl/usr/lib/llvm/19/bin
```

The problem is that cross emerge wrapper uses a cross clang wrapper as
a compiler, e.g. `aarch64-unknown-linux-musl-clang`. However, the file
with such name can be usually found in two places:

* `/usr/lib/llvm/19/bin/aarch64-unknown-linux-musl-clang`, which is
  a clang wrapper that calls the host clang with appropriate
  configuration. We want to call that file.
* 
`/usr/aarch64-unknown-linux-musl/usr/lib/llvm/19/bin/aarch64-unknown-linux-musl-clang`,
  which is an actual aarch64 compiler binary. We cannot execute it on
  x86_64, or other incompatible host.

However, the path added by `llvm_prepend_path` causes resolution of
`aarch64-unknown-linux-musl-clang` to the second path, therefore causing
errors like:

```
/usr/aarch64-unknown-linux-musl/usr/lib/llvm/19/bin/clang: cannot execute 
binary file: Exec format error
```

Solve that by:

* Using `LLVM_ROOT` CMake parameter to point the build to LLVM library
  artifacts.
* Using `llvm_prepend_path` with `-b` argument if we need clang, which
  is the case when either `clang` or `test` USE flags are enabled.

Signed-off-by: Michal Rostecki <vadorovsky <AT> protonmail.com>
Part-of: https://github.com/gentoo/gentoo/pull/39280
Closes: https://github.com/gentoo/gentoo/pull/39280
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
Part-of: https://github.com/gentoo/gentoo/pull/39280
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 llvm-runtimes/libgcc/libgcc-19.1.7-r1.ebuild   | 7 +++++--
 llvm-runtimes/libgcc/libgcc-20.1.8.ebuild      | 5 ++++-
 llvm-runtimes/libgcc/libgcc-21.1.0.9999.ebuild | 5 ++++-
 llvm-runtimes/libgcc/libgcc-22.0.0.9999.ebuild | 5 ++++-
 4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/llvm-runtimes/libgcc/libgcc-19.1.7-r1.ebuild 
b/llvm-runtimes/libgcc/libgcc-19.1.7-r1.ebuild
index d0a3126ebcf1..3ae6287c30eb 100644
--- a/llvm-runtimes/libgcc/libgcc-19.1.7-r1.ebuild
+++ b/llvm-runtimes/libgcc/libgcc-19.1.7-r1.ebuild
@@ -3,7 +3,7 @@
 
 EAPI=8
 
-PYTHON_COMPAT=( python3_{10..13} )
+PYTHON_COMPAT=( python3_{11..13} )
 
 inherit cmake crossdev flag-o-matic llvm.org llvm-utils python-any-r1
 inherit toolchain-funcs
@@ -58,7 +58,9 @@ src_configure() {
        # COMPILER_RT_BUILTINS_HIDE_SYMBOLS option - compatibility with libgcc 
requires
        # visibility of all symbols.
 
-       llvm_prepend_path "${LLVM_MAJOR}"
+       if use clang || use test; then
+               llvm_prepend_path -b "${LLVM_MAJOR}"
+       fi
 
        # LLVM_ENABLE_ASSERTIONS=NO does not guarantee this for us, #614844
        use debug || local -x CPPFLAGS="${CPPFLAGS} -DNDEBUG"
@@ -68,6 +70,7 @@ src_configure() {
 
        local mycmakeargs=(
                
-DCOMPILER_RT_INSTALL_PATH="${EPREFIX}/usr/lib/clang/${LLVM_MAJOR}"
+               -DLLVM_ROOT="${ESYSROOT}/usr/lib/llvm/${LLVM_MAJOR}"
 
                -DCOMPILER_RT_INCLUDE_TESTS=$(usex test)
                -DCOMPILER_RT_BUILD_CRT=OFF

diff --git a/llvm-runtimes/libgcc/libgcc-20.1.8.ebuild 
b/llvm-runtimes/libgcc/libgcc-20.1.8.ebuild
index a3e93dfffb7e..310ed22721e8 100644
--- a/llvm-runtimes/libgcc/libgcc-20.1.8.ebuild
+++ b/llvm-runtimes/libgcc/libgcc-20.1.8.ebuild
@@ -58,7 +58,9 @@ src_configure() {
        # COMPILER_RT_BUILTINS_HIDE_SYMBOLS option - compatibility with libgcc 
requires
        # visibility of all symbols.
 
-       llvm_prepend_path "${LLVM_MAJOR}"
+       if use clang || use test; then
+               llvm_prepend_path -b "${LLVM_MAJOR}"
+       fi
 
        # LLVM_ENABLE_ASSERTIONS=NO does not guarantee this for us, #614844
        use debug || local -x CPPFLAGS="${CPPFLAGS} -DNDEBUG"
@@ -68,6 +70,7 @@ src_configure() {
 
        local mycmakeargs=(
                
-DCOMPILER_RT_INSTALL_PATH="${EPREFIX}/usr/lib/clang/${LLVM_MAJOR}"
+               -DLLVM_ROOT="${ESYSROOT}/usr/lib/llvm/${LLVM_MAJOR}"
 
                -DCOMPILER_RT_INCLUDE_TESTS=$(usex test)
                -DCOMPILER_RT_BUILD_CRT=OFF

diff --git a/llvm-runtimes/libgcc/libgcc-21.1.0.9999.ebuild 
b/llvm-runtimes/libgcc/libgcc-21.1.0.9999.ebuild
index 285e3592a666..52833f54b8a8 100644
--- a/llvm-runtimes/libgcc/libgcc-21.1.0.9999.ebuild
+++ b/llvm-runtimes/libgcc/libgcc-21.1.0.9999.ebuild
@@ -57,7 +57,9 @@ src_configure() {
        # COMPILER_RT_BUILTINS_HIDE_SYMBOLS option - compatibility with libgcc 
requires
        # visibility of all symbols.
 
-       llvm_prepend_path "${LLVM_MAJOR}"
+       if use clang || use test; then
+               llvm_prepend_path -b "${LLVM_MAJOR}"
+       fi
 
        # LLVM_ENABLE_ASSERTIONS=NO does not guarantee this for us, #614844
        use debug || local -x CPPFLAGS="${CPPFLAGS} -DNDEBUG"
@@ -67,6 +69,7 @@ src_configure() {
 
        local mycmakeargs=(
                
-DCOMPILER_RT_INSTALL_PATH="${EPREFIX}/usr/lib/clang/${LLVM_MAJOR}"
+               -DLLVM_ROOT="${ESYSROOT}/usr/lib/llvm/${LLVM_MAJOR}"
 
                -DCOMPILER_RT_INCLUDE_TESTS=$(usex test)
                -DCOMPILER_RT_BUILD_CRT=OFF

diff --git a/llvm-runtimes/libgcc/libgcc-22.0.0.9999.ebuild 
b/llvm-runtimes/libgcc/libgcc-22.0.0.9999.ebuild
index a3b9a91d2a2e..eebc5d612900 100644
--- a/llvm-runtimes/libgcc/libgcc-22.0.0.9999.ebuild
+++ b/llvm-runtimes/libgcc/libgcc-22.0.0.9999.ebuild
@@ -57,7 +57,9 @@ src_configure() {
        # COMPILER_RT_BUILTINS_HIDE_SYMBOLS option - compatibility with libgcc 
requires
        # visibility of all symbols.
 
-       llvm_prepend_path "${LLVM_MAJOR}"
+       if use clang || use test; then
+               llvm_prepend_path -b "${LLVM_MAJOR}"
+       fi
 
        # LLVM_ENABLE_ASSERTIONS=NO does not guarantee this for us, #614844
        use debug || local -x CPPFLAGS="${CPPFLAGS} -DNDEBUG"
@@ -67,6 +69,7 @@ src_configure() {
 
        local mycmakeargs=(
                
-DCOMPILER_RT_INSTALL_PATH="${EPREFIX}/usr/lib/clang/${LLVM_MAJOR}"
+               -DLLVM_ROOT="${ESYSROOT}/usr/lib/llvm/${LLVM_MAJOR}"
 
                -DCOMPILER_RT_INCLUDE_TESTS=$(usex test)
                -DCOMPILER_RT_BUILD_CRT=OFF

Reply via email to