From 1bc64cfe4de2ebe81b66252165f2bf5ce4291b8e Mon Sep 17 00:00:00 2001 From: Julien Olivain Date: Tue, 23 Aug 2022 00:14:29 +0200 Subject: [PATCH] linux: fix builds for kernels < 5.6 and host-gcc >= 10 During a linux-backports update, it was found that kernel v3.10.108 was failing to compile. See: https://lists.buildroot.org/pipermail/buildroot/2022-August/649507.html This issue was introduced by commit 9b41b54be07711c10ad13ce157be272ed1cf402e "linux: fix build with host-gcc 10+", which removes all declarations of "yylloc" symbols in the dtc parser. This symbol is generated by bison, if the "%locations" directive is provided in the parser. See: https://git.savannah.gnu.org/cgit/bison.git/tree/doc/bison.texi?h=v3.8.2#n5984 Kernel versions < 5.6 did not include this directive, so removing all yylloc declararions in the parser also was failing for those version. In the kernel, dtc was updated to v1.5.1-22-gc40aeb60b47a in: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=0cec114e36606412908a35695a5db944cec2e3db This commit is included in kernel v5.6. This dtc update include the dtc commit: https://git.kernel.org/pub/scm/utils/dtc/dtc.git/commit/?id=7150286225476345bd6e7312331e3baf4d621c32 which adds the '%locations' directive. This commit fixes the issue by programmatically adding the '%locations' Bison directive, if it's not found in the parser file. Fixes: - https://bugs.busybox.net/show_bug.cgi?id=14971 Signed-off-by: Julien Olivain Signed-off-by: Yann E. MORIN (cherry picked from commit e75f3962084045cf50f38f0adf8bfaa8da71dfd5) Signed-off-by: Peter Korsgaard --- linux/linux.mk | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/linux/linux.mk b/linux/linux.mk index 1b54fb561d..818e6f8b99 100644 --- a/linux/linux.mk +++ b/linux/linux.mk @@ -155,6 +155,7 @@ LINUX_MAKE_FLAGS = \ INSTALL_MOD_PATH=$(TARGET_DIR) \ CROSS_COMPILE="$(TARGET_CROSS)" \ WERROR=0 \ + REGENERATE_PARSERS=1 \ DEPMOD=$(HOST_DIR)/sbin/depmod ifeq ($(BR2_REPRODUCIBLE),y) @@ -286,6 +287,19 @@ define LINUX_DROP_YYLLOC endef LINUX_POST_PATCH_HOOKS += LINUX_DROP_YYLLOC +# Kernel version < 5.6 breaks if host-gcc version is >= 10 and +# 'yylloc' symbol is removed in previous hook, due to missing +# '%locations' bison directive in dtc-parser.y. See: +# https://bugs.busybox.net/show_bug.cgi?id=14971 +define LINUX_ADD_DTC_LOCATIONS + $(Q)DTC_PARSER=$(@D)/scripts/dtc/dtc-parser.y; \ + if test -e "$${DTC_PARSER}" \ + && ! grep -Eq '^%locations$$' "$${DTC_PARSER}" ; then \ + $(SED) '/^%{$$/i %locations' "$${DTC_PARSER}"; \ + fi +endef +LINUX_POST_PATCH_HOOKS += LINUX_ADD_DTC_LOCATIONS + # Older linux kernels use deprecated perl constructs in timeconst.pl # that were removed for perl 5.22+ so it breaks on newer distributions # Try a dry-run patch to see if this applies, if it does go ahead