Index: libffi/configure =================================================================== --- libffi/configure (revision 112376) +++ libffi/configure (working copy) @@ -5381,6 +5381,7 @@ i*86-*-solaris2.1[0-9]*) TARGET=X86_64; TARGETDIR=x86;; i*86-*-solaris*) TARGET=X86; TARGETDIR=x86;; i*86-*-beos*) TARGET=X86; TARGETDIR=x86;; +i*86-*-darwin*) TARGET=X86; TARGETDIR=x86;; i*86-*-freebsd* | i*86-*-kfreebsd*-gnu) TARGET=X86; TARGETDIR=x86;; i*86-*-netbsdelf* | i*86-*-knetbsd*-gnu) TARGET=X86; TARGETDIR=x86;; i*86-*-rtems*) TARGET=X86; TARGETDIR=x86;; Index: libffi/src/x86/ffi.c =================================================================== --- libffi/src/x86/ffi.c (revision 112376) +++ libffi/src/x86/ffi.c (working copy) @@ -121,7 +121,7 @@ switch (cif->rtype->type) { case FFI_TYPE_VOID: -#ifndef X86_WIN32 +#if !defined X86_WIN32 && !defined __APPLE__ case FFI_TYPE_STRUCT: #endif case FFI_TYPE_SINT64: @@ -135,7 +135,7 @@ cif->flags = FFI_TYPE_SINT64; break; -#ifdef X86_WIN32 +#if defined X86_WIN32 || defined __APPLE__ case FFI_TYPE_STRUCT: if (cif->rtype->size == 1) { @@ -165,6 +165,10 @@ break; } +#ifdef __APPLE__ + cif->bytes = (cif->bytes + 15) & ~0xF; +#endif + return FFI_OK; } Index: libffi/src/x86/sysv.S =================================================================== --- libffi/src/x86/sysv.S (revision 112376) +++ libffi/src/x86/sysv.S (working copy) @@ -31,18 +31,34 @@ .text +#ifdef __APPLE__ +.globl _ffi_prep_args +#else .globl ffi_prep_args +#endif + .align 4 +#ifdef __APPLE__ +.globl _ffi_call_SYSV +#else .globl ffi_call_SYSV .type ffi_call_SYSV,@function +#endif +#ifdef __APPLE__ +_ffi_call_SYSV: +#else ffi_call_SYSV: +#endif .LFB1: pushl %ebp .LCFI0: movl %esp,%ebp .LCFI1: +#ifdef __APPLE__ + subl $8,%esp +#endif /* Make room for all of the new args. */ movl 16(%ebp),%ecx subl %ecx,%esp @@ -50,12 +66,19 @@ movl %esp,%eax /* Place all of the ffi_prep_args in position */ +#ifdef __APPLE__ + subl $8,%esp +#endif pushl 12(%ebp) pushl %eax call *8(%ebp) /* Return stack to previous state and call the function */ +#ifdef __APPLE__ + addl $16,%esp +#else addl $8,%esp +#endif call *28(%ebp) @@ -112,30 +135,67 @@ retint64: cmpl $FFI_TYPE_SINT64,%ecx - jne retstruct + jne retstruct1b /* Load %ecx with the pointer to storage for the return value */ movl 24(%ebp),%ecx movl %eax,0(%ecx) movl %edx,4(%ecx) + jmp epilogue +retstruct1b: + cmpl $FFI_TYPE_SINT8,%ecx + jne retstruct2b + /* Load %ecx with the pointer to storage for the return value */ + movl 24(%ebp),%ecx + movb %al,0(%ecx) + jmp epilogue + +retstruct2b: + cmpl $FFI_TYPE_SINT16,%ecx + jne retstruct + /* Load %ecx with the pointer to storage for the return value */ + movl 24(%ebp),%ecx + movw %ax,0(%ecx) + jmp epilogue + retstruct: + cmpl $FFI_TYPE_STRUCT,%ecx + jne noretval /* Nothing to do! */ +#ifdef __APPLE__ + addl $4,%esp + popl %ebp + ret +#endif noretval: epilogue: +#ifdef __APPLE__ + addl $8,%esp +#endif movl %ebp,%esp popl %ebp ret .LFE1: .ffi_call_SYSV_end: +#ifndef __APPLE__ .size ffi_call_SYSV,.ffi_call_SYSV_end-ffi_call_SYSV +#endif .align 4 FFI_HIDDEN (ffi_closure_SYSV) +#ifdef __APPLE__ +.globl _ffi_closure_SYSV +#else .globl ffi_closure_SYSV .type ffi_closure_SYSV, @function +#endif +#ifdef __APPLE__ +_ffi_closure_SYSV: +#else ffi_closure_SYSV: +#endif .LFB2: pushl %ebp .LCFI2: @@ -153,10 +213,14 @@ #else movl %ebx, 8(%esp) .LCFI7: +#ifdef __APPLE__ + call L_ffi_closure_SYSV_inner$stub +#else call 1f 1: popl %ebx addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx call ffi_closure_SYSV_inner@PLT +#endif movl 8(%esp), %ebx #endif movl -12(%ebp), %ecx @@ -170,6 +234,14 @@ je .Lcls_retldouble cmpl $FFI_TYPE_SINT64, %eax je .Lcls_retllong +#ifdef __APPLE__ + cmpl $FFI_TYPE_SINT8, %eax + je .Lcls_retstruct1 + cmpl $FFI_TYPE_SINT16, %eax + je .Lcls_retstruct2 + cmpl $FFI_TYPE_STRUCT, %eax + je .Lcls_retstruct +#endif .Lcls_epilogue: movl %ebp, %esp popl %ebp @@ -190,8 +262,23 @@ movl (%ecx), %eax movl 4(%ecx), %edx jmp .Lcls_epilogue +#ifdef __APPLE__ +.Lcls_retstruct1: + movsbl (%ecx), %eax + jmp .Lcls_epilogue +.Lcls_retstruct2: + movswl (%ecx), %eax + jmp .Lcls_epilogue +.Lcls_retstruct: + lea -8(%ebp),%esp + movl %ebp, %esp + popl %ebp + ret $4 +#endif .LFE2: +#ifndef __APPLE__ .size ffi_closure_SYSV, .-ffi_closure_SYSV +#endif #if !FFI_NO_RAW_API @@ -202,10 +289,18 @@ .align 4 FFI_HIDDEN (ffi_closure_raw_SYSV) +#ifdef __APPLE__ +.globl _ffi_closure_raw_SYSV +#else .globl ffi_closure_raw_SYSV .type ffi_closure_raw_SYSV, @function +#endif +#ifdef __APPLE__ +_ffi_closure_raw_SYSV: +#else ffi_closure_raw_SYSV: +#endif .LFB3: pushl %ebp .LCFI4: @@ -256,9 +351,128 @@ movl -20(%ebp), %edx jmp .Lrcls_epilogue .LFE3: +#ifndef __APPLE__ .size ffi_closure_raw_SYSV, .-ffi_closure_raw_SYSV #endif +#endif +#ifdef __APPLE__ +.section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5 +L_ffi_closure_SYSV_inner$stub: + .indirect_symbol _ffi_closure_SYSV_inner + hlt ; hlt ; hlt ; hlt ; hlt +#endif + +#ifdef __APPLE__ + +.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support +EH_frame1: + .set L$set$0,LECIE1-LSCIE1 + .long L$set$0 +LSCIE1: + .long 0x0 + .byte 0x1 + .ascii "zR\0" + .byte 0x1 + .byte 0x7c + .byte 0x8 + .byte 0x1 + .byte 0x10 + .byte 0xc + .byte 0x5 + .byte 0x4 + .byte 0x88 + .byte 0x1 + .align 2 +LECIE1: +.globl _ffi_call_SYSV.eh +_ffi_call_SYSV.eh: +LSFDE1: + .set L$set$1,LEFDE1-LASFDE1 + .long L$set$1 +LASFDE1: + .long LASFDE1-EH_frame1 + .long .LFB1-. + .set L$set$2,.LFE1-.LFB1 + .long L$set$2 + .byte 0x0 + .byte 0x4 + .set L$set$3,.LCFI0-.LFB1 + .long L$set$3 + .byte 0xe + .byte 0x8 + .byte 0x84 + .byte 0x2 + .byte 0x4 + .set L$set$4,.LCFI1-.LCFI0 + .long L$set$4 + .byte 0xd + .byte 0x4 + .align 2 +LEFDE1: +.globl _ffi_closure_SYSV.eh +_ffi_closure_SYSV.eh: +LSFDE2: + .set L$set$5,LEFDE2-LASFDE2 + .long L$set$5 +LASFDE2: + .long LASFDE2-EH_frame1 + .long .LFB2-. + .set L$set$6,.LFE2-.LFB2 + .long L$set$6 + .byte 0x0 + .byte 0x4 + .set L$set$7,.LCFI2-.LFB2 + .long L$set$7 + .byte 0xe + .byte 0x8 + .byte 0x84 + .byte 0x2 + .byte 0x4 + .set L$set$8,.LCFI3-.LCFI2 + .long L$set$8 + .byte 0xd + .byte 0x4 + .align 2 +LEFDE2: + +#if !FFI_NO_RAW_API + +.globl _ffi_closure_raw_SYSV.eh +_ffi_closure_raw_SYSV.eh: +LSFDE3: + .set L$set$10,LEFDE3-LASFDE3 + .long L$set$10 +LASFDE3: + .long LASFDE3-EH_frame1 + .long .LFB3-. + .set L$set$11,.LFE3-.LFB3 + .long L$set$11 + .byte 0x0 + .byte 0x4 + .set L$set$12,.LCFI4-.LFB3 + .long L$set$12 + .byte 0xe + .byte 0x8 + .byte 0x84 + .byte 0x2 + .byte 0x4 + .set L$set$13,.LCFI5-.LCFI4 + .long L$set$13 + .byte 0xd + .byte 0x4 + .byte 0x4 + .set L$set$14,.LCFI6-.LCFI5 + .long L$set$14 + .byte 0x85 + .byte 0x3 + .align 2 +LEFDE3: + +#endif + +#else + .section .eh_frame,EH_FRAME_FLAGS,@progbits .Lframe1: .long .LECIE1-.LSCIE1 /* Length of Common Information Entry */ @@ -375,4 +589,6 @@ #endif +#endif + #endif /* ifndef __x86_64__ */ Index: libffi/src/prep_cif.c =================================================================== --- libffi/src/prep_cif.c (revision 112376) +++ libffi/src/prep_cif.c (working copy) @@ -124,7 +124,10 @@ #ifdef SPARC && (cif->abi != FFI_V9 || cif->rtype->size > 32) #endif +#ifdef __APPLE__ + && (cif->rtype->size > 8) ) +#endif bytes = STACK_ARG_SIZE(sizeof(void*)); #endif Index: libffi/configure.ac =================================================================== --- libffi/configure.ac (revision 112376) +++ libffi/configure.ac (working copy) @@ -46,6 +46,7 @@ i*86-*-solaris2.1[[0-9]]*) TARGET=X86_64; TARGETDIR=x86;; i*86-*-solaris*) TARGET=X86; TARGETDIR=x86;; i*86-*-beos*) TARGET=X86; TARGETDIR=x86;; +i*86-*-darwin*) TARGET=X86; TARGETDIR=x86;; i*86-*-freebsd* | i*86-*-kfreebsd*-gnu) TARGET=X86; TARGETDIR=x86;; i*86-*-netbsdelf* | i*86-*-knetbsd*-gnu) TARGET=X86; TARGETDIR=x86;; i*86-*-rtems*) TARGET=X86; TARGETDIR=x86;;