[Buildroot] [PATCH v2] toolchain-external: Fix external toolchains when BR2_ROOTFS_MERGED_USR

Charlie Jenkins charlie at rivosinc.com
Fri Apr 11 23:08:53 UTC 2025


External toolchains like crosstool-ng place libraries at /lib.
When BR2_ROOTFS_MERGED_USR is enabled, these libraries were not being
copied into the target. This caused these toolchains to be unusable with
this option.

WHen BR2_ROOTFS_MERGED_USR is selected, copy the /lib and /lib64
directories into /usr/lib and /usr/lib64 respectively.

Signed-off-by: Charlie Jenkins <charlie at rivosinc.com>
---
I originally reported this issue here [1].

[1] https://lore.kernel.org/buildroot/Z86AGdrKHaUqgLVt@ghost/T/#t
---
Changes in v2:
- Reduce rsync to root cause. The previous solution was very
  heavy-handed as pointed out by Arnout. This seems to be the proper way
  of doing this.
- Link to v1: https://lore.kernel.org/r/20250310-fix_external_toolchains-v1-1-446f48af7cf7@rivosinc.com
---
 toolchain/helpers.mk | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk
index f3fdaaec07c5a01688da685c4d0fd4e2cb357b95..c47f8cd80cf19be7a8a72e9d40eb7327705a3de7 100644
--- a/toolchain/helpers.mk
+++ b/toolchain/helpers.mk
@@ -55,6 +55,9 @@ copy_toolchain_lib_root = \
 # corresponding architecture variants), and we don't want to import
 # them.
 #
+# Furthermore, when BR2_ROOTFS_MERGED_USR is enabled, the 'lib*' directories
+# need to be copied over to usr/'lib*'.
+#
 # If ARCH_LIB_DIR is not a singular directory component, e.g.
 # 'lib32/octeon2', then symbolic links in ARCH_LIB_DIR and
 # usr/ARCH_LIB_DIR may be broken because Buildroot will flatten the
@@ -114,9 +117,15 @@ copy_toolchain_sysroot = \
 			continue ; \
 		fi ; \
 		if [ "$$i" = "usr" ]; then \
-			rsync -au --chmod=u=rwX,go=rX --exclude 'locale/' \
-				--include '/libexec*/' --exclude '/lib*/' \
-				$${ARCH_SYSROOT_DIR}/$$i/ $(STAGING_DIR)/$$i/ ; \
+			if [ "$(BR2_ROOTFS_MERGED_USR)" == "y" ]; then \
+				rsync -au --chmod=u=rwX,go=rX --exclude 'locale/' \
+					--include '/libexec*/' \
+					$${ARCH_SYSROOT_DIR}/$$i/ $(STAGING_DIR)/$$i/ ; \
+			else \
+				rsync -au --chmod=u=rwX,go=rX --exclude 'locale/' \
+					--include '/libexec*/' --exclude '/lib*/' \
+					$${ARCH_SYSROOT_DIR}/$$i/ $(STAGING_DIR)/$$i/ ; \
+			fi ; \
 		else \
 			rsync -au --chmod=u=rwX,go=rX --exclude 'locale/' \
 				$${ARCH_SYSROOT_DIR}/$$i/ $(STAGING_DIR)/$$i/ ; \

---
base-commit: 4809690d42f9b395ccb76ee7583c199fdd8d42c5
change-id: 20250310-fix_external_toolchains-d1b8c4da0be8
-- 
- Charlie



More information about the buildroot mailing list