Skip to contentSkip to conversation

package/llvm-project/clang: use host arch in gcc-install-dir setup

PATCH In review James Knight 2 participants 3 messages Jun 29, 2025 – Jul 2, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/llvm-project/clang: use host arch in gcc-install-dir setup

When configuring --gcc-install-dir for external toolchain configuration, take into consideration of the configured host architecture (HOSTARCH) when populating the expected path for a GCC install. This is help setup register the desired GCC architecture if a given toolchain packages includes multiple GCC architecture installations (e.g. a merged stack of crosstool-ng builds; standalone, non-multilib builds).

For example:

    └── /opt/container/my-toolchain-2025.01.01.12345/lib/gcc/
        ├── aarch64-example-linux-gnu/
        │   └── ...
        ├── i686-example-linux-gnu/
        │   └── ...
        └── x86_64-example-linux-gnu/
            └── ...

---
This patch was created due to a compiling issue detected when building libclc with an external toolchain. An x86_64 build failed with the message:

-- Build files have been written to: /srv/share/test/output/build/libclc-20.1.7
>>> libclc 20.1.7 Building
GIT_DIR=. PATH="/srv/share/test/output/host/bin:/srv/share/test/output/host/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl" /usr/bin/cmake --build /srv/share/test/output/build/libclc-20.1.7/ -j17 -- [ 0%] Generating clspv-convert.cl
[ 0%] Building CXX object CMakeFiles/prepare_builtins.dir/utils/prepare-builtins.cpp.o
...
[ 1%] Generating obj.libclc.dir/nvptx64--/clc/lib/generic/common/clc_degrees.cl.bc
clangclangclangclang: : : : error: error: error: error: no such file or directory: 'i686-example-linux-gnu'
no such file or directory: 'i686-example-linux-gnu'
no such file or directory: 'i686-example-linux-gnu'
clang: error: no such file or directory: 'i686-example-linux-gnu'
clang: error: no such file or directory: 'i686-example-linux-gnu'
clang: error: no such file or directory: 'i686-example-linux-gnu'

When manually running the clang host build, the following errors were reported:

    $ /srv/share/test/output/host/bin/clang
    clang: error: '/opt/container/my-toolchain-2025.01.01.12345/lib/gcc/aarch64-example-linux-gnu' does not contain a GCC installation
    clang: error: no such file or directory: 'i686-example-linux-gnu'
    clang: error: no such file or directory: 'x86_64-example-linux-gnu//opt/container/my-toolchain-2025.01.01.12345/lib/gcc/aarch64-example-linux-gnu:'
    clang: error: no such file or directory: '14.2.0'
    clang: error: no input files

Inspecting the clang host configuration showed an interesting result:

    $ cat /srv/share/test/output/host/lib/clang/20/x86_64-buildroot-linux-gnu.cfg
    --gcc-install-dir=/opt/container/my-toolchain-2025.01.01.12345/lib/gcc/aarch64-example-linux-gnu
    i686-example-linux-gnu
    x86_64-example-linux-gnu//opt/container/my-toolchain-2025.01.01.12345/lib/gcc/aarch64-example-linux-gnu:
    14.2.0
    --target=x86_64-buildroot-linux-gnu

Inspecting the clang package, noticed HOST_CLANG_INSTALL_CONFIG_FILE searches for a GCC path using:

    ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/

However, for the toolchain package I was using, it contains multiple GCC paths:

    $ ls /opt/container/my-toolchain-2025.01.01.12345/lib/gcc/
    aarch64-example-linux-gnu  i686-example-linux-gnu  x86_64-example-linux-gnu

To support this, made the tweak to HOST_CLANG_INSTALL_CONFIG_FILE to use the configured value of HOSTARCH when populating the path. Performed a reinstall of clang (make host-clang-reinstall) and observed an expected path:

    $ cat  /srv/share/test/output/host/lib/clang/20/x86_64-buildroot-linux-gnu.cfg
    --gcc-install-dir=/opt/container/my-toolchain-2025.01.01.12345/lib/gcc/x86_64-example-linux-gnu/14.2.0
    --target=x86_64-buildroot-linux-gnu

Was able to build my configuration afterwards.

---
 package/llvm-project/clang/clang.mk | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
package/llvm-project/clang/clang.mk +2 -1
index a5c8b990aa..800f8d9ef3 100644
@@ -116,7 +116,8 @@ ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y)
 define HOST_CLANG_INSTALL_CONFIG_FILE
 	mkdir -p $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)
 	touch $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg
