  static pthread_mutex_t ffi_trampoline_lock = PTHREAD_MUTEX_INITIALIZER;
  static ffi_trampoline_table *ffi_trampoline_tables = NULL;
  
-@@ -195,34 +214,61 @@
+@@ -195,34 +218,67 @@
    kern_return_t kt;
    uint16_t i;
  

 
       if (i < table->free_count - 1)
 	entry->next = &table->free_list_pool[i + 1];
diff -ur libffi-3.3/src/prep_cif.c libffi-3.3.new/src/prep_cif.c
--- libffi-3.3/src/prep_cif.c	2019-10-31 08:49:54.000000000 -0600
+++ libffi-3.3.new/src/prep_cif.c	2021-01-04 19:39:16.000000000 -0700
@@ -234,7 +234,7 @@
   return ffi_prep_cif_core(cif, abi, 1, nfixedargs, ntotalargs, rtype, atypes);
 }
 
-#if FFI_CLOSURES
+#if FFI_CLOSURES && FFI_LEGACY_CLOSURE_API
 
 ffi_status
 ffi_prep_closure (ffi_closure* closure,
diff -ur libffi-3.3/src/x86/ffi.c libffi-3.3.new/src/x86/ffi.c
--- libffi-3.3/src/x86/ffi.c	2019-10-31 08:49:54.000000000 -0600
+++ libffi-3.3.new/src/x86/ffi.c	2021-01-04 19:38:38.000000000 -0700

 	      }
 	  }
 	  break;
@@ -756,6 +761,8 @@
   ffi_call_int (cif, fn, rvalue, avalue, NULL);
 }
 
+#if FFI_CLOSURES
+
 #ifdef FFI_GO_CLOSURES
 void
 ffi_call_go (ffi_cif *cif, void (*fn) (void), void *rvalue,
@@ -789,7 +796,14 @@
 
 #if FFI_EXEC_TRAMPOLINE_TABLE
 #ifdef __MACH__
+#ifdef HAVE_PTRAUTH
+  codeloc = ptrauth_auth_data(codeloc, ptrauth_key_function_pointer, 0);
+#endif
+#ifdef FFI_TRAMPOLINE_WHOLE_DYLIB
