Skip to contentSkip to conversation

toolchain/clang-native: Work around native compiles for some gcc configs

PATCH Richard Purdie 1 participant 3 messages Jul 8, 2025 – Jul 9, 2025 3 messages not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 22 lines · Richard Purdie via lists.openembedded.org

Some systems can have mixed development headers, such as pieces of both gcc 13 and 14 which can cause build failures, particularly if libgcc and libstdc++ for gcc 13 are present but only libgcc for gcc 14 and not libstdc++ when the gcc version is gcc 13.

This patch forces clang to use the full toolchain rather than any partial incomplete version. It is only necessary in the native case and should also be applicable to compiler-rt in due source, hence making it an inc file.

---
 meta/classes/toolchain/clang-native.bbclass | 7 +++++++

 1 file changed, 7 insertions(+)
meta/classes/toolchain/clang-native.bbclass +0 -0
index 4de491a1cb5..c8b20ff8c40 100644
@@ -16,3 +16,10 @@ BUILD_READELF = "${BUILD_PREFIX}llvm-readelf"

 DEPENDS += "clang-native libcxx-native compiler-rt-native"
 LDFLAGS += " --rtlib=libgcc --unwindlib=libgcc"

meta/classes/toolchain/clang-native.bbclass

Quoted 7 lines
meta/classes/toolchain/clang-native.bbclass +7 -0
+
+# Some systems can have mixed gcc development headers, such as pieces of both gcc 13
+# and 14 which can cause build failures, particularly if libgcc and libstdc++ for
+# gcc 13 are present but only libgcc for gcc 14 and not libstdc++ when the gcc
+# version is gcc 13. Force the gcc install that matches gcc itself
+BUILD_CFLAGS:append:class-native = " --gcc-install-dir=$(dirname $(gcc -print-libgcc-file-name))"
+BUILD_CXXFLAGS:append:class-native = " --gcc-install-dir=$(dirname $(gcc -print-libgcc-file-name))"

Sadly on a system with buildtools tarball this doesn't work.

https://autobuilder.yoctoproject.org/valkyrie/#/builders/37/builds/2052

&& /srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe-sysroot-native/usr/bin/clang -isystem/srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe-sysroot-native/usr/include -O2 -pipe --gcc-install-dir=/srv/pokybuild/yocto-worker/reproducible/build/buildtools/sysroots/x86_64-pokysdk-linux/usr/lib/gcc/x86_64-pokysdk-linux/14.2.0/../../../../lib/x86_64-pokysdk-linux/14.2.0 -isystem/srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe-sysroot-native/usr/include -L/srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe-sysroot-native/usr/lib -L/srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe-sysroot-native/lib -Wl,--enable-new-dtags -Wl,-rpath-link,/srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe-sysroot-native/usr/lib -Wl,-rpath-link,/srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe-sysroot-native/lib -Wl,-rpath,/srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe-sysroot-native/usr/lib -Wl,-rpath,/srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe-sysroot-native/lib -Wl,-O1 -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=/srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/sysroots-uninative/x86_64-linux/lib/ld-linux-x86-64.so.2 -pthread -rtlib=libgcc -unwindlib=libgcc -stdlib=libstdc++ --rtlib=libgcc --unwindlib=libgcc -unwindlib=libgcc -L/srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe-sysroot-native/usr/lib -L/srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe-sysroot-native/lib -Wl,--enable-new-dtags -Wl,-rpath-link,/srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe-sysroot-native/usr/lib -Wl,-rpath-link,/srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe-sysroot-native/lib -Wl,-rpath,/srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe-sysroot-native/usr/lib -Wl,-rpath,/srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe-sysroot-native/lib -Wl,-O1 -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=/srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/sysroots-uninative/x86_64-linux/lib/ld-linux-x86-64.so.2 -pthread -rtlib=libgcc -unwindlib=libgcc -stdlib=libstdc++ --rtlib=libgcc --unwindlib=libgcc -unwindlib=libgcc CMakeFiles/cmTC_14598.dir/testCCompiler.c.o -o cmTC_14598 && :

