Skip to contentSkip to conversation

toolchain-scripts: fix kernel host tool builds broken in the SDK

PATCH New Daniel Dragomir 1 participant 1 message Aug 30

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 toolchain-scripts: fix kernel host tool builds broken in the SDK

Building an out-of-tree kernel module with an SDK fails while the kernel is compiling its own host tools:

  $ cd $SDKTARGETSYSROOT/usr/lib/modules/*/build
  $ make modules_prepare
  ...
  /usr/include/sys/cdefs.h:486: error: "__attribute_const__" redefined
  /usr/include/stdlib.h:219: error: redundant redeclaration of 'strtol'

objtool and the other tools under tools/ ask pkg-config where libelf is, via HOSTPKG_CONFIG. They are host programs, but the SDK environment sets PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH so that pkg-config answers for the target, and that answer now contains -I/usr/include. Passing /usr/include explicitly with -I makes the compiler treat those headers as ordinary headers rather than system headers, so the warnings inside them stop being suppressed and -Werror turns them into errors.

Ordinary applications built with the SDK are affected too, less visibly: they pick up a redundant -I$SDKTARGETSYSROOT/usr/include and -L$SDKTARGETSYSROOT/usr/lib that they never used to get.

Neither the kernel nor the SDK layout changed. What changed is which pkg-config implementation the SDK ships. pkg-config dropped system directories such as /usr/include from its answer on its own. pkgconf only drops them if they are listed in PKG_CONFIG_SYSTEM_INCLUDE_PATH and PKG_CONFIG_SYSTEM_LIBRARY_PATH, and it compares those lists against paths that already have the sysroot prepended. So the lists have to hold sysroot-prefixed paths, and the SDK environment never set them at all.

a3320989ca ("class/pkgconfig: use pkgconf instead of pkgconfig") already sysroot-prefixed both variables for the build environment, in pkgconfig.bbclass. Do the same for the SDK environment.

Checked with pkgconf 2.5.1 on a .pc file inside a sysroot, with PKG_CONFIG_SYSROOT_DIR set:

before: -I$S/usr/include -I$S/usr/include/bsd-1.0 -L$S/usr/lib -lbsd
after: -I$S/usr/include/bsd-1.0 -lbsd

which is what pkg-config used to return for the same input.

The native sysroot directories are listed as well. Setting either variable replaces pkgconf's built-in list instead of adding to it, and for nativesdk-pkgconf that built-in list is what currently keeps nativesdk .pc files from leaking their own -I and -L into host tool builds.

toolchain_create_tree_env_script() is left alone: it already passes an unset $libdir and $prefix to its own PKG_CONFIG_PATH line, so it needs a separate look.

Assisted-by kiro:claude-opus-5
---
 meta/classes-recipe/toolchain-scripts.bbclass | 2 ++
 1 file changed, 2 insertions(+)
meta/classes-recipe/toolchain-scripts.bbclass +2 -0
index 5bdf22dfa2..e971b9a270 100644
@@ -63,6 +63,8 @@ toolchain_create_sdk_env_script () {
 	echo "export PATH=$sdkpathnative$bindir:$sdkpathnative$sbindir:$sdkpathnative$base_bindir:$sdkpathnative$base_sbindir:$sdkpathnative$bindir/../${HOST_SYS}/bin:$sdkpathnative$bindir/${TARGET_SYS}"$EXTRAPATH':"$PATH"' >> $script
 	echo 'export PKG_CONFIG_SYSROOT_DIR=$SDKTARGETSYSROOT' >> $script
 	echo 'export PKG_CONFIG_PATH=$SDKTARGETSYSROOT'"$libdir"'/pkgconfig:$SDKTARGETSYSROOT'"$prefix"'/share/pkgconfig' >> $script
+	echo 'export PKG_CONFIG_SYSTEM_INCLUDE_PATH=$SDKTARGETSYSROOT'"$prefix"'/include:'"$sdkpathnative${includedir_nativesdk}" >> $script
+	echo 'export PKG_CONFIG_SYSTEM_LIBRARY_PATH=$SDKTARGETSYSROOT'"$libdir"':$SDKTARGETSYSROOT/${baselib}:'"$sdkpathnative${libdir_nativesdk}" >> $script
 	echo 'export CONFIG_SITE=${SDKPATH}/site-config-'"${multimach_target_sys}" >> $script
 	echo "export OECORE_NATIVE_SYSROOT=\"$sdkpathnative\"" >> $script
 	echo 'export OECORE_TARGET_SYSROOT="$SDKTARGETSYSROOT"' >> $script
Signature · 1 line
2.43.0