From e449a43bbe12f8119399928db1ae26adc71dde14 Mon Sep 17 00:00:00 2001 From: Landon Fuller Date: Sat, 12 Feb 2011 10:20:42 -0500 Subject: [PATCH 1/8] Allow specification of the minimum supported iOS version. --- build-ios.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build-ios.sh b/build-ios.sh index d9010af..751fc69 100755 --- a/build-ios.sh +++ b/build-ios.sh @@ -3,10 +3,11 @@ PLATFORM_IOS=/Developer/Platforms/iPhoneOS.platform/ PLATFORM_IOS_SIM=/Developer/Platforms/iPhoneSimulator.platform/ SDK_IOS_VERSION="4.1" +MIN_IOS_VERSION="3.0" mkdir -p "build-ios" pushd "build-ios" export CC="${PLATFORM_IOS}"/Developer/usr/bin/gcc-4.2 -export CFLAGS="-arch armv6 -isysroot ${PLATFORM_IOS}/Developer/SDKs/iPhoneOS${SDK_IOS_VERSION}.sdk/" +export CFLAGS="-arch armv6 -isysroot ${PLATFORM_IOS}/Developer/SDKs/iPhoneOS${SDK_IOS_VERSION}.sdk/ -miphoneos-version-min=${MIN_IOS_VERSION}" ../configure --host=arm-apple-darwin10 && make popd From 92ff23e77fa586455b427b71f49e1d9502470e6e Mon Sep 17 00:00:00 2001 From: Landon Fuller Date: Sat, 12 Feb 2011 10:24:49 -0500 Subject: [PATCH 2/8] Switch to the current iOS 4.2 SDK. --- build-ios.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-ios.sh b/build-ios.sh index 751fc69..1035843 100755 --- a/build-ios.sh +++ b/build-ios.sh @@ -2,7 +2,7 @@ PLATFORM_IOS=/Developer/Platforms/iPhoneOS.platform/ PLATFORM_IOS_SIM=/Developer/Platforms/iPhoneSimulator.platform/ -SDK_IOS_VERSION="4.1" +SDK_IOS_VERSION="4.2" MIN_IOS_VERSION="3.0" mkdir -p "build-ios" From 7f2ea33a80bfced5e48ed7292f3b8f057d54ff8f Mon Sep 17 00:00:00 2001 From: Landon Fuller Date: Sat, 12 Feb 2011 10:39:18 -0500 Subject: [PATCH 3/8] Replace RETLDM macro. The macro is incompatible with Apple's assembler; switch to a simple inline version. --- src/arm/sysv.S | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/arm/sysv.S b/src/arm/sysv.S index 14a7f03..95329d7 100644 --- a/src/arm/sysv.S +++ b/src/arm/sysv.S @@ -147,23 +147,6 @@ _L__\name: .endm #endif -.macro RETLDM regs=, cond=, dirn=ia -#if defined (__INTERWORKING__) - .ifc "\regs","" - ldr\cond lr, [sp], #4 - .else - ldm\cond\dirn sp!, {\regs, lr} - .endif - bx\cond lr -#else - .ifc "\regs","" - ldr\cond pc, [sp], #4 - .else - ldm\cond\dirn sp!, {\regs, pc} - .endif -#endif -.endm - @ r0: ffi_prep_args @ r1: &ecif @ r2: cif->bytes @@ -424,7 +407,12 @@ LSYM(Lbase_args): fstmiadeq r2, {d0-d3} LSYM(Lepilogue_vfp): - RETLDM "r0-r3,fp" +#if defined (__INTERWORKING__) + ldmia sp!, {r0-r3,fp, lr} + bx lr +#else + ldmia sp!, {r0-r3,fp, pc} +#endif .ffi_call_VFP_end: UNWIND .fnend From 28a00f61ff3f64c4eb2269ce2aea3d493274469e Mon Sep 17 00:00:00 2001 From: Landon Fuller Date: Sat, 12 Feb 2011 11:01:48 -0500 Subject: [PATCH 4/8] Apple assembler support; fixed most gas/ELF-isms. --- src/arm/sysv.S | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/arm/sysv.S b/src/arm/sysv.S index 95329d7..895eba8 100644 --- a/src/arm/sysv.S +++ b/src/arm/sysv.S @@ -318,7 +318,12 @@ ARM_FUNC_START ffi_closure_SYSV /* Below are VFP hard-float ABI call and closure implementations. Add VFP FPU directive here. */ +#ifndef __APPLE__ + /* XXX - .fpu pseudo-directive is not supported by Apple's assembler, + and VFP hard-float calling conventions are not supported by the + compiler. */ .fpu vfp +#endif @ r0: fn @ r1: &ecif @@ -416,7 +421,9 @@ LSYM(Lepilogue_vfp): .ffi_call_VFP_end: UNWIND .fnend +#ifdef __ELF__ .size CNAME(ffi_call_VFP),.ffi_call_VFP_end-CNAME(ffi_call_VFP) +#endif ARM_FUNC_START ffi_closure_VFP @@ -478,7 +485,9 @@ ARM_FUNC_START ffi_closure_VFP .ffi_closure_VFP_end: UNWIND .fnend +#ifdef __ELF__ .size CNAME(ffi_closure_VFP),.ffi_closure_VFP_end-CNAME(ffi_closure_VFP) +#endif #if defined __ELF__ && defined __linux__ .section .note.GNU-stack,"",%progbits From 56b3f8cef0f28cefaa0f40fe0cf7c524adef131d Mon Sep 17 00:00:00 2001 From: Landon Fuller Date: Sat, 12 Feb 2011 11:14:54 -0500 Subject: [PATCH 5/8] Modify the ffi_closure structures to hold table/table entry pointers instead of a code buffer. This re-integrates commit da2773e02ab26cc11a7f. --- include/ffi.h.in | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/ffi.h.in b/include/ffi.h.in index 96b8fd3..747dd17 100644 --- a/include/ffi.h.in +++ b/include/ffi.h.in @@ -270,7 +270,12 @@ size_t ffi_java_raw_size (ffi_cif *cif); __declspec(align(8)) #endif typedef struct { +#if @FFI_EXEC_TRAMPOLINE_TABLE@ + void *trampoline_table; + void *trampoline_table_entry; +#else char tramp[FFI_TRAMPOLINE_SIZE]; +#endif ffi_cif *cif; void (*fun)(ffi_cif*,void*,void**,void*); void *user_data; @@ -303,7 +308,12 @@ ffi_prep_closure_loc (ffi_closure*, # pragma pack 8 #endif typedef struct { +#if @FFI_EXEC_TRAMPOLINE_TABLE@ + void *trampoline_table; + void *trampoline_table_entry; +#else char tramp[FFI_TRAMPOLINE_SIZE]; +#endif ffi_cif *cif; @@ -324,7 +334,12 @@ typedef struct { } ffi_raw_closure; typedef struct { +#if @FFI_EXEC_TRAMPOLINE_TABLE@ + void *trampoline_table; + void *trampoline_table_entry; +#else char tramp[FFI_TRAMPOLINE_SIZE]; +#endif ffi_cif *cif; From 8195e0e11df7a53fa474caa9375f73ca1136ed66 Mon Sep 17 00:00:00 2001 From: Landon Fuller Date: Sat, 12 Feb 2011 11:27:00 -0500 Subject: [PATCH 6/8] Fix symbol prefixes on Darwin. --- src/arm/sysv.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/arm/sysv.S b/src/arm/sysv.S index 895eba8..2b7ea60 100644 --- a/src/arm/sysv.S +++ b/src/arm/sysv.S @@ -170,7 +170,7 @@ ARM_FUNC_START ffi_call_SYSV @ r1 already set @ Call ffi_prep_args(stack, &ecif) - bl ffi_prep_args + bl CNAME(ffi_prep_args) @ move first 4 parameters in registers ldmia sp, {r0-r3} @@ -350,7 +350,7 @@ ARM_FUNC_START ffi_call_VFP sub r2, fp, #64 @ VFP scratch space @ Call ffi_prep_args(stack, &ecif, vfp_space) - bl ffi_prep_args + bl CNAME(ffi_prep_args) @ Load VFP register args if needed cmp r0, #0 @@ -439,7 +439,7 @@ ARM_FUNC_START ffi_closure_VFP sub sp, sp, #72 str sp, [sp, #64] add r1, sp, #64 - bl ffi_closure_SYSV_inner + bl CNAME(ffi_closure_SYSV_inner) cmp r0, #FFI_TYPE_INT beq .Lretint_vfp From a0c80f279b8733d001cb5e5c5a3289ecb7a6e56a Mon Sep 17 00:00:00 2001 From: Landon Fuller Date: Sat, 12 Feb 2011 11:43:49 -0500 Subject: [PATCH 7/8] Update my e-mail address. --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0f7d85a..4a3ceed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -43,7 +43,7 @@ * src/prep_cif.c (UNLIKELY, LIKELY): Define. (initialize_aggregate): Check for bad types. -2011-02-09 Landon Fuller +2011-02-09 Landon Fuller * Makefile.am (EXTRA_DIST): Add build-ios.sh, src/arm/gentramp.sh, src/arm/trampoline.S. From 55e4a5aa1568558a04aa40f16fc022e459af53e3 Mon Sep 17 00:00:00 2001 From: Landon Fuller Date: Sat, 12 Feb 2011 12:13:46 -0500 Subject: [PATCH 8/8] Add support for building a full armv6/armv7/i386 universal iOS library --- build-ios.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/build-ios.sh b/build-ios.sh index 1035843..3dea242 100755 --- a/build-ios.sh +++ b/build-ios.sh @@ -4,10 +4,64 @@ PLATFORM_IOS=/Developer/Platforms/iPhoneOS.platform/ PLATFORM_IOS_SIM=/Developer/Platforms/iPhoneSimulator.platform/ SDK_IOS_VERSION="4.2" MIN_IOS_VERSION="3.0" +OUTPUT_DIR="universal-ios" -mkdir -p "build-ios" -pushd "build-ios" -export CC="${PLATFORM_IOS}"/Developer/usr/bin/gcc-4.2 -export CFLAGS="-arch armv6 -isysroot ${PLATFORM_IOS}/Developer/SDKs/iPhoneOS${SDK_IOS_VERSION}.sdk/ -miphoneos-version-min=${MIN_IOS_VERSION}" -../configure --host=arm-apple-darwin10 && make -popd +build_target () { + local platform=$1 + local sdk=$2 + local arch=$3 + local triple=$4 + local builddir=$5 + + mkdir -p "${builddir}" + pushd "${builddir}" + export CC="${platform}"/Developer/usr/bin/gcc-4.2 + export CFLAGS="-arch ${arch} -isysroot ${sdk} -miphoneos-version-min=${MIN_IOS_VERSION}" + ../configure --host=${triple} && make + popd +} + +# Build all targets +build_target "${PLATFORM_IOS}" "${PLATFORM_IOS}/Developer/SDKs/iPhoneOS${SDK_IOS_VERSION}.sdk/" armv6 arm-apple-darwin10 armv6-ios +build_target "${PLATFORM_IOS}" "${PLATFORM_IOS}/Developer/SDKs/iPhoneOS${SDK_IOS_VERSION}.sdk/" armv7 arm-apple-darwin10 armv7-ios +build_target "${PLATFORM_IOS_SIM}" "${PLATFORM_IOS_SIM}/Developer/SDKs/iPhoneSimulator${SDK_IOS_VERSION}.sdk/" i386 i386-apple-darwin10 i386-ios-sim + +# Create universal output directories +mkdir -p "${OUTPUT_DIR}" +mkdir -p "${OUTPUT_DIR}/include" +mkdir -p "${OUTPUT_DIR}/include/armv6" +mkdir -p "${OUTPUT_DIR}/include/armv7" +mkdir -p "${OUTPUT_DIR}/include/i386" + +# Create the universal binary +lipo -create armv6-ios/.libs/libffi.a armv7-ios/.libs/libffi.a i386-ios-sim/.libs/libffi.a -output "${OUTPUT_DIR}/libffi.a" + +# Copy in the headers +copy_headers () { + local src=$1 + local dest=$2 + + # Fix non-relative header reference + sed 's//"ffitarget.h"/' < "${src}/include/ffi.h" > "${dest}/ffi.h" + cp "${src}/include/ffitarget.h" "${dest}" +} + +copy_headers armv6-ios "${OUTPUT_DIR}/include/armv6" +copy_headers armv7-ios "${OUTPUT_DIR}/include/armv7" +copy_headers i386-ios-sim "${OUTPUT_DIR}/include/i386" + +# Create top-level header +( +cat << EOF +#ifdef __arm__ + #include + #ifdef _ARM_ARCH_6 + #include "include/armv6/ffi.h" + #elif _ARM_ARCH_7 + #include "include/armv7/ffi.h" + #endif +#elif defined(__i386__) + #include "include/i386/ffi.h" +#endif +EOF +) > "${OUTPUT_DIR}/ffi.h"