[llvm] [OFFLOAD] Update ffi_cif structure to match libffi (PR #128756)

via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 26 09:58:04 PST 2025


https://github.com/adurang updated https://github.com/llvm/llvm-project/pull/128756

>From 9e3412a6d90d101efb39321f783eaf9715ed9596 Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Tue, 25 Feb 2025 10:22:55 -0800
Subject: [PATCH] [OFFLOAD] Update ffi_cif structure to match libffi

The ffi_cif structure defined in the wrapper header is smaller than
the actual structure in libffi which results in other structures
being overwritten when libffi is called, and finally in a segfault.

The patch updates the structure to the correct layout as specified in
ffi.h
---
 offload/plugins-nextgen/host/dynamic_ffi/ffi.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/offload/plugins-nextgen/host/dynamic_ffi/ffi.h b/offload/plugins-nextgen/host/dynamic_ffi/ffi.h
index 80aa512236d28..33285b4aef402 100644
--- a/offload/plugins-nextgen/host/dynamic_ffi/ffi.h
+++ b/offload/plugins-nextgen/host/dynamic_ffi/ffi.h
@@ -53,6 +53,16 @@ typedef enum ffi_abi {
 #else
 #error "Unknown ABI"
 #endif
+} ffi_abi;
+
+typedef struct {
+  ffi_abi abi;
+  unsigned nargs;
+  ffi_type **arg_types;
+  ffi_type *rtype;
+  unsigned bytes;
+  unsigned flags;
+  long long extra_fields; // Longest extra field defined in the FFI sources
 } ffi_cif;
 
 #ifdef __cplusplus



More information about the llvm-commits mailing list