From 920e240f67953c1b80827c665868d6dcf789f45a Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Wed, 26 Apr 2023 02:17:04 +0200 Subject: [PATCH] foc: fix build errors with gcc 12 Fixes #4833 --- ...RE-get-rid-of-__builtin_strlen-usage.patch | 3 +- ...c_10.patch => 0018-L4-enable-gcc_12.patch} | 4 +- ..._10.patch => 0021-FOC-enable-gcc_12.patch} | 4 +- ...-add-implementation-for-__udivmoddi4.patch | 94 +++++++++++++++++++ ...FOC-no-tree-loop-distribute-patterns.patch | 17 ++++ repos/base-foc/ports/foc.hash | 2 +- repos/base-foc/ports/foc.port | 6 +- 7 files changed, 122 insertions(+), 8 deletions(-) rename repos/base-foc/patches/{0018-L4-enable-gcc_10.patch => 0018-L4-enable-gcc_12.patch} (87%) rename repos/base-foc/patches/{0021-FOC-enable-gcc_10.patch => 0021-FOC-enable-gcc_12.patch} (81%) create mode 100644 repos/base-foc/patches/0024-FOC-ia32-add-implementation-for-__udivmoddi4.patch create mode 100644 repos/base-foc/patches/0025-FOC-no-tree-loop-distribute-patterns.patch diff --git a/repos/base-foc/patches/0010-L4RE-get-rid-of-__builtin_strlen-usage.patch b/repos/base-foc/patches/0010-L4RE-get-rid-of-__builtin_strlen-usage.patch index f602178ab5..172b272185 100644 --- a/repos/base-foc/patches/0010-L4RE-get-rid-of-__builtin_strlen-usage.patch +++ b/repos/base-foc/patches/0010-L4RE-get-rid-of-__builtin_strlen-usage.patch @@ -11,10 +11,11 @@ diff --git a/l4/pkg/l4re-core/l4sys/include/kdebug.h b/l4/pkg/l4re-core/l4sys/in index cfb17464..64ee9900 100644 --- a/l4/pkg/l4re-core/l4sys/include/kdebug.h +++ b/l4/pkg/l4re-core/l4sys/include/kdebug.h -@@ -133,6 +133,13 @@ __kdebug_op_1(unsigned op, l4_mword_t val) L4_NOTHROW +@@ -133,6 +133,14 @@ __kdebug_op_1(unsigned op, l4_mword_t val) L4_NOTHROW return res; } ++__attribute__((optimize("no-tree-loop-distribute-patterns"))) +L4_INLINE unsigned __kdebug_strlen(char const * s) +{ + unsigned r = 0; diff --git a/repos/base-foc/patches/0018-L4-enable-gcc_10.patch b/repos/base-foc/patches/0018-L4-enable-gcc_12.patch similarity index 87% rename from repos/base-foc/patches/0018-L4-enable-gcc_10.patch rename to repos/base-foc/patches/0018-L4-enable-gcc_12.patch index 02be589c40..0604860825 100644 --- a/repos/base-foc/patches/0018-L4-enable-gcc_10.patch +++ b/repos/base-foc/patches/0018-L4-enable-gcc_12.patch @@ -1,4 +1,4 @@ -L4: enable GCC 10 +L4: enable GCC 12 diff --git a/l4/mk/Makeconf b/l4/mk/Makeconf index eb59b51..a7b5955 100644 @@ -9,7 +9,7 @@ index eb59b51..a7b5955 100644 L4_STACK_SIZE ?= $(if $(L4_STACK_SIZE_MAIN_THREAD),$(L4_STACK_SIZE_MAIN_THREAD),0x8000) -CC_WHITELIST-gcc := 4.7 4.8 4.9 5 6 7 8 9 -+CC_WHITELIST-gcc := 4.7 4.8 4.9 5 6 7 8 9 10 ++CC_WHITELIST-gcc := 4.7 4.8 4.9 5 6 7 8 9 10 11 12 CC_WHITELIST-clang := 3.5 3.6 3.7 3.8 3.9 # This is quite bad: There is no other chance to disable the page-alignedment diff --git a/repos/base-foc/patches/0021-FOC-enable-gcc_10.patch b/repos/base-foc/patches/0021-FOC-enable-gcc_12.patch similarity index 81% rename from repos/base-foc/patches/0021-FOC-enable-gcc_10.patch rename to repos/base-foc/patches/0021-FOC-enable-gcc_12.patch index b1eb44487a..41cd8b8176 100644 --- a/repos/base-foc/patches/0021-FOC-enable-gcc_10.patch +++ b/repos/base-foc/patches/0021-FOC-enable-gcc_12.patch @@ -1,4 +1,4 @@ -FOC: enable GCC 10 +FOC: enable GCC 12 diff --git a/src/Makeconf b/src/Makeconf index de5b656..7660daa 100644 @@ -9,7 +9,7 @@ index de5b656..7660daa 100644 -CC_WHITELIST-gcc := 4.7 4.8 4.9 5 6 7 8 9 -+CC_WHITELIST-gcc := 4.7 4.8 4.9 5 6 7 8 9 10 ++CC_WHITELIST-gcc := 4.7 4.8 4.9 5 6 7 8 9 10 11 12 CC_WHITELIST-clang := 3.6 3.7 3.8 3.9 4.0 5.0 6.0 7.0 8.0 9.0 CC_WHITELIST := $(CC_WHITELIST-$(CC_TYPE)) diff --git a/repos/base-foc/patches/0024-FOC-ia32-add-implementation-for-__udivmoddi4.patch b/repos/base-foc/patches/0024-FOC-ia32-add-implementation-for-__udivmoddi4.patch new file mode 100644 index 0000000000..55a1f1be99 --- /dev/null +++ b/repos/base-foc/patches/0024-FOC-ia32-add-implementation-for-__udivmoddi4.patch @@ -0,0 +1,94 @@ +From 8d55cdc73b07dd56ae59a42bcc11cde82614334a Mon Sep 17 00:00:00 2001 +From: Frank Mehnert +Date: Mon, 10 May 2021 00:00:00 +0000 +Subject: [PATCH] ia32: add implementation for '__udivmoddi4()' + +This function is implicitly required by code in jdb.cpp performing a +64-bit integer division on 32-bit systems. This function is required +by code generated with gcc-11. Code generated with older versions of +gcc was satisfied with the existing implementation for '__udivdi3'. + +Also fix cosmetic issues in gcc_lib.c and add Doxygen documentation. + +Change-Id: If5b44a9e98429c4fc3eacdd5af8bdaf33c9c2a8f +--- + src/lib/libk/gcc_lib.c | 49 +++++++++++++++++++++++++++++++++++------- + 1 file changed, 41 insertions(+), 8 deletions(-) + +diff --git a/src/lib/libk/gcc_lib.c b/src/lib/libk/gcc_lib.c +index e5626145..b121cb63 100644 +--- a/src/lib/libk/gcc_lib.c ++++ b/src/lib/libk/gcc_lib.c +@@ -1,6 +1,8 @@ + + unsigned long long __umoddi3(unsigned long long, unsigned long long); + unsigned long long __udivdi3(unsigned long long, unsigned long long); ++unsigned long long __udivmoddi4(unsigned long long, unsigned long long, ++ unsigned long long *); + + struct llmoddiv_t + { +@@ -31,15 +33,15 @@ static struct llmoddiv_t llmoddiv(unsigned long long div, unsigned long long s) + while (1) + { + if (div >= s) +- { +- div -= s; +- i |= tmp; +- } ++ { ++ div -= s; ++ i |= tmp; ++ } + if (div == 0) +- break; ++ break; + tmp >>= 1; + if (!tmp) +- break; ++ break; + s >>= 1; + } + +@@ -47,8 +49,39 @@ static struct llmoddiv_t llmoddiv(unsigned long long div, unsigned long long s) + } + + ++/** ++ * 64-bit unsigned modulo for 32-bit machines. ++ * ++ * \param div Dividend. ++ * \param s Divisor. ++ * \return div / s. ++ */ + unsigned long long __umoddi3(unsigned long long div, unsigned long long s) +-{ return llmoddiv(div,s).mod; } ++{ return llmoddiv(div, s).mod; } + ++/** ++ * 64-bit unsigned division for 32-bit machines. ++ * ++ * \param div Dividend. ++ * \param s Divisor. ++ * \return div / s. ++ */ + unsigned long long __udivdi3(unsigned long long div, unsigned long long s) +-{ return llmoddiv(div,s).div; } ++{ return llmoddiv(div, s).div; } ++ ++/** ++ * 64-bit unsigned division + modulo for 32-bit machines. ++ * ++ * \param n Dividend. ++ * \param d Divisor. ++ * \param[out] r Pointer to the result holding div % s. ++ * \return div / s. ++ */ ++unsigned long long __udivmoddi4(unsigned long long div, unsigned long long s, ++ unsigned long long *r) ++{ ++ struct llmoddiv_t md = llmoddiv(div, s); ++ if (r) ++ *r = md.mod; ++ return md.div; ++} diff --git a/repos/base-foc/patches/0025-FOC-no-tree-loop-distribute-patterns.patch b/repos/base-foc/patches/0025-FOC-no-tree-loop-distribute-patterns.patch new file mode 100644 index 0000000000..ae5a5aaf5a --- /dev/null +++ b/repos/base-foc/patches/0025-FOC-no-tree-loop-distribute-patterns.patch @@ -0,0 +1,17 @@ +Fix reboot loop when built with GCC 12. + +diff --git a/src/Makeconf b/src/Makeconf +index bb7ad16c..2fe11226 100644 +--- a/src/Makeconf ++++ b/src/Makeconf +@@ -167,8 +167,8 @@ NOOPT_SHARED_FLAGS += $(NOOPT_SHARED_FLAGS-$(CC_TYPE)) + # Standard compile flags + ASFLAGS += $(SHARED_FLAGS) -DASSEMBLER + ASFLAGS-clang += -no-integrated-as +-CFLAGS += $(SHARED_FLAGS) -Wbad-function-cast -Wstrict-prototypes +-CXXFLAGS += $(SHARED_FLAGS) -fno-rtti -fno-exceptions ++CFLAGS += $(SHARED_FLAGS) -Wbad-function-cast -Wstrict-prototypes -fno-tree-loop-distribute-patterns ++CXXFLAGS += $(SHARED_FLAGS) -fno-rtti -fno-exceptions -fno-tree-loop-distribute-patterns + OPT_CFLAGS += $(OPT_SHARED_FLAGS) + OPT_CXXFLAGS += $(OPT_SHARED_FLAGS) + NOOPT_CFLAGS += $(NOOPT_SHARED_FLAGS) diff --git a/repos/base-foc/ports/foc.hash b/repos/base-foc/ports/foc.hash index 9553e9dc52..b09561604d 100644 --- a/repos/base-foc/ports/foc.hash +++ b/repos/base-foc/ports/foc.hash @@ -1 +1 @@ -abe2de76835f33297ca4e4ac687e69bc04f83dc5 +00cfb7994fee75bb5aae010a3d2c16a7ffd29ec9 diff --git a/repos/base-foc/ports/foc.port b/repos/base-foc/ports/foc.port index f77ab1b37b..872850b2da 100644 --- a/repos/base-foc/ports/foc.port +++ b/repos/base-foc/ports/foc.port @@ -37,11 +37,13 @@ PATCH_OPT(patches/0014-Always-enable-user-mode-access-for-performance-monit.patc PATCH_OPT(patches/0015-VMX-disable-event-injection-if-requested-by-VMM.patch) := -p3 -d${DIR(foc)} PATCH_OPT(patches/0016-svm-provide-cr0-to-guest-if-np-enabled.patch) := -p3 -d${DIR(foc)} PATCH_OPT(patches/0017-svm-avoid-forceful-exit-on-task-switch.patch) := -p3 -d${DIR(foc)} -PATCH_OPT(patches/0018-L4-enable-gcc_10.patch) := -p2 -d${DIR(mk)} +PATCH_OPT(patches/0018-L4-enable-gcc_12.patch) := -p2 -d${DIR(mk)} PATCH_OPT(patches/0019-Bootstrap-do-not-depend-on-any-libstdcxx-feature.patch) := -p1 -d${DIR(bootstrap)} PATCH_OPT(patches/0020-Bootstrap-fix-amd64-build-with-binutils-2_32.patch) := -p1 -d${DIR(bootstrap)} -PATCH_OPT(patches/0021-FOC-enable-gcc_10.patch) := -p1 -d${DIR(foc)} +PATCH_OPT(patches/0021-FOC-enable-gcc_12.patch) := -p1 -d${DIR(foc)} PATCH_OPT(patches/0022-FOC-amd64-split-_syscall_entry-into-code-and-data.patch) := -p1 -d${DIR(foc)} PATCH_OPT(patches/0023-FOC-arm-link-bootstrap-as-et_rel.patch) := -p1 -d${DIR(foc)} +PATCH_OPT(patches/0024-FOC-ia32-add-implementation-for-__udivmoddi4.patch) := -p1 -d${DIR(foc)} +PATCH_OPT(patches/0025-FOC-no-tree-loop-distribute-patterns.patch) := -p1 -d${DIR(foc)} $(call check_tool,gawk)