|     /srv/pokybuild/yocto-worker/reproducible/build/build-st/reproducibleA/tmp/hosttools/ld: cannot find -lgcc_s: No such file or directory
|     clang: error: linker command failed with exit code 1 (use -v to see invocation)

which is because in this case, libgcc_s is in ~/yocto-worker/reproducible/build/buildtools/sysroots/x86_64-pokysdk-linux/lib

but gcc is saying:

~/yocto-worker/reproducible/build/buildtools/sysroots/x86_64-pokysdk-linux/usr/lib/x86_64-pokysdk-linux/14.2.0

which is where the .a files are.

Cheers,

Richard

#3 lore raw
In reply to a message not in the archive
Quoted 119 lines · Richard Purdie via lists.openembedded.org
Quoted 37 lines · Richard Purdie via lists.openembedded.org

Some systems can have mixed development headers, such as pieces of both gcc 13
and 14 which can cause build failures, particularly if libgcc and libstdc++ for
gcc 13 are present but only libgcc for gcc 14 and not libstdc++ when the gcc
version is gcc 13.

This patch forces clang to use the full toolchain rather than any partial incomplete
version. It is only necessary in the native case and should also be applicable to
compiler-rt in due source, hence making it an inc file.

---
 meta/classes/toolchain/clang-native.bbclass | 7 +++++++

 1 file changed, 7 insertions(+)
meta/classes/toolchain/clang-native.bbclass +0 -0
index 4de491a1cb5..c8b20ff8c40 100644
@@ -16,3 +16,10 @@ BUILD_READELF = "${BUILD_PREFIX}llvm-readelf"

 DEPENDS += "clang-native libcxx-native compiler-rt-native"
 LDFLAGS += " --rtlib=libgcc --unwindlib=libgcc"

meta/classes/toolchain/clang-native.bbclass +2 -0
+
+# Some systems can have mixed gcc development headers, such as

pieces of both gcc 13
+# and 14 which can cause build failures, particularly if libgcc and libstdc++ for
+# gcc 13 are present but only libgcc for gcc 14 and not libstdc++ when the gcc

meta/classes/toolchain/clang-native.bbclass +2 -0
+# version is gcc 13. Force the gcc install that matches gcc itself
+BUILD_CFLAGS:append:class-native = " --gcc-install-dir=$(dirname
Quoted 3 lines

$(gcc -print-libgcc-file-name))" +BUILD_CXXFLAGS:append:class-native = " --gcc-install-dir=$(dirname $(gcc -print-libgcc-file-name))"

Sadly on a system with buildtools tarball this doesn't work.

https://autobuilder.yoctoproject.org/valkyrie/#/builders/37/builds/2052

 && /srv/pokybuild/yocto-worker/reproducible/build/build- st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe- sysroot-native/usr/bin/clang -isystem/srv/pokybuild/yocto- worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64- linux/libcxx-native/20.1.7/recipe-sysroot-native/usr/include -O2 - pipe  --gcc-install-dir=/srv/pokybuild/yocto- worker/reproducible/build/buildtools/sysroots/x86_64-pokysdk- linux/usr/lib/gcc/x86_64-pokysdk-linux/14.2.0/../../../../lib/x86_64- pokysdk-linux/14.2.0   -isystem/srv/pokybuild/yocto- worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64- linux/libcxx-native/20.1.7/recipe-sysroot-native/usr/include - L/srv/pokybuild/yocto-worker/reproducible/build/build- st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe- sysroot-native/usr/lib                         - L/srv/pokybuild/yocto-worker/reproducible/build/build- st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe- sysroot-native/lib                         -Wl,--enable-new- dtags                         -Wl,-rpath-link,/srv/pokybuild/yocto- worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64- linux/libcxx-native/20.1.7/recipe-sysroot-