-	echo "--gcc-install-dir=$(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/)/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/)/)" > $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg
+	TRIPLET=$$(basename -a $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$(HOSTARCH)*); \
+	echo "--gcc-install-dir=$(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$$TRIPLET/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$$TRIPLET/)" > $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg
 	echo "--target=$(GNU_TARGET_NAME)" >> $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg
 endef
 
Signature · 6 lines
2.49.0.windows.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

Hello James, All,

Le 30/06/2025 à 01:53, James Knight a écrit :

Quoted 23 lines

When configuring --gcc-install-dir for external toolchain configuration, take into consideration of the configured host architecture (HOSTARCH) when populating the expected path for a GCC install. This is help setup register the desired GCC architecture if a given toolchain packages includes multiple GCC architecture installations (e.g. a merged stack of crosstool-ng builds; standalone, non-multilib builds).

For example:

     └── /opt/container/my-toolchain-2025.01.01.12345/lib/gcc/
         ├── aarch64-example-linux-gnu/
         │   └── ...
         ├── i686-example-linux-gnu/
         │   └── ...
         └── x86_64-example-linux-gnu/
             └── ...

---
This patch was created due to a compiling issue detected when building libclc with an external toolchain. An x86_64 build failed with the message:

Quoted 13 lines

-- Build files have been written to: /srv/share/test/output/build/libclc-20.1.7
>>> libclc 20.1.7 Building
GIT_DIR=. PATH="/srv/share/test/output/host/bin:/srv/share/test/output/host/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl" /usr/bin/cmake --build /srv/share/test/output/build/libclc-20.1.7/ -j17 -- [ 0%] Generating clspv-convert.cl
[ 0%] Building CXX object CMakeFiles/prepare_builtins.dir/utils/prepare-builtins.cpp.o
...
[ 1%] Generating obj.libclc.dir/nvptx64--/clc/lib/generic/common/clc_degrees.cl.bc
clangclangclangclang: : : : error: error: error: error: no such file or directory: 'i686-example-linux-gnu'
no such file or directory: 'i686-example-linux-gnu'
no such file or directory: 'i686-example-linux-gnu'
clang: error: no such file or directory: 'i686-example-linux-gnu'
clang: error: no such file or directory: 'i686-example-linux-gnu'
clang: error: no such file or directory: 'i686-example-linux-gnu'

Thanks for spotting that out, I forgot the case when the toolchain supports more than one target architecture. In this case, with what I have done before it takes the first architecture and uses it. In this case it finds aarch64 instead of the x86_64 (your target architecture).

Quoted 24 lines

When manually running the clang host build, the following errors were reported:

     $ /srv/share/test/output/host/bin/clang
     clang: error: '/opt/container/my-toolchain-2025.01.01.12345/lib/gcc/aarch64-example-linux-gnu' does not contain a GCC installation
     clang: error: no such file or directory: 'i686-example-linux-gnu'
     clang: error: no such file or directory: 'x86_64-example-linux-gnu//opt/container/my-toolchain-2025.01.01.12345/lib/gcc/aarch64-example-linux-gnu:'
     clang: error: no such file or directory: '14.2.0'
     clang: error: no input files

Inspecting the clang host configuration showed an interesting result:

     $ cat /srv/share/test/output/host/lib/clang/20/x86_64-buildroot-linux-gnu.cfg
     --gcc-install-dir=/opt/container/my-toolchain-2025.01.01.12345/lib/gcc/aarch64-example-linux-gnu
     i686-example-linux-gnu
     x86_64-example-linux-gnu//opt/container/my-toolchain-2025.01.01.12345/lib/gcc/aarch64-example-linux-gnu:
     14.2.0
     --target=x86_64-buildroot-linux-gnu

Inspecting the clang package, noticed HOST_CLANG_INSTALL_CONFIG_FILE searches for a GCC path using:

     ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/
Quoted 8 lines

However, for the toolchain package I was using, it contains multiple GCC paths:

     $ ls /opt/container/my-toolchain-2025.01.01.12345/lib/gcc/
     aarch64-example-linux-gnu  i686-example-linux-gnu  x86_64-example-linux-gnu

To support this, made the tweak to HOST_CLANG_INSTALL_CONFIG_FILE to use the configured value of HOSTARCH when populating the path. Performed a reinstall of clang (make host-clang-reinstall) and observed an expected path:

However, we must use 'ARCH' instead of 'HOSTARCH' to point on the target architeture , not the host build machine. It has worked on your case since your 'HOSTARCH = ARCH', if you run this using your 'aarch64-example-linux-gnu', it won't work since you are using the HOSTARCH which is an x86_64. Also, you can test with the runtime Clang CompileRt available that uses an aarch64 target, it wont work also on this case.

Quoted 14 lines
     $ cat  /srv/share/test/output/host/lib/clang/20/x86_64-buildroot-linux-gnu.cfg
     --gcc-install-dir=/opt/container/my-toolchain-2025.01.01.12345/lib/gcc/x86_64-example-linux-gnu/14.2.0
     --target=x86_64-buildroot-linux-gnu

Was able to build my configuration afterwards.

---
  package/llvm-project/clang/clang.mk | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
package/llvm-project/clang/clang.mk +0 -0
index a5c8b990aa..800f8d9ef3 100644

package/llvm-project/clang/clang.mk ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y) · line 119

Quoted 5 lines
package/llvm-project/clang/clang.mk +1 -1
@@ -116,7 +116,8 @@ ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y)
  define HOST_CLANG_INSTALL_CONFIG_FILE
  	mkdir -p $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)
  	touch $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg
-	echo "--gcc-install-dir=$(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/)/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/)/)" > $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg
+	TRIPLET=$$(basename -a $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$(HOSTARCH)*); \

We must replace here '$(HOSTARCH)' with $(ARCH).

And maybe we can go further replacing the '*' by matching the 'TARGET_OS' and 'LIBC'. What do you think about that?

package/llvm-project/clang/clang.mk ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y) · line 122

Quoted 3 lines
package/llvm-project/clang/clang.mk +1 -0
+	echo "--gcc-install-dir=$(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$$TRIPLET/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$$TRIPLET/)" > $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg
  	echo "--target=$(GNU_TARGET_NAME)" >> $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg
  endef

Best regards,
El Mehdi

Quoted 1 line

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#2 lore raw

Hello Mehdi, James, All,

Le 02/07/2025 à 18:00, El Mehdi YOUNES via buildroot a écrit :

Quoted 129 lines

Hello James, All,

Le 30/06/2025 à 01:53, James Knight a écrit :

Quoted 35 lines

When configuring --gcc-install-dir for external toolchain configuration, take into consideration of the configured host architecture (HOSTARCH) when populating the expected path for a GCC install. This is help setup register the desired GCC architecture if a given toolchain packages includes multiple GCC architecture installations (e.g. a merged stack of crosstool-ng builds; standalone, non-multilib builds).

For example:

     └── /opt/container/my-toolchain-2025.01.01.12345/lib/gcc/
         ├── aarch64-example-linux-gnu/
         │   └── ...
         ├── i686-example-linux-gnu/
         │   └── ...
         └── x86_64-example-linux-gnu/
             └── ...

---
This patch was created due to a compiling issue detected when building libclc with an external toolchain. An x86_64 build failed with the message:

     -- Build files have been written to: /srv/share/test/output/build/ libclc-20.1.7
     >>> libclc 20.1.7 Building
     GIT_DIR=. PATH="/srv/share/test/output/host/bin:/srv/share/test/output/ host/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/ vendor_perl:/usr/bin/core_perl"  /usr/bin/cmake --build /srv/share/test/ output/build/libclc-20.1.7/ -j17 --
     [  0%] Generating clspv-convert.cl
     [  0%] Building CXX object CMakeFiles/prepare_builtins.dir/utils/prepare- builtins.cpp.o
     ...
     [  1%] Generating obj.libclc.dir/nvptx64--/clc/lib/generic/common/

Quoted 8 lines

clc_degrees.cl.bc
     clangclangclangclang: : : : error: error: error: error: no such file or
directory: 'i686-example-linux-gnu'
     no such file or directory: 'i686-example-linux-gnu'
     no such file or directory: 'i686-example-linux-gnu'
     clang: error: no such file or directory: 'i686-example-linux-gnu'
     clang: error: no such file or directory: 'i686-example-linux-gnu'
     clang: error: no such file or directory: 'i686-example-linux-gnu'

