[Buildroot] [PATCH] package/clang: set the path to the sysroot

Romain Naour romain.naour at smile.fr
Wed Aug 7 16:27:01 UTC 2019


While testing a clang toolchain to build userspace application after
building an internal toolchain with Buildroot, the build failed due
to host linker being used (/usr/bin/ld).

Clang needs some files (libgcc.a, crt*.o) from the gcc toolchain
to complete to build.

The sysroot is not set when Clang's "Gnu Toolchains driver" try to
find the gcc cross-toolchain [1].

The issue is trigged only with the Buildroot's internal toolchain
backend. For the toolchain external toolchain, clang is able to guess
where to find the cross toolchain (probably because the sysroot is
relocated while importing the external toolchain).

The issue is fixed by setting path to STAGING_DIR to DEFAULT_SYSROOT.

[1] https://github.com/llvm-mirror/clang/blob/release_80/lib/Driver/ToolChains/Gnu.cpp#L1693

Signed-off-by: Romain Naour <romain.naour at smile.fr>
Cc: Valentin Korenblit <valentinkorenblit at gmail.com>
---
 package/clang/clang.mk | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/package/clang/clang.mk b/package/clang/clang.mk
index 07e7fced2a..3059fb8676 100644
--- a/package/clang/clang.mk
+++ b/package/clang/clang.mk
@@ -43,6 +43,11 @@ CLANG_CONF_OPTS += -DCMAKE_BUILD_TYPE=Release
 
 CLANG_CONF_OPTS += -DCMAKE_CROSSCOMPILING=1
 
+# Provide the path the the gcc toolchain sysroot (STAGING_DIR)
+# otherwise the (host) clang's "Gnu Toolchains driver" will
+# fallback to the host's root directory "/".
+HOST_CLANG_CONF_OPTS += -DDEFAULT_SYSROOT=$(STAGING_DIR)
+
 # We need to build tools because libclang is a tool
 HOST_CLANG_CONF_OPTS += -DCLANG_BUILD_TOOLS=ON
 CLANG_CONF_OPTS += -DCLANG_BUILD_TOOLS=ON
-- 
2.20.1



More information about the buildroot mailing list