native/usr/lib                         -Wl,-rpath- link,/srv/pokybuild/yocto-worker/reproducible/build/build- st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe- sysroot-native/lib                         -Wl,- rpath,/srv/pokybuild/yocto-worker/reproducible/build/build- st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe- sysroot-native/usr/lib                         -Wl,- rpath,/srv/pokybuild/yocto-worker/reproducible/build/build- st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe- sysroot-native/lib                         -Wl,-O1 -Wl,--allow-shlib- undefined -Wl,--dynamic-linker=/srv/pokybuild/yocto- worker/reproducible/build/build-st/reproducibleA/tmp/sysroots- uninative/x86_64-linux/lib/ld-linux-x86-64.so.2 -pthread - rtlib=libgcc -unwindlib=libgcc -stdlib=libstdc++  --rtlib=libgcc -- unwindlib=libgcc -unwindlib=libgcc -L/srv/pokybuild/yocto- worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64- linux/libcxx-native/20.1.7/recipe-sysroot-
native/usr/lib                         -L/srv/pokybuild/yocto- worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64- linux/libcxx-native/20.1.7/recipe-sysroot-
native/lib                         -Wl,--enable-new-
dtags                         -Wl,-rpath-link,/srv/pokybuild/yocto- worker/reproducible/build/build-st/reproducibleA/tmp/work/x86_64- linux/libcxx-native/20.1.7/recipe-sysroot-
native/usr/lib                         -Wl,-rpath- link,/srv/pokybuild/yocto-worker/reproducible/build/build- st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe- sysroot-native/lib                         -Wl,- rpath,/srv/pokybuild/yocto-worker/reproducible/build/build- st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe- sysroot-native/usr/lib                         -Wl,- rpath,/srv/pokybuild/yocto-worker/reproducible/build/build- st/reproducibleA/tmp/work/x86_64-linux/libcxx-native/20.1.7/recipe- sysroot-native/lib                         -Wl,-O1 -Wl,--allow-shlib- undefined -Wl,--dynamic-linker=/srv/pokybuild/yocto- worker/reproducible/build/build-st/reproducibleA/tmp/sysroots- uninative/x86_64-linux/lib/ld-linux-x86-64.so.2 -pthread - rtlib=libgcc -unwindlib=libgcc -stdlib=libstdc++  --rtlib=libgcc -- unwindlib=libgcc -unwindlib=libgcc CMakeFiles/cmTC_14598.dir/testCCompiler.c.o -o cmTC_14598   && :

Quoted 5 lines

    /srv/pokybuild/yocto-worker/reproducible/build/build- st/reproducibleA/tmp/hosttools/ld: cannot find -lgcc_s: No such file or directory
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

which is because in this case, libgcc_s is in ~/yocto- worker/reproducible/build/buildtools/sysroots/x86_64-pokysdk- linux/lib

Quoted 6 lines

but gcc is saying:

~/yocto-worker/reproducible/build/buildtools/sysroots/x86_64-pokysdk- linux/usr/lib/x86_64-pokysdk-linux/14.2.0

which is where the .a files are.

I did try:

BUILD_CFLAGS:append:class-native = " --gcc-install-dir=$(dirname $(gcc -print-file-name=libgcc_s.so))" BUILD_CXXFLAGS:append:class-native = " --gcc-install-dir=$(dirname $(gcc -print-file-name=libstdc++.so))"

but that doesn't work either.

Cheers,

Richard

#5 lore raw
In reply to a message not in the archive
Quoted 6 lines · Richard Purdie via lists.openembedded.org

BUILD_CFLAGS:append:class-native = " --gcc-install-dir=$(dirname $(gcc -print-file-name=libgcc_s.so))" BUILD_CXXFLAGS:append:class-native = " --gcc-install-dir=$(dirname $(gcc -print-file-name=libstdc++.so))"

but that doesn't work either.

For the achieves, we added detection for the broken host config to sanity.bbclass, then changed our infrastucture to avoid that config since it is straightforward to do so.

Cheers,

Richard