+2023-12-19 Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de>
+
+ 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 <cgzones@googlemail.com>
selinux-h: add stubs and wrappers for raw counterparts
#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)
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. */