OpenRISC/or1k build fixes (#854)
authorThomas Petazzoni <thomas.petazzoni@bootlin.com>
Sun, 15 Sep 2024 11:22:36 +0000 (13:22 +0200)
committerGitHub <noreply@github.com>
Sun, 15 Sep 2024 11:22:36 +0000 (07:22 -0400)
* src/or1k/ffi.c: fix prototype of ffi_call_SYSV()

The current code base of libffi on OpenRISC (or1k) fails to build with
GCC 14.x with the following error:

../src/or1k/ffi.c: In function 'ffi_call':
../src/or1k/ffi.c:167:34: error: passing argument 3 of 'ffi_call_SYSV' from incompatible pointer type [-Wincompatible-pointer-types]
  167 |       ffi_call_SYSV(size, &ecif, ffi_prep_args, rvalue, fn, cif->flags);
      |                                  ^~~~~~~~~~~~~
      |                                  |
      |                                  void * (*)(char *, extended_cif *)
../src/or1k/ffi.c:113:27: note: expected 'void * (*)(int *, extended_cif *)' but argument is of type 'void * (*)(char *, extended_cif *)'
  113 |                           void *(*)(int *, extended_cif *),
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is due to the fact that ffi_prep_args() is in fact defined as:

  void* ffi_prep_args(char *stack, extended_cif *ecif)

so, let's fix the prototype of the function pointer, which anyway gets
passed to assembly code, so the typing gets lost.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
* src/or1k/ffi.c: fix incompatible pointer type

The current code base of libffi on OpenRISC (or1k) fails to build with
GCC 14.x with the following error:

../src/or1k/ffi.c: In function 'ffi_closure_SYSV':
../src/or1k/ffi.c:183:22: error: initialization of 'char *' from incompatible pointer type 'int *' [-Wincompatible-pointer-types]
  183 |   char *stack_args = sp;
      |                      ^~

Indeed:

  register int *sp __asm__ ("r17");
  [..]
  char *stack_args = sp;

Adopt the same logic used for:

  char *ptr = (char *) register_args;

which consists in casting to the desired pointer type. Indeed, later
in the code stack_args is assigned to ptr (so they need to be the same
pointer type), and some arithmetic is done on ptr, so changing its
pointer type would change the behavior.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---------

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
src/or1k/ffi.c

index 9451d4e7e433dd0d3c0324a8ce86d492c63100fe..7a6d28c2c12e39bc3f5ee034f6fd83b6d08ed9a8 100644 (file)
@@ -110,7 +110,7 @@ void* ffi_prep_args(char *stack, extended_cif *ecif)
 
 extern void ffi_call_SYSV(unsigned,
                           extended_cif *,
-                          void *(*)(int *, extended_cif *),
+                          void *(*)(char *, extended_cif *),
                           unsigned *,
                           void (*fn)(void),
                           unsigned);
@@ -180,7 +180,7 @@ void ffi_closure_SYSV(unsigned long r3, unsigned long r4, unsigned long r5,
   register int *r13 __asm__ ("r13");
 
   ffi_closure* closure = (ffi_closure*) r13;
-  char *stack_args = sp;
+  char *stack_args = (char*) sp;
 
   /* Lay the register arguments down in a continuous chunk of memory.  */
   unsigned register_args[6] =