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 9b41b54be0
"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 <ju.o@free.fr>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
This commit is contained in:
Julien Olivain 2022-08-23 00:14:29 +02:00 committed by Yann E. MORIN
parent 2f54c2a841
commit e75f396208

View File

@ -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