From f8504293dc1135c1a6d3badf48641075b3d0b75b Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 9 Jan 2024 16:56:08 +0100 Subject: [PATCH] jit/cache tests: Avoid test failure on hppa CPUs. * tests/jit/test-cache.c (FUNCPTR_BIAS): New macro. (structptr_to_funcptr, funcptr_to_structptr): New functions/macros. (xcopy_structptr): Renamed from xcopy_funcptr. Mark as inline. (COPY_FUNCPTR, CODE): Use structptr_to_funcptr, funcptr_to_structptr. * modules/jit/cache-tests (configure.ac): Require AC_C_INLINE. --- ChangeLog | 9 +++++++++ modules/jit/cache-tests | 1 + tests/jit/test-cache.c | 27 +++++++++++++++++++++++---- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 18a80f6d6e..95dfd50d3c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2024-01-09 Bruno Haible + + jit/cache tests: Avoid test failure on hppa CPUs. + * tests/jit/test-cache.c (FUNCPTR_BIAS): New macro. + (structptr_to_funcptr, funcptr_to_structptr): New functions/macros. + (xcopy_structptr): Renamed from xcopy_funcptr. Mark as inline. + (COPY_FUNCPTR, CODE): Use structptr_to_funcptr, funcptr_to_structptr. + * modules/jit/cache-tests (configure.ac): Require AC_C_INLINE. + 2024-01-08 Bruno Haible jit/cache tests: Fix for powerpc*, ia64, hppa* CPUs. diff --git a/modules/jit/cache-tests b/modules/jit/cache-tests index 2b30831f1d..14809b5111 100644 --- a/modules/jit/cache-tests +++ b/modules/jit/cache-tests @@ -22,6 +22,7 @@ gl_COMPILER_OPTION_IF([-fno-ret-protector], [DISABLE_OPENBSD_RETGUARD='-fno-ret-protector'], [DISABLE_OPENBSD_RETGUARD=]) AC_SUBST([DISABLE_OPENBSD_RETGUARD]) +AC_REQUIRE([AC_C_INLINE]) Makefile.am: TESTS += test-cache diff --git a/tests/jit/test-cache.c b/tests/jit/test-cache.c index 86fe4c7aec..76c38eec9e 100644 --- a/tests/jit/test-cache.c +++ b/tests/jit/test-cache.c @@ -82,6 +82,7 @@ struct func void *code_address; void *pic_base; }; +# define FUNCPTR_BIAS 2 # endif #else # define FUNCPTR_POINTS_TO_CODE @@ -92,14 +93,32 @@ struct func # define CODE(funcptr) (funcptr) #else /* A function pointer points to a 'struct func'. */ -static struct func *xcopy_funcptr (struct func *orig_funcptr) +# if FUNCPTR_BIAS +static inline void * +structptr_to_funcptr (struct func *p) +{ + return (char *) p + FUNCPTR_BIAS; +} +static inline struct func * +funcptr_to_structptr (void * volatile funcptr) +{ + return (struct func *) ((char *) funcptr - FUNCPTR_BIAS); +} +# else +# define structptr_to_funcptr(p) ((void *) (p)) +# define funcptr_to_structptr(funcptr) ((struct func *) (funcptr)) +# endif +static inline struct func * +xcopy_structptr (struct func *structptr) { struct func *copy = (struct func *) xmalloc (sizeof (struct func)); - *copy = *orig_funcptr; + *copy = *structptr; return copy; } -# define COPY_FUNCPTR(funcptr) (void *) xcopy_funcptr ((struct func *)(funcptr)) -# define CODE(funcptr) (((struct func *)(funcptr))->code_address) +# define COPY_FUNCPTR(funcptr) \ + structptr_to_funcptr (xcopy_structptr (funcptr_to_structptr (funcptr))) +# define CODE(funcptr) \ + ((funcptr_to_structptr (funcptr))->code_address) #endif /* This test assumes that the code generated by the compiler for the -- 2.39.5