Thanks for spotting that out, I forgot the case when the toolchain supports more than one target architecture. In this case, with what I have done before it takes the first architecture and uses it. In this case it finds aarch64 instead of the x86_64 (your target architecture).

Quoted 29 lines

When manually running the clang host build, the following errors were reported:

     $ /srv/share/test/output/host/bin/clang
     clang: error: '/opt/container/my-toolchain-2025.01.01.12345/lib/gcc/
aarch64-example-linux-gnu' does not contain a GCC installation
     clang: error: no such file or directory: 'i686-example-linux-gnu'
     clang: error: no such file or directory: 'x86_64-example-linux-gnu//opt/
container/my-toolchain-2025.01.01.12345/lib/gcc/aarch64-example-linux-gnu:'
     clang: error: no such file or directory: '14.2.0'
     clang: error: no input files

Inspecting the clang host configuration showed an interesting result:

     $ cat /srv/share/test/output/host/lib/clang/20/x86_64-buildroot-linux-
gnu.cfg
     --gcc-install-dir=/opt/container/my-toolchain-2025.01.01.12345/lib/gcc/
aarch64-example-linux-gnu
     i686-example-linux-gnu
     x86_64-example-linux-gnu//opt/container/my-toolchain-2025.01.01.12345/
lib/gcc/aarch64-example-linux-gnu:
     14.2.0
     --target=x86_64-buildroot-linux-gnu

Inspecting the clang package, noticed HOST_CLANG_INSTALL_CONFIG_FILE searches for a GCC path using:

     ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/

Quoted 7 lines

However, for the toolchain package I was using, it contains multiple GCC paths:

          $ ls /opt/container/my-toolchain-2025.01.01.12345/lib/gcc/
     aarch64-example-linux-gnu  i686-example-linux-gnu  x86_64-example-linux-gnu

To support this, made the tweak to HOST_CLANG_INSTALL_CONFIG_FILE to use the configured value of HOSTARCH when populating the path. Performed a reinstall of clang (make host-clang-reinstall) and observed an expected path:

However, we must use 'ARCH' instead of 'HOSTARCH' to point on the target architeture ,
not the host build machine. It has worked on your case since your 'HOSTARCH = ARCH',
if you run this using your 'aarch64-example-linux-gnu', it won't work since you are using
the HOSTARCH which is an x86_64. Also, you can test with the runtime Clang CompileRt available
that uses an aarch64 target, it wont work also on this case.

Quoted 19 lines
     $ cat  /srv/share/test/output/host/lib/clang/20/x86_64-buildroot-linux-
gnu.cfg
     --gcc-install-dir=/opt/container/my-toolchain-2025.01.01.12345/lib/gcc/
x86_64-example-linux-gnu/14.2.0
     --target=x86_64-buildroot-linux-gnu

Was able to build my configuration afterwards.
---
  package/llvm-project/clang/clang.mk | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
package/llvm-project/clang/ renamed from package/llvm-project/clang/clang.mk +0 -0

clang.mk
index a5c8b990aa..800f8d9ef3 100644

package/llvm-project/clang/clang.mk +0 -0
@@ -116,7 +116,8 @@ ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y)

  define HOST_CLANG_INSTALL_CONFIG_FILE
      mkdir -p $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)

Quoted 8 lines

      touch $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg -    echo "--gcc-install-dir=$(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/)/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/)/)" > $(HOST_DIR)/lib/clang/ $(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg
+    TRIPLET=$$(basename -a $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/ $(HOSTARCH)*); \

We must replace here '$(HOSTARCH)' with $(ARCH).

Quoted 3 lines

And maybe we can go further replacing the '*' by matching the 'TARGET_OS' and 'LIBC'.
What do you think about that?

Mehdi, have you tried asking gcc for this install path?

[...]/host/bin/aarch64-linux-gcc -print-search-dirs | sed -n '/^install: /p' | sed -n 's/^install: *\(.*\)/\1/p'

[...]/host/opt/ext-toolchain/bin/../lib/gcc/aarch64-buildroot-linux-gnu/14.2.0/

Best regards,
Romain

Quoted 8 lines
Quoted 7 lines

+    echo "--gcc-install-dir=$(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$ $TRIPLET/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$$TRIPLET/)" > $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg echo "--target=$(GNU_TARGET_NAME)" >> $(HOST_DIR)/lib/clang/ $(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg
  endef

Quoted 8 lines

Best regards,
El Mehdi

Quoted 1 line

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot