From 4d31d28e33109fde145a10b6063ae6fe6757bfec Mon Sep 17 00:00:00 2001 From: "Tobias S. Josefowitz" <tobij@tobij.de> Date: Tue, 16 Mar 2021 21:51:16 +0100 Subject: [PATCH] Build [Configure]: Prevent inling of find_stack_direction() Clang 11 has either learned to inline find_stack_direction(), or it may have inlined find_stack_direction() before but changed allocation order for our "objects with automatic storage duration" that we use to check the stack direction. Calling find_stack_direction() through a volatile function pointer should reliably prevent it from getting inlined and thus flush out the real stack direction. Thanks to Cezary Cerekwicki <ccerekwicki@opera.com> for the report. --- src/configure.in | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/configure.in b/src/configure.in index fde19017ea..5a2e1a1a4f 100644 --- a/src/configure.in +++ b/src/configure.in @@ -4689,9 +4689,10 @@ AC_CACHE_VAL(pike_cv_hardware_stack_direction, [ AC_TRY_RUN([ #include <stdio.h> +static int (* volatile find_stack_direction_funptr)(void *foo, int cnt); static int find_stack_direction(void *foo, int cnt) { - if (cnt) return 1*find_stack_direction(foo, cnt>>1); + if (cnt) return 1*find_stack_direction_funptr(foo, cnt>>1); if (((void *)&foo) > foo) { return 1; } else { @@ -4699,7 +4700,10 @@ static int find_stack_direction(void *foo, int cnt) } } -int main() { void *bar; exit( find_stack_direction(&bar, 0x10) > 0); } +int main() { + find_stack_direction_funptr = &find_stack_direction; + void *bar; exit( find_stack_direction_funptr(&bar, 0x10) > 0); +} ], [ pike_cv_hardware_stack_direction=down ], [ pike_cv_hardware_stack_direction=up ], [ -- GitLab