diff --git a/add-loongarch64-support.patch b/add-loongarch64-support.patch deleted file mode 100644 index e2eebf1f26e387fde3e2e79606ba4e7becd801c6..0000000000000000000000000000000000000000 --- a/add-loongarch64-support.patch +++ /dev/null @@ -1,1021 +0,0 @@ -From bd1aa6c52aa7753a502c191dcb9f941351c6dcc2 Mon Sep 17 00:00:00 2001 -From: baizg1107 -Date: Tue, 19 Apr 2022 17:41:00 +0800 -Subject: [PATCH] add loongarch support - ---- - Makefile.am | 4 +- - Makefile.in | 26 +- - configure.host | 4 + - src/loongarch/ffi.c | 490 ++++++++++++++++++++++++++++++++++++++ - src/loongarch/ffitarget.h | 68 ++++++ - src/loongarch/sysv.S | 288 ++++++++++++++++++++++ - 6 files changed, 878 insertions(+), 2 deletions(-) - create mode 100644 src/loongarch/ffi.c - create mode 100644 src/loongarch/ffitarget.h - create mode 100644 src/loongarch/sysv.S - -diff --git a/Makefile.am b/Makefile.am -index 1b18198..754b41a 100644 ---- a/Makefile.am -+++ b/Makefile.am -@@ -51,6 +51,7 @@ noinst_HEADERS = src/aarch64/ffitarget.h src/aarch64/internal.h \ - src/avr32/ffitarget.h src/bfin/ffitarget.h \ - src/cris/ffitarget.h src/csky/ffitarget.h src/frv/ffitarget.h \ - src/ia64/ffitarget.h src/ia64/ia64_flags.h \ -+ src/loongarch/ffitarget.h \ - src/m32r/ffitarget.h src/m68k/ffitarget.h \ - src/m88k/ffitarget.h src/metag/ffitarget.h \ - src/microblaze/ffitarget.h src/mips/ffitarget.h \ -@@ -72,7 +73,8 @@ EXTRA_libffi_la_SOURCES = src/aarch64/ffi.c src/aarch64/sysv.S \ - src/avr32/ffi.c src/avr32/sysv.S src/bfin/ffi.c \ - src/bfin/sysv.S src/cris/ffi.c src/cris/sysv.S src/frv/ffi.c \ - src/csky/ffi.c src/csky/sysv.S src/frv/eabi.S src/ia64/ffi.c \ -- src/ia64/unix.S src/m32r/ffi.c src/m32r/sysv.S src/m68k/ffi.c \ -+ src/ia64/unix.S src/loongarch/ffi.c src/loongarch/sysv.S \ -+ src/m32r/ffi.c src/m32r/sysv.S src/m68k/ffi.c \ - src/m68k/sysv.S src/m88k/ffi.c src/m88k/obsd.S \ - src/metag/ffi.c src/metag/sysv.S src/microblaze/ffi.c \ - src/microblaze/sysv.S src/mips/ffi.c src/mips/o32.S \ -diff --git a/Makefile.in b/Makefile.in -index a4b67a7..739e066 100644 ---- a/Makefile.in -+++ b/Makefile.in -@@ -212,6 +212,7 @@ am__depfiles_remade = src/$(DEPDIR)/closures.Plo \ - src/frv/$(DEPDIR)/eabi.Plo src/frv/$(DEPDIR)/ffi.Plo \ - src/ia64/$(DEPDIR)/ffi.Plo src/ia64/$(DEPDIR)/unix.Plo \ - src/kvx/$(DEPDIR)/ffi.Plo src/kvx/$(DEPDIR)/sysv.Plo \ -+ src/loongarch/$(DEPDIR)/ffi.Plo src/loongarch/$(DEPDIR)/sysv.Plo \ - src/m32r/$(DEPDIR)/ffi.Plo src/m32r/$(DEPDIR)/sysv.Plo \ - src/m68k/$(DEPDIR)/ffi.Plo src/m68k/$(DEPDIR)/sysv.Plo \ - src/m88k/$(DEPDIR)/ffi.Plo src/m88k/$(DEPDIR)/obsd.Plo \ -@@ -552,6 +553,7 @@ noinst_HEADERS = src/aarch64/ffitarget.h src/aarch64/internal.h \ - src/avr32/ffitarget.h src/bfin/ffitarget.h \ - src/cris/ffitarget.h src/csky/ffitarget.h src/frv/ffitarget.h \ - src/ia64/ffitarget.h src/ia64/ia64_flags.h \ -+ src/loongarch/ffitarget.h \ - src/m32r/ffitarget.h src/m68k/ffitarget.h \ - src/m88k/ffitarget.h src/metag/ffitarget.h \ - src/microblaze/ffitarget.h src/mips/ffitarget.h \ -@@ -573,7 +575,8 @@ EXTRA_libffi_la_SOURCES = src/aarch64/ffi.c src/aarch64/sysv.S \ - src/avr32/ffi.c src/avr32/sysv.S src/bfin/ffi.c \ - src/bfin/sysv.S src/cris/ffi.c src/cris/sysv.S src/frv/ffi.c \ - src/csky/ffi.c src/csky/sysv.S src/frv/eabi.S src/ia64/ffi.c \ -- src/ia64/unix.S src/m32r/ffi.c src/m32r/sysv.S src/m68k/ffi.c \ -+ src/ia64/unix.S src/loongarch/ffi.c src/loongarch/sysv.S \ -+ src/m32r/ffi.c src/m32r/sysv.S src/m68k/ffi.c \ - src/m68k/sysv.S src/m88k/ffi.c src/m88k/obsd.S \ - src/metag/ffi.c src/metag/sysv.S src/microblaze/ffi.c \ - src/microblaze/sysv.S src/mips/ffi.c src/mips/o32.S \ -@@ -833,6 +836,16 @@ src/ia64/ffi.lo: src/ia64/$(am__dirstamp) \ - src/ia64/$(DEPDIR)/$(am__dirstamp) - src/ia64/unix.lo: src/ia64/$(am__dirstamp) \ - src/ia64/$(DEPDIR)/$(am__dirstamp) -+src/loongarch/$(am__dirstamp): -+ @$(MKDIR_P) src/loongarch -+ @: > src/loongarch/$(am__dirstamp) -+src/loongarch/$(DEPDIR)/$(am__dirstamp): -+ @$(MKDIR_P) src/loongarch/$(DEPDIR) -+ @: > src/loongarch/$(DEPDIR)/$(am__dirstamp) -+src/loongarch/ffi.lo: src/loongarch/$(am__dirstamp) \ -+ src/loongarch/$(DEPDIR)/$(am__dirstamp) -+src/loongarch/sysv.lo: src/loongarch/$(am__dirstamp) \ -+ src/loongarch/$(DEPDIR)/$(am__dirstamp) - src/m32r/$(am__dirstamp): - @$(MKDIR_P) src/m32r - @: > src/m32r/$(am__dirstamp) -@@ -1114,6 +1127,8 @@ mostlyclean-compile: - -rm -f src/ia64/*.lo - -rm -f src/kvx/*.$(OBJEXT) - -rm -f src/kvx/*.lo -+ -rm -f src/loongarch/*.$(OBJEXT) -+ -rm -f src/loongarch/*.lo - -rm -f src/m32r/*.$(OBJEXT) - -rm -f src/m32r/*.lo - -rm -f src/m68k/*.$(OBJEXT) -@@ -1189,6 +1204,8 @@ distclean-compile: - @AMDEP_TRUE@@am__include@ @am__quote@src/ia64/$(DEPDIR)/unix.Plo@am__quote@ # am--include-marker - @AMDEP_TRUE@@am__include@ @am__quote@src/kvx/$(DEPDIR)/ffi.Plo@am__quote@ # am--include-marker - @AMDEP_TRUE@@am__include@ @am__quote@src/kvx/$(DEPDIR)/sysv.Plo@am__quote@ # am--include-marker -+@AMDEP_TRUE@@am__include@ @am__quote@src/loongarch/$(DEPDIR)/ffi.Plo@am__quote@ # am--include-marker -+@AMDEP_TRUE@@am__include@ @am__quote@src/loongarch/$(DEPDIR)/sysv.Plo@am__quote@ # am--include-marker - @AMDEP_TRUE@@am__include@ @am__quote@src/m32r/$(DEPDIR)/ffi.Plo@am__quote@ # am--include-marker - @AMDEP_TRUE@@am__include@ @am__quote@src/m32r/$(DEPDIR)/sysv.Plo@am__quote@ # am--include-marker - @AMDEP_TRUE@@am__include@ @am__quote@src/m68k/$(DEPDIR)/ffi.Plo@am__quote@ # am--include-marker -@@ -1321,6 +1338,7 @@ clean-libtool: - -rm -rf src/frv/.libs src/frv/_libs - -rm -rf src/ia64/.libs src/ia64/_libs - -rm -rf src/kvx/.libs src/kvx/_libs -+ -rm -rf src/loongarch/.libs src/loongarch/_libs - -rm -rf src/m32r/.libs src/m32r/_libs - -rm -rf src/m68k/.libs src/m68k/_libs - -rm -rf src/m88k/.libs src/m88k/_libs -@@ -1730,6 +1748,8 @@ distclean-generic: - -rm -f src/ia64/$(am__dirstamp) - -rm -f src/kvx/$(DEPDIR)/$(am__dirstamp) - -rm -f src/kvx/$(am__dirstamp) -+ -rm -f src/loongarch/$(DEPDIR)/$(am__dirstamp) -+ -rm -f src/loongarch/$(am__dirstamp) - -rm -f src/m32r/$(DEPDIR)/$(am__dirstamp) - -rm -f src/m32r/$(am__dirstamp) - -rm -f src/m68k/$(DEPDIR)/$(am__dirstamp) -@@ -1813,6 +1833,8 @@ distclean: distclean-recursive - -rm -f src/ia64/$(DEPDIR)/unix.Plo - -rm -f src/kvx/$(DEPDIR)/ffi.Plo - -rm -f src/kvx/$(DEPDIR)/sysv.Plo -+ -rm -f src/loongarch/$(DEPDIR)/ffi.Plo -+ -rm -f src/loongarch/$(DEPDIR)/sysv.Plo - -rm -f src/m32r/$(DEPDIR)/ffi.Plo - -rm -f src/m32r/$(DEPDIR)/sysv.Plo - -rm -f src/m68k/$(DEPDIR)/ffi.Plo -@@ -1951,6 +1973,8 @@ maintainer-clean: maintainer-clean-recursive - -rm -f src/ia64/$(DEPDIR)/unix.Plo - -rm -f src/kvx/$(DEPDIR)/ffi.Plo - -rm -f src/kvx/$(DEPDIR)/sysv.Plo -+ -rm -f src/loongarch/$(DEPDIR)/ffi.Plo -+ -rm -f src/loongarch/$(DEPDIR)/sysv.Plo - -rm -f src/m32r/$(DEPDIR)/ffi.Plo - -rm -f src/m32r/$(DEPDIR)/sysv.Plo - -rm -f src/m68k/$(DEPDIR)/ffi.Plo -diff --git a/configure.host b/configure.host -index 2682671..ff3fb6e 100644 ---- a/configure.host -+++ b/configure.host -@@ -139,6 +139,10 @@ case "${host}" in - TARGET=KVX; TARGETDIR=kvx - SOURCES="ffi.c sysv.S" - ;; -+ loongarch64-*-*) -+ TARGET=LOONGARCH; TARGETDIR=loongarch -+ SOURCES="ffi.c sysv.S" -+ ;; - - m32r*-*-*) - TARGET=M32R; TARGETDIR=m32r -diff --git a/src/loongarch/ffi.c b/src/loongarch/ffi.c -new file mode 100644 -index 0000000..4d12477 ---- /dev/null -+++ b/src/loongarch/ffi.c -@@ -0,0 +1,490 @@ -+/* ----------------------------------------------------------------------- -+ ffi.c - Copyright (c) 2015 Michael Knyszek -+ 2015 Andrew Waterman -+ 2018 Stef O'Rear -+ Based on MIPS N32/64 port -+ -+ LOONGARCH Foreign Function Interface -+ -+ Permission is hereby granted, free of charge, to any person obtaining -+ a copy of this software and associated documentation files (the -+ ``Software''), to deal in the Software without restriction, including -+ without limitation the rights to use, copy, modify, merge, publish, -+ distribute, sublicense, and/or sell copies of the Software, and to -+ permit persons to whom the Software is furnished to do so, subject to -+ the following conditions: -+ -+ The above copyright notice and this permission notice shall be included -+ in all copies or substantial portions of the Software. -+ -+ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, -+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -+ DEALINGS IN THE SOFTWARE. -+ ----------------------------------------------------------------------- */ -+ -+#include -+#include -+ -+#include -+#include -+ -+#define ABI_FLEN 64 -+#define ABI_FLOAT double -+ -+#define NARGREG 8 -+#define STKALIGN 16 -+#define MAXCOPYARG (2 * sizeof(double)) -+ -+typedef struct call_context -+{ -+ ABI_FLOAT fa[8]; -+ size_t a[8]; -+ /* used by the assembly code to in-place construct its own stack frame */ -+ char frame[16]; -+} call_context; -+ -+typedef struct call_builder -+{ -+ call_context *aregs; -+ int used_integer; -+ int used_float; -+ size_t *used_stack; -+} call_builder; -+ -+/* integer (not pointer) less than ABI XLEN */ -+/* FFI_TYPE_INT does not appear to be used */ -+#if __SIZEOF_POINTER__ == 8 -+#define IS_INT(type) ((type) >= FFI_TYPE_UINT8 && (type) <= FFI_TYPE_SINT64) -+#else -+#define IS_INT(type) ((type) >= FFI_TYPE_UINT8 && (type) <= FFI_TYPE_SINT32) -+#endif -+ -+#if ABI_FLEN -+typedef struct { -+ char as_elements, type1, offset2, type2; -+} float_struct_info; -+ -+#if ABI_FLEN >= 64 -+#define IS_FLOAT(type) ((type) >= FFI_TYPE_FLOAT && (type) <= FFI_TYPE_DOUBLE) -+#else -+#define IS_FLOAT(type) ((type) == FFI_TYPE_FLOAT) -+#endif -+ -+static ffi_type **flatten_struct(ffi_type *in, ffi_type **out, ffi_type **out_end) { -+ int i; -+ if (out == out_end) return out; -+ if (in->type != FFI_TYPE_STRUCT) { -+ *(out++) = in; -+ } else { -+ for (i = 0; in->elements[i]; i++) -+ out = flatten_struct(in->elements[i], out, out_end); -+ } -+ return out; -+} -+ -+/* Structs with at most two fields after flattening, one of which is of -+ floating point type, are passed in multiple registers if sufficient -+ registers are available. */ -+static float_struct_info struct_passed_as_elements(call_builder *cb, ffi_type *top) { -+ float_struct_info ret = {0, 0, 0, 0}; -+ ffi_type *fields[3]; -+ int num_floats, num_ints; -+ int num_fields = flatten_struct(top, fields, fields + 3) - fields; -+ -+ if (num_fields == 1) { -+ if (IS_FLOAT(fields[0]->type)) { -+ ret.as_elements = 1; -+ ret.type1 = fields[0]->type; -+ } -+ } else if (num_fields == 2) { -+ num_floats = IS_FLOAT(fields[0]->type) + IS_FLOAT(fields[1]->type); -+ num_ints = IS_INT(fields[0]->type) + IS_INT(fields[1]->type); -+ if (num_floats == 0 || num_floats + num_ints != 2) -+ return ret; -+ if (cb->used_float + num_floats > NARGREG || cb->used_integer + (2 - num_floats) > NARGREG) -+ return ret; -+ if (!IS_FLOAT(fields[0]->type) && !IS_FLOAT(fields[1]->type)) -+ return ret; -+ -+ ret.type1 = fields[0]->type; -+ ret.type2 = fields[1]->type; -+ ret.offset2 = FFI_ALIGN(fields[0]->size, fields[1]->alignment); -+ ret.as_elements = 1; -+ } -+ -+ return ret; -+} -+#endif -+ -+/* allocates a single register, float register, or XLEN-sized stack slot to a datum */ -+static void marshal_atom(call_builder *cb, int type, void *data) { -+ size_t value = 0; -+ switch (type) { -+ case FFI_TYPE_UINT8: value = *(uint8_t *)data; break; -+ case FFI_TYPE_SINT8: value = *(int8_t *)data; break; -+ case FFI_TYPE_UINT16: value = *(uint16_t *)data; break; -+ case FFI_TYPE_SINT16: value = *(int16_t *)data; break; -+ /* 32-bit quantities are always sign-extended in the ABI */ -+ case FFI_TYPE_UINT32: value = *(int32_t *)data; break; -+ case FFI_TYPE_SINT32: value = *(int32_t *)data; break; -+#if __SIZEOF_POINTER__ == 8 -+ case FFI_TYPE_UINT64: value = *(uint64_t *)data; break; -+ case FFI_TYPE_SINT64: value = *(int64_t *)data; break; -+#endif -+ case FFI_TYPE_POINTER: value = *(size_t *)data; break; -+ -+ /* float values may be recoded in an implementation-defined way -+ by hardware conforming to 2.1 or earlier, so use asm to -+ reinterpret floats as doubles */ -+#if ABI_FLEN >= 32 -+ case FFI_TYPE_FLOAT: -+ asm("" : "=f"(cb->aregs->fa[cb->used_float++]) : "0"(*(float *)data)); -+ return; -+#endif -+#if ABI_FLEN >= 64 -+ case FFI_TYPE_DOUBLE: -+ asm("" : "=f"(cb->aregs->fa[cb->used_float++]) : "0"(*(double *)data)); -+ return; -+#endif -+ default: FFI_ASSERT(0); break; -+ } -+ -+ if (cb->used_integer == NARGREG) { -+ *cb->used_stack++ = value; -+ } else { -+ cb->aregs->a[cb->used_integer++] = value; -+ } -+} -+ -+static void unmarshal_atom(call_builder *cb, int type, void *data) { -+ size_t value; -+ switch (type) { -+#if ABI_FLEN >= 32 -+ case FFI_TYPE_FLOAT: -+ asm("" : "=f"(*(float *)data) : "0"(cb->aregs->fa[cb->used_float++])); -+ return; -+#endif -+#if ABI_FLEN >= 64 -+ case FFI_TYPE_DOUBLE: -+ asm("" : "=f"(*(double *)data) : "0"(cb->aregs->fa[cb->used_float++])); -+ return; -+#endif -+ } -+ -+ if (cb->used_integer == NARGREG) { -+ value = *cb->used_stack++; -+ } else { -+ value = cb->aregs->a[cb->used_integer++]; -+ } -+ -+ switch (type) { -+ case FFI_TYPE_UINT8: *(uint8_t *)data = value; break; -+ case FFI_TYPE_SINT8: *(uint8_t *)data = value; break; -+ case FFI_TYPE_UINT16: *(uint16_t *)data = value; break; -+ case FFI_TYPE_SINT16: *(uint16_t *)data = value; break; -+ case FFI_TYPE_UINT32: *(uint32_t *)data = value; break; -+ case FFI_TYPE_SINT32: *(uint32_t *)data = value; break; -+#if __SIZEOF_POINTER__ == 8 -+ case FFI_TYPE_UINT64: *(uint64_t *)data = value; break; -+ case FFI_TYPE_SINT64: *(uint64_t *)data = value; break; -+#endif -+ case FFI_TYPE_POINTER: *(size_t *)data = value; break; -+ default: FFI_ASSERT(0); break; -+ } -+} -+ -+/* adds an argument to a call, or a not by reference return value */ -+static void marshal(call_builder *cb, ffi_type *type, int var, void *data) { -+ size_t realign[2]; -+ -+#if ABI_FLEN -+ if (!var && type->type == FFI_TYPE_STRUCT) { -+ float_struct_info fsi = struct_passed_as_elements(cb, type); -+ if (fsi.as_elements) { -+ marshal_atom(cb, fsi.type1, data); -+ if (fsi.offset2) -+ marshal_atom(cb, fsi.type2, ((char*)data) + fsi.offset2); -+ return; -+ } -+ } -+ -+ if (!var && cb->used_float < NARGREG && IS_FLOAT(type->type)) { -+ marshal_atom(cb, type->type, data); -+ return; -+ } -+ -+ double promoted; -+ if (var && type->type == FFI_TYPE_FLOAT) -+ { -+ /* C standard requires promoting float -> double for variable arg */ -+ promoted = *(float *)data; -+ type = &ffi_type_double; -+ data = &promoted; -+ } -+#endif -+ -+ if (type->size > 2 * __SIZEOF_POINTER__) { -+ /* pass by reference */ -+ marshal_atom(cb, FFI_TYPE_POINTER, &data); -+ } else if (IS_INT(type->type) || type->type == FFI_TYPE_POINTER) { -+ marshal_atom(cb, type->type, data); -+ } else { -+ /* overlong integers, soft-float floats, and structs without special -+ float handling are treated identically from this point on */ -+ -+ /* variadics are aligned even in registers */ -+ if (type->alignment > __SIZEOF_POINTER__) { -+ if (var) -+ cb->used_integer = FFI_ALIGN(cb->used_integer, 2); -+ cb->used_stack = (size_t *)FFI_ALIGN(cb->used_stack, 2*__SIZEOF_POINTER__); -+ } -+ -+ memcpy(realign, data, type->size); -+ if (type->size > 0) -+ marshal_atom(cb, FFI_TYPE_POINTER, realign); -+ if (type->size > __SIZEOF_POINTER__) -+ marshal_atom(cb, FFI_TYPE_POINTER, realign + 1); -+ } -+} -+ -+/* for arguments passed by reference returns the pointer, otherwise the arg is copied (up to MAXCOPYARG bytes) */ -+static void *unmarshal(call_builder *cb, ffi_type *type, int var, void *data) { -+ size_t realign[2]; -+ void *pointer; -+ -+#if ABI_FLEN -+ if (!var && type->type == FFI_TYPE_STRUCT) { -+ float_struct_info fsi = struct_passed_as_elements(cb, type); -+ if (fsi.as_elements) { -+ unmarshal_atom(cb, fsi.type1, data); -+ if (fsi.offset2) -+ unmarshal_atom(cb, fsi.type2, ((char*)data) + fsi.offset2); -+ return data; -+ } -+ } -+ -+ if (!var && cb->used_float < NARGREG && IS_FLOAT(type->type)) { -+ unmarshal_atom(cb, type->type, data); -+ return data; -+ } -+ -+ if (var && type->type == FFI_TYPE_FLOAT) -+ { -+ int m = cb->used_integer; -+ void *promoted = m < NARGREG ? cb->aregs->a + m:cb->used_stack + m - NARGREG + 1; -+ *(float*)promoted = *(double *)promoted; -+ } -+#endif -+ -+ if (type->size > 2 * __SIZEOF_POINTER__) { -+ /* pass by reference */ -+ unmarshal_atom(cb, FFI_TYPE_POINTER, (char*)&pointer); -+ return pointer; -+ } else if (IS_INT(type->type) || type->type == FFI_TYPE_POINTER) { -+ unmarshal_atom(cb, type->type, data); -+ return data; -+ } else { -+ /* overlong integers, soft-float floats, and structs without special -+ float handling are treated identically from this point on */ -+ -+ /* variadics are aligned even in registers */ -+ if (type->alignment > __SIZEOF_POINTER__) { -+ if (var) -+ cb->used_integer = FFI_ALIGN(cb->used_integer, 2); -+ cb->used_stack = (size_t *)FFI_ALIGN(cb->used_stack, 2*__SIZEOF_POINTER__); -+ } -+ -+ if (type->size > 0) -+ unmarshal_atom(cb, FFI_TYPE_POINTER, realign); -+ if (type->size > __SIZEOF_POINTER__) -+ unmarshal_atom(cb, FFI_TYPE_POINTER, realign + 1); -+ memcpy(data, realign, type->size); -+ return data; -+ } -+} -+ -+static int passed_by_ref(call_builder *cb, ffi_type *type, int var) { -+#if ABI_FLEN -+ if (!var && type->type == FFI_TYPE_STRUCT) { -+ float_struct_info fsi = struct_passed_as_elements(cb, type); -+ if (fsi.as_elements) return 0; -+ } -+#endif -+ -+ return type->size > 2 * __SIZEOF_POINTER__; -+} -+ -+/* Perform machine dependent cif processing */ -+ffi_status ffi_prep_cif_machdep(ffi_cif *cif) { -+ cif->loongarch_nfixedargs = cif->nargs; -+ return FFI_OK; -+} -+ -+/* Perform machine dependent cif processing when we have a variadic function */ -+ -+ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif, unsigned int nfixedargs, unsigned int ntotalargs) { -+ cif->loongarch_nfixedargs = nfixedargs; -+ return FFI_OK; -+} -+ -+/* Low level routine for calling functions */ -+extern void ffi_call_asm (void *stack, struct call_context *regs, -+ void (*fn) (void), void *closure) FFI_HIDDEN; -+ -+static void -+ffi_call_int (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue, -+ void *closure) -+{ -+ /* this is a conservative estimate, assuming a complex return value and -+ that all remaining arguments are long long / __int128 */ -+ size_t arg_bytes = cif->nargs <= 3 ? 0 : -+ FFI_ALIGN(2 * sizeof(size_t) * (cif->nargs - 3), STKALIGN); -+ size_t rval_bytes = 0; -+ if (rvalue == NULL && cif->rtype->size > 2*__SIZEOF_POINTER__) -+ rval_bytes = FFI_ALIGN(cif->rtype->size, STKALIGN); -+ size_t alloc_size = arg_bytes + rval_bytes + sizeof(call_context); -+ -+ /* the assembly code will deallocate all stack data at lower addresses -+ than the argument region, so we need to allocate the frame and the -+ return value after the arguments in a single allocation */ -+ size_t alloc_base; -+ /* Argument region must be 16-byte aligned */ -+ if (_Alignof(max_align_t) >= STKALIGN) { -+ /* since sizeof long double is normally 16, the compiler will -+ guarantee alloca alignment to at least that much */ -+ alloc_base = (size_t)alloca(alloc_size); -+ } else { -+ alloc_base = FFI_ALIGN(alloca(alloc_size + STKALIGN - 1), STKALIGN); -+ } -+ -+ if (rval_bytes) -+ rvalue = (void*)(alloc_base + arg_bytes); -+ -+ call_builder cb; -+ cb.used_float = cb.used_integer = 0; -+ cb.aregs = (call_context*)(alloc_base + arg_bytes + rval_bytes); -+ cb.used_stack = (void*)alloc_base; -+ -+ int return_by_ref = passed_by_ref(&cb, cif->rtype, 0); -+ if (return_by_ref) -+ marshal(&cb, &ffi_type_pointer, 0, &rvalue); -+ -+ int i; -+ for (i = 0; i < cif->nargs; i++) -+ marshal(&cb, cif->arg_types[i], i >= cif->loongarch_nfixedargs, avalue[i]); -+ -+ ffi_call_asm ((void *) alloc_base, cb.aregs, fn, closure); -+ -+ cb.used_float = cb.used_integer = 0; -+ if (!return_by_ref && rvalue) -+ unmarshal(&cb, cif->rtype, 0, rvalue); -+} -+ -+void -+ffi_call (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue) -+{ -+ ffi_call_int(cif, fn, rvalue, avalue, NULL); -+} -+ -+void -+ffi_call_go (ffi_cif *cif, void (*fn) (void), void *rvalue, -+ void **avalue, void *closure) -+{ -+ ffi_call_int(cif, fn, rvalue, avalue, closure); -+} -+ -+extern void ffi_closure_asm(void) FFI_HIDDEN; -+ -+ffi_status ffi_prep_closure_loc(ffi_closure *closure, ffi_cif *cif, void (*fun)(ffi_cif*,void*,void**,void*), void *user_data, void *codeloc) -+{ -+ uint32_t *tramp = (uint32_t *) &closure->tramp[0]; -+ uint64_t fn = (uint64_t) (uintptr_t) ffi_closure_asm; -+ -+ if (cif->abi <= FFI_FIRST_ABI || cif->abi >= FFI_LAST_ABI) -+ return FFI_BAD_ABI; -+ -+ /* we will call ffi_closure_inner with codeloc, not closure, but as long -+ as the memory is readable it should work */ -+ -+ tramp[0] = 0x1800000c; /* pcaddi $t0, 0 (i.e. $t0 <- tramp) */ -+#ifdef _ABILP64 -+ tramp[1] = 0x28c0418d; /* ld.d $t1, $t0, 16 */ -+#elif defined _ABILPX32 -+ tramp[1] = 0x2880418d; /* ld.w $t1, $t0, 16 */ -+#endif -+ tramp[2] = 0x4c0001a0; /* jirl $zero, $t1, 0 */ -+ tramp[3] = 0x03400000; /* nop */ -+ tramp[4] = fn; -+ tramp[5] = fn >> 32; -+ -+ closure->cif = cif; -+ closure->fun = fun; -+ closure->user_data = user_data; -+ -+ __builtin___clear_cache(codeloc, codeloc + FFI_TRAMPOLINE_SIZE); -+ -+ return FFI_OK; -+} -+ -+extern void ffi_go_closure_asm (void) FFI_HIDDEN; -+ -+ffi_status -+ffi_prep_go_closure (ffi_go_closure *closure, ffi_cif *cif, -+ void (*fun) (ffi_cif *, void *, void **, void *)) -+{ -+ if (cif->abi <= FFI_FIRST_ABI || cif->abi >= FFI_LAST_ABI) -+ return FFI_BAD_ABI; -+ -+ closure->tramp = (void *) ffi_go_closure_asm; -+ closure->cif = cif; -+ closure->fun = fun; -+ -+ return FFI_OK; -+} -+ -+/* Called by the assembly code with aregs pointing to saved argument registers -+ and stack pointing to the stacked arguments. Return values passed in -+ registers will be reloaded from aregs. */ -+void FFI_HIDDEN -+ffi_closure_inner (ffi_cif *cif, -+ void (*fun) (ffi_cif *, void *, void **, void *), -+ void *user_data, -+ size_t *stack, call_context *aregs) -+{ -+ void **avalue = alloca(cif->nargs * sizeof(void*)); -+ /* storage for arguments which will be copied by unmarshal(). We could -+ theoretically avoid the copies in many cases and use at most 128 bytes -+ of memory, but allocating disjoint storage for each argument is -+ simpler. */ -+ char *astorage = alloca(cif->nargs * MAXCOPYARG); -+ void *rvalue; -+ call_builder cb; -+ int return_by_ref; -+ int i; -+ -+ cb.aregs = aregs; -+ cb.used_integer = cb.used_float = 0; -+ cb.used_stack = stack; -+ -+ return_by_ref = passed_by_ref(&cb, cif->rtype, 0); -+ if (return_by_ref) -+ unmarshal(&cb, &ffi_type_pointer, 0, &rvalue); -+ else -+ rvalue = alloca(cif->rtype->size); -+ -+ for (i = 0; i < cif->nargs; i++) -+ avalue[i] = unmarshal(&cb, cif->arg_types[i], -+ i >= cif->loongarch_nfixedargs, astorage + i*MAXCOPYARG); -+ -+ fun (cif, rvalue, avalue, user_data); -+ -+ if (!return_by_ref && cif->rtype->type != FFI_TYPE_VOID) { -+ cb.used_integer = cb.used_float = 0; -+ marshal(&cb, cif->rtype, 0, rvalue); -+ } -+} -diff --git a/src/loongarch/ffitarget.h b/src/loongarch/ffitarget.h -new file mode 100644 -index 0000000..42ebf46 ---- /dev/null -+++ b/src/loongarch/ffitarget.h -@@ -0,0 +1,68 @@ -+/* -----------------------------------------------------------------*-C-*- -+ ffitarget.h - 2014 Michael Knyszek -+ -+ Target configuration macros for LOONGARCH. -+ -+ Permission is hereby granted, free of charge, to any person obtaining -+ a copy of this software and associated documentation files (the -+ ``Software''), to deal in the Software without restriction, including -+ without limitation the rights to use, copy, modify, merge, publish, -+ distribute, sublicense, and/or sell copies of the Software, and to -+ permit persons to whom the Software is furnished to do so, subject to -+ the following conditions: -+ -+ The above copyright notice and this permission notice shall be included -+ in all copies or substantial portions of the Software. -+ -+ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, -+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -+ DEALINGS IN THE SOFTWARE. -+ -+ ----------------------------------------------------------------------- */ -+ -+#ifndef LIBFFI_TARGET_H -+#define LIBFFI_TARGET_H -+ -+#ifndef LIBFFI_H -+#error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." -+#endif -+ -+#ifndef __loongarch__ -+#error "libffi was configured for a LOONGARCH target but this does not appear to be a LOONGARCH compiler." -+#endif -+ -+#ifndef LIBFFI_ASM -+ -+typedef unsigned long ffi_arg; -+typedef signed long ffi_sarg; -+ -+/* FFI_UNUSED_NN and loongarch_unused are to maintain ABI compatibility with a -+ distributed Berkeley patch from 2014, and can be removed at SONAME bump */ -+typedef enum ffi_abi { -+ FFI_FIRST_ABI = 0, -+ FFI_LP64, -+ FFI_UNUSED_1, -+ FFI_UNUSED_2, -+ FFI_UNUSED_3, -+ FFI_LAST_ABI, -+ -+ FFI_DEFAULT_ABI = FFI_LP64 -+} ffi_abi; -+ -+#endif /* LIBFFI_ASM */ -+ -+/* ---- Definitions for closures ----------------------------------------- */ -+ -+#define FFI_CLOSURES 1 -+#define FFI_GO_CLOSURES 1 -+#define FFI_TRAMPOLINE_SIZE 24 -+#define FFI_NATIVE_RAW_API 0 -+#define FFI_EXTRA_CIF_FIELDS unsigned loongarch_nfixedargs; unsigned loongarch_unused; -+#define FFI_TARGET_SPECIFIC_VARIADIC -+//#define FFI_TARGET_HAS_COMPLEX_TYPE 1 -+#endif -diff --git a/src/loongarch/sysv.S b/src/loongarch/sysv.S -new file mode 100644 -index 0000000..1d5bac1 ---- /dev/null -+++ b/src/loongarch/sysv.S -@@ -0,0 +1,288 @@ -+/* ----------------------------------------------------------------------- -+ ffi.c - Copyright (c) 2015 Michael Knyszek -+ 2015 Andrew Waterman -+ 2018 Stef O'Rear -+ -+ LOONGARCH Foreign Function Interface -+ -+ Permission is hereby granted, free of charge, to any person obtaining -+ a copy of this software and associated documentation files (the -+ ``Software''), to deal in the Software without restriction, including -+ without limitation the rights to use, copy, modify, merge, publish, -+ distribute, sublicense, and/or sell copies of the Software, and to -+ permit persons to whom the Software is furnished to do so, subject to -+ the following conditions: -+ -+ The above copyright notice and this permission notice shall be included -+ in all copies or substantial portions of the Software. -+ -+ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, -+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -+ DEALINGS IN THE SOFTWARE. -+ ----------------------------------------------------------------------- */ -+ -+#define LIBFFI_ASM -+#include -+#include -+ -+/* Define aliases so that we can handle all ABIs uniformly */ -+ -+#if __SIZEOF_POINTER__ == 8 -+#define PTRS 8 -+#define LARG ld.d -+#define SARG st.d -+#else -+#define PTRS 4 -+#define LARG ld.w -+#define SARG st.w -+#endif -+ -+#ifdef __loongarch_hard_float -+# if defined __loongarch_single_float -+# define FLT float -+# define FLEN 4 -+# define FLD fld.w -+# define FST fst.w -+# error "need check" -+# else -+# define FLT double -+# define FLEN 8 -+# define FLARG fld.d -+# define FSARG fst.d -+# endif -+#else -+# define FLEN 0 -+# error "need check" -+#endif -+ -+#define FLTS 8 -+ -+ -+ .text -+ .globl ffi_call_asm -+ .type ffi_call_asm, @function -+ .hidden ffi_call_asm -+/* -+ struct call_context { -+ floatreg fa[8]; -+ intreg a[8]; -+ intreg pad[rv32 ? 2 : 0]; -+ intreg save_fp, save_ra; -+ } -+ void ffi_call_asm (size_t *stackargs, struct call_context *regargs, -+ void (*fn) (void), void *closure); -+*/ -+ -+#define FRAME_LEN (8 * FLTS + 8 * PTRS + 8 * 2) -+ -+ffi_call_asm: -+ .cfi_startproc -+ -+ /* -+ We are NOT going to set up an ordinary stack frame. In order to pass -+ the stacked args to the called function, we adjust our stack pointer to -+ a0, which is in the _caller's_ alloca area. We establish our own stack -+ frame at the end of the call_context. -+ -+ Anything below the arguments will be freed at this point, although we -+ preserve the call_context so that it can be read back in the caller. -+ */ -+ -+ .cfi_def_cfa 5, FRAME_LEN # interim CFA based on a1 -+ SARG $fp, $a1, FRAME_LEN - 2*PTRS -+ .cfi_offset 22, -2*PTRS -+ SARG $ra, $a1, FRAME_LEN - 1*PTRS -+ .cfi_offset 1, -1*PTRS -+ -+ addi.d $fp, $a1, FRAME_LEN -+ move $sp, $a0 -+ .cfi_def_cfa 22, 0 # our frame is fully set up -+ -+ # Load arguments -+ move $t1, $a2 -+ move $t2, $a3 -+ -+ FLARG $fa0, $fp, -FRAME_LEN+0*FLTS -+ FLARG $fa1, $fp, -FRAME_LEN+1*FLTS -+ FLARG $fa2, $fp, -FRAME_LEN+2*FLTS -+ FLARG $fa3, $fp, -FRAME_LEN+3*FLTS -+ FLARG $fa4, $fp, -FRAME_LEN+4*FLTS -+ FLARG $fa5, $fp, -FRAME_LEN+5*FLTS -+ FLARG $fa6, $fp, -FRAME_LEN+6*FLTS -+ FLARG $fa7, $fp, -FRAME_LEN+7*FLTS -+ -+ LARG $a0, $fp, -FRAME_LEN+8*FLTS+0*PTRS -+ LARG $a1, $fp, -FRAME_LEN+8*FLTS+1*PTRS -+ LARG $a2, $fp, -FRAME_LEN+8*FLTS+2*PTRS -+ LARG $a3, $fp, -FRAME_LEN+8*FLTS+3*PTRS -+ LARG $a4, $fp, -FRAME_LEN+8*FLTS+4*PTRS -+ LARG $a5, $fp, -FRAME_LEN+8*FLTS+5*PTRS -+ LARG $a6, $fp, -FRAME_LEN+8*FLTS+6*PTRS -+ LARG $a7, $fp, -FRAME_LEN+8*FLTS+7*PTRS -+ -+ /* Call */ -+ jirl $ra,$t1,0 -+ -+ /* Save return values - only a0/a1 (fa0/fa1) are used */ -+ FSARG $fa0, $fp, -FRAME_LEN+0*FLTS -+ FSARG $fa1, $fp, -FRAME_LEN+1*FLTS -+ -+ SARG $a0, $fp, -FRAME_LEN+8*FLTS+0*PTRS -+ SARG $a1, $fp, -FRAME_LEN+8*FLTS+1*PTRS -+ -+ /* Restore and return */ -+ addi.d $sp, $fp, -FRAME_LEN -+ .cfi_def_cfa 3, FRAME_LEN -+ LARG $ra, $fp, -1*PTRS -+ .cfi_restore 1 -+ LARG $fp, $fp, -2*PTRS -+ .cfi_restore 22 -+ jirl $r0, $ra, 0 -+ .cfi_endproc -+ .size ffi_call_asm, .-ffi_call_asm -+ -+ -+/* -+ ffi_closure_asm. Expects address of the passed-in ffi_closure in t1. -+ void ffi_closure_inner (ffi_cif *cif, -+ void (*fun) (ffi_cif *, void *, void **, void *), -+ void *user_data, -+ size_t *stackargs, struct call_context *regargs) -+*/ -+ -+ .globl ffi_closure_asm -+ .hidden ffi_closure_asm -+ .type ffi_closure_asm, @function -+ffi_closure_asm: -+ .cfi_startproc -+ -+ addi.d $sp, $sp, -FRAME_LEN -+ .cfi_def_cfa_offset FRAME_LEN -+ -+ /* make a frame */ -+ SARG $fp, $sp, FRAME_LEN - 2*PTRS -+ .cfi_offset 22, -2*PTRS -+ SARG $ra, $sp, FRAME_LEN - 1*PTRS -+ .cfi_offset 1, -1*PTRS -+ addi.d $fp, $sp, FRAME_LEN -+ -+ /* save arguments */ -+ FSARG $fa0, $sp, 0*FLTS -+ FSARG $fa1, $sp, 1*FLTS -+ FSARG $fa2, $sp, 2*FLTS -+ FSARG $fa3, $sp, 3*FLTS -+ FSARG $fa4, $sp, 4*FLTS -+ FSARG $fa5, $sp, 5*FLTS -+ FSARG $fa6, $sp, 6*FLTS -+ FSARG $fa7, $sp, 7*FLTS -+ -+ SARG $a0, $sp, 8*FLTS+0*PTRS -+ SARG $a1, $sp, 8*FLTS+1*PTRS -+ SARG $a2, $sp, 8*FLTS+2*PTRS -+ SARG $a3, $sp, 8*FLTS+3*PTRS -+ SARG $a4, $sp, 8*FLTS+4*PTRS -+ SARG $a5, $sp, 8*FLTS+5*PTRS -+ SARG $a6, $sp, 8*FLTS+6*PTRS -+ SARG $a7, $sp, 8*FLTS+7*PTRS -+ -+ /* enter C */ -+ LARG $a0, $t0, FFI_TRAMPOLINE_SIZE+0*PTRS -+ LARG $a1, $t0, FFI_TRAMPOLINE_SIZE+1*PTRS -+ LARG $a2, $t0, FFI_TRAMPOLINE_SIZE+2*PTRS -+ addi.d $a3, $sp, FRAME_LEN -+ move $a4, $sp -+ -+ bl ffi_closure_inner -+ -+ /* return values */ -+ FLARG $fa0, $sp, 0*FLTS -+ FLARG $fa1, $sp, 1*FLTS -+ -+ LARG $a0, $sp, 8*FLTS+0*PTRS -+ LARG $a1, $sp, 8*FLTS+1*PTRS -+ -+ /* restore and return */ -+ LARG $ra, $sp, FRAME_LEN-1*PTRS -+ .cfi_restore 1 -+ LARG $fp, $sp, FRAME_LEN-2*PTRS -+ .cfi_restore 22 -+ addi.d $sp, $sp, FRAME_LEN -+ .cfi_def_cfa_offset 0 -+ jirl $r0, $ra, 0 -+ .cfi_endproc -+ .size ffi_closure_asm, .-ffi_closure_asm -+ -+/* -+ ffi_go_closure_asm. Expects address of the passed-in ffi_go_closure in t2. -+ void ffi_closure_inner (ffi_cif *cif, -+ void (*fun) (ffi_cif *, void *, void **, void *), -+ void *user_data, -+ size_t *stackargs, struct call_context *regargs) -+*/ -+ -+ .globl ffi_go_closure_asm -+ .hidden ffi_go_closure_asm -+ .type ffi_go_closure_asm, @function -+ffi_go_closure_asm: -+ .cfi_startproc -+ -+ addi.d $sp, $sp, -FRAME_LEN -+ .cfi_def_cfa_offset FRAME_LEN -+ -+ /* make a frame */ -+ SARG $fp, $sp, FRAME_LEN - 2*PTRS -+ .cfi_offset 22, -2*PTRS -+ SARG $ra, $sp, FRAME_LEN - 1*PTRS -+ .cfi_offset 1, -1*PTRS -+ addi.d $fp, $sp, FRAME_LEN -+ -+ /* save arguments */ -+ FSARG $fa0, $sp, 0*FLTS -+ FSARG $fa1, $sp, 1*FLTS -+ FSARG $fa2, $sp, 2*FLTS -+ FSARG $fa3, $sp, 3*FLTS -+ FSARG $fa4, $sp, 4*FLTS -+ FSARG $fa5, $sp, 5*FLTS -+ FSARG $fa6, $sp, 6*FLTS -+ FSARG $fa7, $sp, 7*FLTS -+ -+ SARG $a0, $sp, 8*FLTS+0*PTRS -+ SARG $a1, $sp, 8*FLTS+1*PTRS -+ SARG $a2, $sp, 8*FLTS+2*PTRS -+ SARG $a3, $sp, 8*FLTS+3*PTRS -+ SARG $a4, $sp, 8*FLTS+4*PTRS -+ SARG $a5, $sp, 8*FLTS+5*PTRS -+ SARG $a6, $sp, 8*FLTS+6*PTRS -+ SARG $a7, $sp, 8*FLTS+7*PTRS -+ -+ /* enter C */ -+ LARG $a0, $t2, 1*PTRS -+ LARG $a1, $t2, 2*PTRS -+ move $a2, $t2 -+ addi.d $a3, $sp, FRAME_LEN -+ move $a4, $sp -+ -+ bl ffi_closure_inner -+ -+ /* return values */ -+ FLARG $fa0, $sp, 0*FLTS -+ FLARG $fa1, $sp, 1*FLTS -+ -+ LARG $a0, $sp, 8*FLTS+0*PTRS -+ LARG $a1, $sp, 8*FLTS+1*PTRS -+ -+ /* restore and return */ -+ LARG $ra, $sp, FRAME_LEN-1*PTRS -+ .cfi_restore 1 -+ LARG $fp, $sp, FRAME_LEN-2*PTRS -+ .cfi_restore 22 -+ addi.d $sp, $sp, FRAME_LEN -+ .cfi_def_cfa_offset 0 -+ jirl $r0, $ra, 0 -+ .cfi_endproc -+ .size ffi_go_closure_asm, .-ffi_go_closure_asm --- -2.27.0 - diff --git a/backport-Fix-check-for-invalid-varargs-arguments-707.patch b/backport-Fix-check-for-invalid-varargs-arguments-707.patch deleted file mode 100644 index 56769dc38e5ee2c5e549d26c4e4b02d6308b58b1..0000000000000000000000000000000000000000 --- a/backport-Fix-check-for-invalid-varargs-arguments-707.patch +++ /dev/null @@ -1,197 +0,0 @@ -From de95947ae5db07e4589bb16bab30b6c8ba2b3106 Mon Sep 17 00:00:00 2001 -From: Roland Schatz -Date: Tue, 24 May 2022 03:04:43 +0200 -Subject: [PATCH] Fix check for invalid varargs arguments. (#707) - -Conflict:NA -Reference:https://github.com/libffi/libffi/commit/de95947ae5db07e4589bb16bab30b6c8ba2b3106 ---- - src/prep_cif.c | 3 +- - testsuite/libffi.call/va_3.c | 154 +++++++++++++++++++++++++++++++++++ - 2 files changed, 156 insertions(+), 1 deletion(-) - create mode 100644 testsuite/libffi.call/va_3.c - -diff --git a/src/prep_cif.c b/src/prep_cif.c -index c1832b1..2d0f252 100644 ---- a/src/prep_cif.c -+++ b/src/prep_cif.c -@@ -1,6 +1,7 @@ - /* ----------------------------------------------------------------------- - prep_cif.c - Copyright (c) 2011, 2012, 2021 Anthony Green - Copyright (c) 1996, 1998, 2007 Red Hat, Inc. -+ Copyright (c) 2022 Oracle and/or its affiliates. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the -@@ -240,7 +241,7 @@ ffi_status ffi_prep_cif_var(ffi_cif *cif, - if (rc != FFI_OK) - return rc; - -- for (i = 1; i < ntotalargs; i++) -+ for (i = nfixedargs; i < ntotalargs; i++) - { - ffi_type *arg_type = atypes[i]; - if (arg_type == &ffi_type_float -diff --git a/testsuite/libffi.call/va_3.c b/testsuite/libffi.call/va_3.c -new file mode 100644 -index 0000000..b3e73b5 ---- /dev/null -+++ b/testsuite/libffi.call/va_3.c -@@ -0,0 +1,154 @@ -+/* Area: ffi_call -+ Purpose: Test function with multiple fixed args and variable argument list. -+ Limitations: none. -+ PR: none. -+ Originator: ARM Ltd., Oracle */ -+ -+/* { dg-do run } */ -+/* { dg-output "" { xfail avr32*-*-* m68k-*-* } } */ -+ -+#include "ffitest.h" -+#include -+ -+/* -+ * This is a modified version of va_2.c that has fixed arguments with "small" types that -+ * are not allowed as variable arguments, but they should be still allowed as fixed args. -+ */ -+ -+static int -+test_fn (char a1, float a2, int n, ...) -+{ -+ va_list ap; -+ unsigned char uc; -+ signed char sc; -+ unsigned short us; -+ signed short ss; -+ unsigned int ui; -+ signed int si; -+ unsigned long ul; -+ signed long sl; -+ float f; -+ double d; -+ -+ va_start (ap, n); -+ -+ uc = va_arg (ap, unsigned); -+ sc = va_arg (ap, signed); -+ -+ us = va_arg (ap, unsigned); -+ ss = va_arg (ap, signed); -+ -+ ui = va_arg (ap, unsigned int); -+ si = va_arg (ap, signed int); -+ -+ ul = va_arg (ap, unsigned long); -+ sl = va_arg (ap, signed long); -+ -+ f = va_arg (ap, double); /* C standard promotes float->double -+ when anonymous */ -+ d = va_arg (ap, double); -+ -+ printf ("%d %f uc=%u sc=%d %u %d %u %d %lu %ld %f %f\n", -+ a1, a2, -+ uc, sc, -+ us, ss, -+ ui, si, -+ ul, sl, -+ f, d); -+ -+ va_end (ap); -+ -+ CHECK(a1 == 1); -+ CHECK((int)a2 == 2); -+ CHECK(uc == 9); -+ CHECK(sc == 10); -+ CHECK(us == 11); -+ CHECK(ss == 12); -+ CHECK(ui == 13); -+ CHECK(si == 14); -+ CHECK(ul == 15); -+ CHECK(sl == 16); -+ CHECK((int)f == 2); -+ CHECK((int)d == 3); -+ -+ return n + 1; -+} -+ -+int -+main (void) -+{ -+ ffi_cif cif; -+ void* args[14]; -+ ffi_type* arg_types[14]; -+ -+ char a1; -+ float a2; -+ int n; -+ ffi_arg res; -+ -+ unsigned int uc; -+ signed int sc; -+ unsigned int us; -+ signed int ss; -+ unsigned int ui; -+ signed int si; -+ unsigned long ul; -+ signed long sl; -+ double d1; -+ double f1; -+ -+ arg_types[0] = &ffi_type_schar; -+ arg_types[1] = &ffi_type_float; -+ arg_types[2] = &ffi_type_sint; -+ arg_types[3] = &ffi_type_uint; -+ arg_types[4] = &ffi_type_sint; -+ arg_types[5] = &ffi_type_uint; -+ arg_types[6] = &ffi_type_sint; -+ arg_types[7] = &ffi_type_uint; -+ arg_types[8] = &ffi_type_sint; -+ arg_types[9] = &ffi_type_ulong; -+ arg_types[10] = &ffi_type_slong; -+ arg_types[11] = &ffi_type_double; -+ arg_types[12] = &ffi_type_double; -+ arg_types[13] = NULL; -+ -+ CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 3, 13, &ffi_type_sint, arg_types) == FFI_OK); -+ -+ a1 = 1; -+ a2 = 2.0f; -+ n = 41; -+ -+ uc = 9; -+ sc = 10; -+ us = 11; -+ ss = 12; -+ ui = 13; -+ si = 14; -+ ul = 15; -+ sl = 16; -+ f1 = 2.12; -+ d1 = 3.13; -+ -+ args[0] = &a1; -+ args[1] = &a2; -+ args[2] = &n; -+ args[3] = &uc; -+ args[4] = ≻ -+ args[5] = &us; -+ args[6] = &ss; -+ args[7] = &ui; -+ args[8] = &si; -+ args[9] = &ul; -+ args[10] = &sl; -+ args[11] = &f1; -+ args[12] = &d1; -+ args[13] = NULL; -+ -+ ffi_call(&cif, FFI_FN(test_fn), &res, args); -+ /* { dg-output "1 2.000000 uc=9 sc=10 11 12 13 14 15 16 2.120000 3.130000" } */ -+ printf("res: %d\n", (int) res); -+ /* { dg-output "\nres: 42" } */ -+ CHECK(res == 42); -+ -+ return 0; -+} --- -2.23.0 - \ No newline at end of file diff --git a/backport-x86-64-Always-double-jump-table-slot-size-for-CET-71.patch b/backport-x86-64-Always-double-jump-table-slot-size-for-CET-71.patch deleted file mode 100644 index 14b08cdf6186e322bc6909ecf4706b6202e19c1b..0000000000000000000000000000000000000000 --- a/backport-x86-64-Always-double-jump-table-slot-size-for-CET-71.patch +++ /dev/null @@ -1,54 +0,0 @@ -From 3ac265d5c0e038e324bae29131dbc4bacb4935ea Mon Sep 17 00:00:00 2001 -From: hjl-tools -Date: Sun, 15 May 2022 18:43:56 -0700 -Subject: [PATCH] x86-64: Always double jump table slot size for CET (#710) - (#711) - -When CET is enabled, double jump table slot size to add 4 bytes of ENDBR64 -for CET. Since CET enabled clang doesn't have the LLVM assembler bug: - -https://bugs.llvm.org/show_bug.cgi?id=21501 - -fixed by - -commit 04d39260d64e08b8bfb3844109ad43d4055b2e8d -Author: Rafael Espindola -Date: Wed Nov 4 23:50:29 2015 +0000 - - Simplify .org processing and make it a bit more powerful. - -we can use .org to allocate jump table slot size to 16 bytes. - -Conflict:NA -Reference:https://github.com/libffi/libffi/commit/3ac265d5c0e038e324bae29131dbc4bacb4935ea ---- - src/x86/unix64.S | 11 +++++------ - 1 file changed, 5 insertions(+), 6 deletions(-) - -diff --git a/src/x86/unix64.S b/src/x86/unix64.S -index 8cf3a23..d9c5bd4 100644 ---- a/src/x86/unix64.S -+++ b/src/x86/unix64.S -@@ -39,14 +39,13 @@ - actual table. The entry points into the table are all 8 bytes. - The use of ORG asserts that we're at the correct location. */ - /* ??? The clang assembler doesn't handle .org with symbolic expressions. */ --#if defined(__clang__) || defined(__APPLE__) || (defined (__sun__) && defined(__svr4__)) -+#ifdef __CET__ -+/* Double slot size to 16 byte to add 4 bytes of ENDBR64. */ -+# define E(BASE, X) .balign 8; .org BASE + X * 16 -+#elif defined(__clang__) || defined(__APPLE__) || (defined (__sun__) && defined(__svr4__)) - # define E(BASE, X) .balign 8 - #else --# ifdef __CET__ --# define E(BASE, X) .balign 8; .org BASE + X * 16 --# else --# define E(BASE, X) .balign 8; .org BASE + X * 8 --# endif -+# define E(BASE, X) .balign 8; .org BASE + X * 8 - #endif - - /* ffi_call_unix64 (void *args, unsigned long bytes, unsigned flags, --- -2.23.0 - \ No newline at end of file diff --git a/libffi-3.4.2.tar.gz b/libffi-3.4.2.tar.gz deleted file mode 100644 index 6752a27688d5817706e3d3f369478975f8a179e6..0000000000000000000000000000000000000000 Binary files a/libffi-3.4.2.tar.gz and /dev/null differ diff --git a/libffi-3.4.4.tar.gz b/libffi-3.4.4.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..173ab92de0476b8d97418da1d04b8b1b46fb7875 Binary files /dev/null and b/libffi-3.4.4.tar.gz differ diff --git a/libffi.spec b/libffi.spec index 0153aa90a27e81d6d8844f748b4c99941284ae64..c406cd57017a2c9a1779d85f75478360d82283b1 100644 --- a/libffi.spec +++ b/libffi.spec @@ -1,6 +1,6 @@ Name: libffi -Version: 3.4.2 -Release: 4 +Version: 3.4.4 +Release: 1 Summary: A Portable Foreign Function Interface Library License: MIT URL: http://sourceware.org/libffi @@ -8,9 +8,6 @@ Source0: https://github.com/libffi/libffi/releases/download/v%{version}/%{name}- Source1: ffi-multilib.h Source2: ffitarget-multilib.h -Patch6000: backport-x86-64-Always-double-jump-table-slot-size-for-CET-71.patch -Patch6001: backport-Fix-check-for-invalid-varargs-arguments-707.patch -Patch6002: add-loongarch64-support.patch BuildRequires: gcc gcc-c++ dejagnu BuildRequires: make @@ -54,11 +51,6 @@ The help package contains man files. %prep %setup -q -%patch6000 -p1 -%patch6001 -p1 -%ifarch loongarch64 -%patch6002 -p1 -%endif %build %configure \ @@ -102,6 +94,9 @@ fi %{_infodir}/libffi.info.gz %changelog +* Thu Jan 19 2023 gaoruoshu -3.4.4-1 +- update version to 3.4.4 + * Fri Dec 16 2022 wangjiang - 3.4.2-4 - add BuildRequires make