]> Savannah Git Hosting - gnulib.git/commitdiff
jit/cache tests: Make more portable.
authorMarc Nieper-Wißkirchen <marc@nieper-wisskirchen.de>
Tue, 19 Dec 2023 19:04:12 +0000 (20:04 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 19 Dec 2023 19:04:12 +0000 (20:04 +0100)
* 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
modules/jit/cache-tests
tests/jit/test-cache.c

index 5cd0fa75b33765dd3b75280defa9e316221110f2..d9449d17b3a9bf3d200692d9015a5312abe780b2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+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
index eff828890d2354defc7680c07ed3a67eb64b3af0..6a713f8bb956629a2ece451ee417fdafba085f62 100644 (file)
@@ -7,6 +7,7 @@ unportable-test
 
 Depends-on:
 getpagesize
+host-cpu-c-abi
 pagealign_alloc
 stdint
 
index 3158d021176347854713e40cb1927efb1b4181cd..145b63e0e8ccd64b31f5db0ea1a485c5b24a6581 100644 (file)
 
 #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.  */