From 4463d8d4b6b27121612d0e1bd76a68312a00e938 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marc=20Nieper-Wi=C3=9Fkirchen?= Date: Tue, 19 Dec 2023 20:04:12 +0100 Subject: [PATCH] jit/cache tests: Make more portable. * tests/jit/test-cache.c (CODE): New macro. (struct func): New type. (main): Initialize f more carefully. * modules/jit/cache-tests (Depends-on): Add host-cpu-c-abi. --- ChangeLog | 8 +++++++ modules/jit/cache-tests | 1 + tests/jit/test-cache.c | 52 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5cd0fa75b3..d9449d17b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2023-12-19 Marc Nieper-Wißkirchen + + jit/cache tests: Make more portable. + * tests/jit/test-cache.c (CODE): New macro. + (struct func): New type. + (main): Initialize f more carefully. + * modules/jit/cache-tests (Depends-on): Add host-cpu-c-abi. + 2023-12-19 Christian Göttsche selinux-h: add stubs and wrappers for raw counterparts diff --git a/modules/jit/cache-tests b/modules/jit/cache-tests index eff828890d..6a713f8bb9 100644 --- a/modules/jit/cache-tests +++ b/modules/jit/cache-tests @@ -7,6 +7,7 @@ unportable-test Depends-on: getpagesize +host-cpu-c-abi pagealign_alloc stdint diff --git a/tests/jit/test-cache.c b/tests/jit/test-cache.c index 3158d02117..145b63e0e8 100644 --- a/tests/jit/test-cache.c +++ b/tests/jit/test-cache.c @@ -29,10 +29,55 @@ #include "macros.h" +/* On most platforms, function pointers are just a pointer to the + code, i.e. to the first instruction to be executed. This, + however, is not universally true, see: + https://git.savannah.gnu.org/gitweb/?p=libffcall.git;a=blob;f=porting-tools/abis/function-pointer.txt. */ + +#define CODE(fn) (((struct func *) (fn))->code_address) +#if ((defined __powerpc__ || defined __powerpc64__) && defined _AIX) || (defined __powerpc64__ && defined __linux__) +struct func +{ + void *code_address; + void *toc_pointer; + void *static_chain; +}; +#elif defined __ia64__ +struct func +{ + void *code_address; + void *global_pointer; +}; +#elif defined __ia64_ilp32__ +struct func +{ + void *code_address; + void *unused1; + void *global_pointer; + void *unused2; +}; +#elif __hppa__ +struct func +{ + void *code_address; + void *pic_base; +}; +#elif __hppa64__ +struct func +{ + void *some_other_code_address; + void *some_other_pic_base; + void *code_address; + void *pic_base; +}; +#else +# undef CODE +# define CODE(fn) ((*(void **) (&fn))) +#endif + /* This test assumes that the code generated by the compiler for the procedures `return1' and `return2' is position independent. It - also assumes that function pointers are compatible with data - pointers and that these are bit-compatible to integers. */ + also assumes that data pointers are bit-compatible to integers. */ static int return1 (void) @@ -60,7 +105,8 @@ main () platforms `mprotect' invalidates the caches. */ mprotect (start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC); - int (*f) (void) = (void *) start; + int (*f) (void) = return1; + CODE (f) = start; /* We assume that the code is not longer than 64 bytes and that we can access the full 64 bytes for reading. */ -- 2.39.5