The issue seems to be that under clang version 16 targeting AMD64, configure.cmake would wrongly set STACK_DIRECTION to 1 instead of -1 and therefore effectively disable check_stack_overrun(). https://stackoverflow.com/questions/6419304/c-program-to-find-direction-of-stack-growth suggests that such checks are futile and we should perhaps simply just apply the logic that debian/rules is already using for cross-compiling:
# Cross building requires stack direction instruction
|
ifneq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH))
|
ifneq (,$(filter $(DEB_HOST_ARCH_CPU),alpha amd64 arm arm64 i386 ia64 m68k mips64el mipsel powerpc ppc64 ppc64el riscv64 s390x sh4 sparc64))
|
CMAKEFLAGS += -DSTACK_DIRECTION=-1
|
endif
|
ifneq (,$(filter $(DEB_HOST_ARCH_CPU),hppa))
|
CMAKEFLAGS += -DSTACK_DIRECTION=1
|
endif
|
endif
|
All the affected tests would pass on AMD64:
10.6 b0a43818b4ffda3dd9b353e222a24dd0b5d1513e Debug with correct STACK_DIRECTION=-1
|
main.json_debug_nonembedded w3 [ pass ] 1
|
main.sp-error w2 [ pass ] 203
|
main.execution_constants w1 [ pass ] 187
|
main.sp_notembedded w4 [ pass ] 208
|
10.6 b0a43818b4ffda3dd9b353e222a24dd0b5d1513e RelWithDebInfo with correct STACK_DIRECTION=-1
|
main.json_debug_nonembedded [ skipped ] Requires debug build
|
main.sp-error w1 [ pass ] 188
|
main.execution_constants w3 [ pass ] 169
|
main.sp_notembedded w4 [ pass ] 184
|
There does not seem to be any absolute need to touch the DBUG_EXECUTE_IF("json_check_min_stack_requirement", …) in sql/json_table.cc or sql/item_jsonfunc.cc, although in my opinion they are rather useless because they basically duplicate the logic of check_stack_overrun(). I would suggest something simpler and less obfuscated, like this:
DBUG_EXECUTE_IF("json_check_min_stack_requirement", return 1;);
|
if (check_stack_overrun(current_thd, STACK_MIN_SIZE , NULL))
|
return 1;
|
The following patch (which I also posted earlier) does not appear to be necessary for the stack overflow check to work:
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
|
index abcd690ba8a..fdbc82e9ad9 100644
|
--- a/sql/sql_parse.cc
|
+++ b/sql/sql_parse.cc
|
@@ -7444,15 +7444,17 @@ long max_stack_used;
|
- Passing to check_stack_overrun() prevents the compiler from removing it.
|
*/
|
|
-bool
|
-#if defined __GNUC__ && !defined __clang__
|
/*
|
Do not optimize the function in order to preserve a stack variable creation.
|
Otherwise, the variable pointed as "buf" can be removed due to a missing
|
usage.
|
*/
|
+#ifdef __clang__
|
+__attribute__((optnone))
|
+#elif defined __GNUC__
|
__attribute__((optimize("-O0")))
|
#endif
|
+bool
|
check_stack_overrun(THD *thd, long margin, uchar *buf __attribute__((unused)))
|
{
|
long stack_used;
|
Sergei fixed it ( as informed by sanja )