Skip to content

powerpc aix/darwin build errors in 3.6.0 #987

Closed

Description

@Renegade334

#951 appears to have been half-implemented in powerpc/ffi_darwin.c, and left in an unbuildable state.

  • The PPC_LD_* definitions are absent, as these are defined in ffi_powerpc.h, which ffi_darwin.c does not include.
  • The return type of ffi_closure_helper_common() has been left as ffi_type*, which is inconsistent with the PPC_LD_* constants that are now returned.

Activity

  1. atgreen commented on Jun 21, 2026

    @atgreen
    Member

    Thanks for the detailed report — both observations are spot on. #951 added a switch in ffi_closure_helper_common() that returns PPC_LD_* jump-table indexes, but never defined those constants in ffi_darwin.c (they live in ffi_powerpc.h, which this file deliberately does not include — it has its own, differing FLAG_* enum and ffi_dblfl), and left the function signatures returning ffi_type *.

    The patch below:

    • Defines the PPC_LD_* constants locally in ffi_darwin.c, mirroring ffi_powerpc.h with the same POWERPC64 conditional. The values match the jump tables in aix_closure.S for both the 64-bit path (PPC_LD_U32=10, PPC_LD_S32=11) and the 32-bit path (where U32/S32 collapse to PPC_LD_R3 and I64 to PPC_LD_R3R4).
    • Changes the return type of ffi_closure_helper_common(), ffi_closure_helper_DARWIN(), and ffi_go_closure_helper_DARWIN() (and the two forward prototypes) from ffi_type * to int, since the value is an integer index consumed by the assembly (r3 × 16 → jump table), consistent with ffi_closure_helper_SYSV/ffi_closure_helper_LINUX64.

    I don't have AIX/Darwin PowerPC hardware to build-test this, so it would be great if you could confirm it builds and runs on your end.

    diff --git a/src/powerpc/ffi_darwin.c b/src/powerpc/ffi_darwin.c
    index 126367e1..d62737f4 100644
    --- a/src/powerpc/ffi_darwin.c
    +++ b/src/powerpc/ffi_darwin.c
    @@ -39,6 +39,33 @@ struct ffi_aix_trampoline_struct {
         void * static_chain;	/* Pointer to closure */
     };
     
    +/* Closure jump table indexes returned by ffi_closure_helper_common and
    +   consumed by the jump tables in aix_closure.S.  These mirror the
    +   definitions in ffi_powerpc.h, which this file cannot include because
    +   it defines its own (differing) FLAG_* and ffi_dblfl.  */
    +#define PPC_LD_NONE		0
    +#define PPC_LD_R3		1
    +#define PPC_LD_R3R4		2
    +#define PPC_LD_F32		3
    +#define PPC_LD_F64		4
    +#define PPC_LD_F128		5
    +#define PPC_LD_U8		6
    +#define PPC_LD_S8		7
    +#define PPC_LD_U16		8
    +#define PPC_LD_S16		9
    +
    +#ifndef POWERPC64
    +# define PPC_LD_U32		PPC_LD_R3
    +# define PPC_LD_S32		PPC_LD_R3
    +# define PPC_LD_PTR		PPC_LD_R3
    +# define PPC_LD_I64		PPC_LD_R3R4
    +#else
    +# define PPC_LD_U32		10
    +# define PPC_LD_S32		11
    +# define PPC_LD_PTR		PPC_LD_R3
    +# define PPC_LD_I64		PPC_LD_R3
    +#endif
    +
     extern void ffi_closure_ASM (void);
     
     #if defined (FFI_GO_CLOSURES)
    @@ -1192,12 +1219,12 @@ typedef union
       double d;
     } ffi_dblfl;
     
    -ffi_type *
    +int
     ffi_closure_helper_DARWIN (ffi_closure *, void *,
     			   unsigned long *, ffi_dblfl *);
     
     #if defined (FFI_GO_CLOSURES)
    -ffi_type *
    +int
     ffi_go_closure_helper_DARWIN (ffi_go_closure*, void *,
     			      unsigned long *, ffi_dblfl *);
     #endif
    @@ -1209,7 +1236,7 @@ ffi_go_closure_helper_DARWIN (ffi_go_closure*, void *,
        up space for a return value, ffi_closure_ASM invokes the
        following helper function to do most of the work.  */
     
    -static ffi_type *
    +static int
     ffi_closure_helper_common (ffi_cif* cif,
     			   void (*fun)(ffi_cif*, void*, void**, void*),
     			   void *user_data, void *rvalue,
    @@ -1485,7 +1512,7 @@ ffi_closure_helper_common (ffi_cif* cif,
         }
     }
     
    -ffi_type *
    +int
     ffi_closure_helper_DARWIN (ffi_closure *closure, void *rvalue,
     			   unsigned long *pgr, ffi_dblfl *pfr)
     {
    @@ -1494,7 +1521,7 @@ ffi_closure_helper_DARWIN (ffi_closure *closure, void *rvalue,
     }
     
     #if defined (FFI_GO_CLOSURES)
    -ffi_type *
    +int
     ffi_go_closure_helper_DARWIN (ffi_go_closure *closure, void *rvalue,
     			      unsigned long *pgr, ffi_dblfl *pfr)
     {
  2. Renegade334 commented on Jun 21, 2026

    @Renegade334
    Author

    Many thanks. With this patch, we get successful builds on aix-ppc64 with clang-20.

  3. added a commit that references this issue on Jun 21, 2026
    9ca53a1
  4. barracuda156 commented on Jun 22, 2026

    @barracuda156

    @atgreen I will try this on Darwin.

    Upd. Builds fine.

  5. barracuda156 commented on Jul 26, 2026

    @barracuda156

    Unfortunately, the library does not work correctly now: #1002

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions