platform/upstream/libffi.git
13 months agopackaging: pass '--enable-portable-binary' to configure 44/289644/1 accepted/tizen_8.0_base accepted/tizen_base accepted/tizen_base_riscv accepted/tizen_base_tool tizen_8.0_base tizen_base accepted/tizen/8.0/base/20231005.044841 accepted/tizen/base/20230714.003345 accepted/tizen/base/riscv/20231110.002655 accepted/tizen/base/tool/20230314.044257 submit/tizen_base/20230313.045051 tizen_8.0_m2_release
Dongkyun Son [Mon, 9 May 2022 03:51:43 +0000 (12:51 +0900)]
packaging: pass '--enable-portable-binary' to configure

To fix SIGILL(crashing on vmovd) with AVX inst. enabled

Change-Id: Ie979daf9282984a0a5bc7a3a0bb52ccc5f1125d2
Signed-off-by: Dongkyun Son <dongkyun.s@samsung.com>
13 months agoBlacklist ffi_call_int for ASan and HWASan build 43/289643/1
Andrey Kazmin [Thu, 3 Jun 2021 10:36:43 +0000 (13:36 +0300)]
Blacklist ffi_call_int for ASan and HWASan build

See:
https://github.com/libffi/libffi/issues/255

Change-Id: Iaa3b738140cd02dd9b5ec1121396a1675ab4f4b3
Signed-off-by: Andrey Kazmin <a.kazmin@partner.samsung.com>
13 months agodoc: disable info files 42/289642/1
Dongkyun Son [Fri, 13 Nov 2020 01:37:41 +0000 (10:37 +0900)]
doc: disable info files

Fix "WARNING: 'makeinfo' is missing on your system."

Change-Id: I66492b0ece188f93a35d2f7ffe1a0fc322ecd680
Signed-off-by: Dongkyun Son <dongkyun.s@samsung.com>
13 months agoAdd packaging with v3.4.2 41/289641/1
Dongkyun Son [Fri, 29 Apr 2022 19:07:33 +0000 (04:07 +0900)]
Add packaging with v3.4.2

Change-Id: I95cbe89e71086b8b6e7e148dded6313b934310de
Signed-off-by: Dongkyun Son <dongkyun.s@samsung.com>
2 years agoUpdate version to 3.4.2 upstream/3.4.2
Anthony Green [Tue, 29 Jun 2021 01:10:49 +0000 (21:10 -0400)]
Update version to 3.4.2

2 years agoVersion 3.4.1
Anthony Green [Mon, 28 Jun 2021 23:50:29 +0000 (19:50 -0400)]
Version 3.4.1

2 years agoUpdate version to 3.4.0
Anthony Green [Mon, 28 Jun 2021 22:50:31 +0000 (18:50 -0400)]
Update version to 3.4.0

2 years agoFix warnings
Anthony Green [Mon, 28 Jun 2021 22:45:11 +0000 (18:45 -0400)]
Fix warnings

2 years agoAdd missing test cases to distribution
Anthony Green [Mon, 28 Jun 2021 18:59:07 +0000 (14:59 -0400)]
Add missing test cases to distribution

2 years agoAdd tests for single entry structs (#653)
Hood Chatham [Mon, 28 Jun 2021 18:51:35 +0000 (11:51 -0700)]
Add tests for single entry structs (#653)

2 years agoFix the assertions in cls-24byte (#652)
Hood Chatham [Mon, 28 Jun 2021 14:24:19 +0000 (07:24 -0700)]
Fix the assertions in cls-24byte (#652)

* Fix the assertions in cls-24byte

* Update print statement too

2 years ago3.4.0 release candidate 2
Anthony Green [Mon, 28 Jun 2021 13:53:01 +0000 (09:53 -0400)]
3.4.0 release candidate 2

2 years agoAdd missing FFI_HIDDEN to ffi_tramp_is_present declaration (#651)
Jeremy Huddleston Sequoia [Mon, 28 Jun 2021 11:56:30 +0000 (04:56 -0700)]
Add missing FFI_HIDDEN to ffi_tramp_is_present declaration (#651)

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
2 years agoPrint more information when an assertion fails in test suite (#649)
Hood Chatham [Sun, 27 Jun 2021 18:02:33 +0000 (11:02 -0700)]
Print more information when an assertion fails in test suite (#649)

2 years agoFix signature of function pointer in cls_dbls_struct (#648)
Hood Chatham [Sun, 27 Jun 2021 16:49:31 +0000 (09:49 -0700)]
Fix signature of function pointer in cls_dbls_struct (#648)

2 years agoconfigure.ac: add --disable-exec-static-tramp flag (#647)
Sergei Trofimovich [Sun, 27 Jun 2021 15:50:20 +0000 (16:50 +0100)]
configure.ac: add --disable-exec-static-tramp flag (#647)

Some projects like GHC (Glasgow Haskell Compiler) and
gobject-introspection use `ffi_closure_alloc()` as a way
to allocate executable memory. exec static tramp
interferes with it (unclear how exactly yet).

GHC symptom: ffi closure freeing cimplains about unexpected
trampoline (GHC manually fills one):

```
$ ghci
GHCi, version 8.10.5: https://www.haskell.org/ghc/  :? for help
ghc: freeHaskellFunctionPtr: not for me, guv! 0x7f0417a1efe8
ghc: freeHaskellFunctionPtr: not for me, guv! 0x7f0417a1efc8
```

gobject-introspection symptom:

```
$ meld
Segmentation fault (core dumped)

$ gdb --args /usr/bin/python3.9 /usr/bin/meld
(gdb) run
...
Thread 1 "python3.9" received signal SIGSEGV, Segmentation fault.
0x00007fffe9ac1ae8 in g_callable_info_free_closure (
  callable_info=0x555555d45990, closure=0x7fffe9e70c20)
    at ../gobject-introspection-1.68.0/girepository/girffi.c:428
428       g_free (wrapper->ffi_closure.cif->arg_types);
(gdb) bt
  callable_info=0x555555d45990, closure=0x7fffe9e70c20)
    at ../gobject-introspection-1.68.0/girepository/girffi.c:428
  data=0x555555d252d0)
    at ../pygobject-3.40.1/gi/pygi-closure.c:635
...
```

To ease downstreams narrowing down the actual problem let's
provide a knob to disable exec static trampolines.

The change for not affect current default.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
2 years agoRemove caveat about varargs support
Anthony Green [Sun, 27 Jun 2021 15:25:06 +0000 (11:25 -0400)]
Remove caveat about varargs support

2 years agoUpdate contact info
Anthony Green [Sun, 27 Jun 2021 11:46:12 +0000 (07:46 -0400)]
Update contact info

2 years agoconfigure.ac: allow user to specify READELF (#646)
Sergei Trofimovich [Sat, 26 Jun 2021 21:26:52 +0000 (22:26 +0100)]
configure.ac: allow user to specify READELF (#646)

Before the change with x86_64-pc-linux-gnu cross-compiler
installed the configure was not able to find cross-readelf:

```
$ ./configure --host=x86_64-pc-linux-gnu
...
checking whether .eh_frame section should be read-only... .././configure: line 19540: readelf: command not found
yes
...
```

The change uses AC_CHECK_TOOL to automatically seatch for ${host}-readelf,
readelf. And as a bonus it also allows user to override readelf with
something like READELF=llvm-readelf.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
2 years agoMake 3.4 release candidate 1
Anthony Green [Sat, 26 Jun 2021 16:12:06 +0000 (12:12 -0400)]
Make 3.4 release candidate 1

2 years agoAdd missing file from make dist. Add missing license info.
Anthony Green [Sat, 26 Jun 2021 16:08:35 +0000 (12:08 -0400)]
Add missing file from make dist.  Add missing license info.

2 years agoRemove test case
Anthony Green [Sat, 26 Jun 2021 14:55:57 +0000 (10:55 -0400)]
Remove test case

2 years agoThis test includes a closure and must live in the closures test directory. (#645)
Matthew Green [Sat, 26 Jun 2021 12:49:45 +0000 (08:49 -0400)]
This test includes a closure and must live in the closures test directory. (#645)

Co-authored-by: Matthew Green <squidhacks@users.noreply.github.com>
2 years agoMake test methods static (#644)
Hood Chatham [Sat, 26 Jun 2021 02:50:33 +0000 (19:50 -0700)]
Make test methods static (#644)

2 years agoSwitch from travis-ci.org to travis-ci.com.
Anthony Green [Tue, 22 Jun 2021 17:01:06 +0000 (13:01 -0400)]
Switch from travis-ci.org to travis-ci.com.

2 years agoAvoid undefined behaviour
Anthony Green [Tue, 22 Jun 2021 12:48:24 +0000 (08:48 -0400)]
Avoid undefined behaviour

2 years agoRemove libtool-ldflags file from .gitignore (#600)
Tres Finocchiaro [Tue, 22 Jun 2021 11:33:46 +0000 (07:33 -0400)]
Remove libtool-ldflags file from .gitignore (#600)

This is correct.  Thank you!

2 years ago2021-06-15 Jakub Jelinek <jakub@redhat.com>
Jakub Jelinek [Tue, 15 Jun 2021 19:19:26 +0000 (15:19 -0400)]
2021-06-15  Jakub Jelinek  <jakub@redhat.com>

        * src/x86/ffi64.c (classify_argument): For FFI_TYPE_STRUCT set words
        to number of words needed for type->size + byte_offset bytes rather
        than just type->size bytes.  Compute pos before the loop and check
        total size of the structure.
        * testsuite/libffi.call/nested_struct12.c: New test.

2 years agoDon't stop test on copy failure (#636)
DJ Delorie [Tue, 15 Jun 2021 12:50:20 +0000 (08:50 -0400)]
Don't stop test on copy failure (#636)

* Don't stop test on copy failure

Static-library tests were failing only because there were
no DLLs to copy.  This change makes a copy failure not stop
the build; if a failed copy would otherwise be relevent, the
later tests would fail anyway.

While there are more clever ways to solve this, a brute force
fix is sufficient.

* [TEST] Try cygwin64; install more packages explicitly

* use correct cygwin64 directory name

appveyor has cygwin64 pre-installed in /cygwin64, and 32-bit cygwin
in /cygwin

* More testing - revert VS change, bump travis timeout

* Add -g to update the rest of perl

* Skip execution tests on non-native platforms

Special site.exp that skips the unix_load() command for arm platforms.

Unset TERM to avoid cruft in stdout

Try harder to find the libffi libraries

2 years agoFix build on OpenBSD/mips64 (#638)
vhankala [Thu, 10 Jun 2021 18:41:02 +0000 (18:41 +0000)]
Fix build on OpenBSD/mips64 (#638)

The build fails on OpenBSD/mips64 because clang 11's integrated
assembler expects read-only .eh_frame:

../src/mips/n32.S:585:9: error: changed section flags for .eh_frame, expected: 0x2
        .section .eh_frame,"aw",@progbits
        ^

Use EH_FRAME_FLAGS to get matching flags for the section.

2 years agoAdd struct test to verify a nested float struct (#640)
Cheng Jin [Wed, 9 Jun 2021 20:00:10 +0000 (16:00 -0400)]
Add struct test to verify a nested float struct (#640)

The test aims to check a nested float struct
[float, [float,float]] to see whether it works good
with libffi.

Signed-off-by: Cheng Jin <jincheng@ca.ibm.com>
2 years agoRemove reference to old test case
Anthony Green [Wed, 9 Jun 2021 19:45:31 +0000 (15:45 -0400)]
Remove reference to old test case

2 years agoRevert appveyor changes
Anthony Green [Fri, 4 Jun 2021 22:20:24 +0000 (18:20 -0400)]
Revert appveyor changes

2 years agoUpdate vs version
Anthony Green [Wed, 2 Jun 2021 03:00:29 +0000 (23:00 -0400)]
Update vs version

2 years agoUpgrade to vs2019
Anthony Green [Wed, 2 Jun 2021 02:57:47 +0000 (22:57 -0400)]
Upgrade to vs2019

2 years agoTry updating automake
Anthony Green [Wed, 2 Jun 2021 02:53:44 +0000 (22:53 -0400)]
Try updating automake

2 years agoBring in the latest version of perl
Anthony Green [Wed, 2 Jun 2021 02:34:37 +0000 (22:34 -0400)]
Bring in the latest version of perl

3 years agoFix building for arm windows with mingw toolchains (#631)
Martin Storsjö [Wed, 7 Apr 2021 02:42:10 +0000 (05:42 +0300)]
Fix building for arm windows with mingw toolchains (#631)

* arm: Check _WIN32 instead of _M_ARM or _MSC_VER for detecting windows

This matches what was done for ARM64 in
c06468fa6674d3783a0edb1d0fae9afc8bc28513.

* arm: Only use armasm source when building with MSVC

When building for windows/arm with clang, the normal gas style .S
source works fine (if fixed up to support thumb and other windows
specifics).

This matches what was done for ARM64 in
c06468fa6674d3783a0edb1d0fae9afc8bc28513.

* arm: Fix sysv.S to work in thumb mode

Align cases in jump tables (adding nop padding to make sure each
case starts where expected).

Rewrite instructions that add directly to the pc register.

For ffi_closure_ret, factor out a call_epilogue subroutine that
restores both sp and pc from the stack; the thumb version of ldm
can't load into the sp register. To avoid excessive ifdeffing, keep
using call_epilogue in arm mode, but keep the shorter "ldm sp, {sp, pc}"
epilogue in that case.

* arm: Add win32 version of trampoline to sysv.S

This matches the version of it in sysv_msvc_arm32.S. The calling
C code expects a specific form of the trampoline on windows; make
sure these work the same on windows regardless of the form of
assembly used.

* arm: Avoid optimizing out clearing the thumb bit of ffi_arm_trampoline

We clear the thumb bit of ffi_arm_trampoline with a bitmask before
memcpying its instructions into closure->tramp.

If the bit isn't cleared, the memcpy of the trampoline function
copies the wrong instructions.

If the ffi_arm_trampoline symbol is declared as an array of int,
the compiler can assume that it is aligned to a 4 byte boundary
and the bitmask operation is a no-op, and optimize it out.

See https://godbolt.org/z/dE3jE1WTz; both Clang and GCC optimize
out the bitmask as it is, while MSVC doesn't. By declaring the
trampoline as an array of unsigned char, the bitmask works as
intended.

3 years agoVerbose brew update.
Anthony Green [Thu, 25 Mar 2021 14:43:05 +0000 (10:43 -0400)]
Verbose brew update.

3 years agoMove container images to quay.io.
Anthony Green [Thu, 25 Mar 2021 13:15:37 +0000 (09:15 -0400)]
Move container images to quay.io.

3 years agotestsuite: fix compiler vendor detection on dash as /bin/sh (#594)
Sergei Trofimovich [Wed, 24 Mar 2021 23:19:54 +0000 (23:19 +0000)]
testsuite: fix compiler vendor detection on dash as /bin/sh (#594)

In https://bugs.gentoo.org/753299 Paolo Pedroni reported
a single test failure out of all libffi. Here is the minimal
reproducer:

```
$ ./autogen
$ CONFIG_SHELL=/bin/dash ./configure --host=x86_64-pc-linux-gnu
$ make check RUNTESTFLAGS='complex.exp'
...
FAIL: libffi.complex/cls_align_complex_float.c (test for excess errors)
```

This happens because under 'dash' shell autoconf generates slightly
different style of string quotation in `config.log`:

- on bash: `ax_cv_c_compiler_vendor=gnu`
- on dash: `ax_cv_c_compiler_vendor='gnu'`

To avoid shell quotation parsing the change just embeds
`compiler_vendor` into `local.exp` at configure time.

Reported-by: Paolo Pedroni
Bug: https://bugs.gentoo.org/753299
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
3 years agoarm64e: Pull in pointer authentication code from Apple's arm64e libffi port (#565)
Jeremy Huddleston Sequoia [Wed, 24 Mar 2021 18:38:36 +0000 (11:38 -0700)]
arm64e: Pull in pointer authentication code from Apple's arm64e libffi port (#565)

NOTES: This changes the ptrauth support from #548 to match what Apple is
       shipping in its libffi-27 tag.

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
3 years agofix windows tests (#595)
ericLemanissier [Wed, 24 Mar 2021 11:20:27 +0000 (12:20 +0100)]
fix windows tests (#595)

* Update .appveyor.yml

* add (debug+release)*(shared+static) CI

* fix libversion

3 years agox86: Fix thiscall and fastcall stack cleanup behavior (#611)
Ole André Vadla Ravnås [Wed, 24 Mar 2021 11:16:12 +0000 (12:16 +0100)]
x86: Fix thiscall and fastcall stack cleanup behavior (#611)

These are meant to use callee clean-up.

3 years agoMention MSVC runtime stack checking improvement
Anthony Green [Wed, 24 Mar 2021 11:07:53 +0000 (07:07 -0400)]
Mention MSVC runtime stack checking improvement

3 years agox86: Fix MSVC runtime checks interop (#612)
Ole André Vadla Ravnås [Wed, 24 Mar 2021 11:04:51 +0000 (12:04 +0100)]
x86: Fix MSVC runtime checks interop (#612)

MSVC can add runtime code that checks if a stack frame is mismanaged,
however our custom assembly deliberately accesses and modifies the parent
stack frame.  Fortunately we can disable that specific check for the
function call so do that.

Co-authored-by: Matthew Waters <matthew@centricular.com>
3 years agoMention LIBFFI_TMPDIR
Anthony Green [Tue, 23 Mar 2021 23:06:08 +0000 (19:06 -0400)]
Mention LIBFFI_TMPDIR

3 years agoSearch $LIBFFI_TMPDIR also (#605)
DJ Delorie [Tue, 23 Mar 2021 23:03:45 +0000 (19:03 -0400)]
Search $LIBFFI_TMPDIR also (#605)

Most temp file directories need to be hardened against execution, but
libffi needs execute privileges.  Add a libffi-specific temp directory
that can be set up by sysadmins as needed with suitable permissions.
This both ensures that libffi will have a valid temp directory to use
as well as preventing attempts to access other directories.

3 years agoaarch64: Fix closures for win64 (#606)
AndreRH [Tue, 23 Mar 2021 22:54:00 +0000 (23:54 +0100)]
aarch64: Fix closures for win64 (#606)

3 years agoUpdate ax_cc_maxopt m4 macro (#617)
Francisco Boni [Tue, 23 Mar 2021 22:50:09 +0000 (19:50 -0300)]
Update ax_cc_maxopt m4 macro (#617)

Keeps libffi's specific changes
(https://github.com/libffi/libffi/commit/cec3a3a201f17a7f018f25e1a0917bd5206e5a5a#diff-2396a1256ac4b1c6849c931ddb8018bdd984bb2383be21bb819a33b95d8d603f)
and updates to the latest ax_cc_maxopt.m4
(http://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=commit;h=73ee1b396c21062ee8eeb8721ba5323322110fb5):

ax_cc_maxopt.m4: retain setting of CFLAGS by configure

AX_CC_MAXOPT checks whether CFLAGS was set by the user; if so, the user’s
setting is respected. This behavior is retained, of course.

However, AX_CC_MAXOPT was then setting CFLAGS="". This overrode the default
setting by configure, which usually includes -g. Hence, if CFLAGS was not
set by the user, retain the default setting, to preserve the ability to
debug.

A typical default setting from configure is "-g -O2". This means that
AX_CC_MAXOPT might typically set CFLAGS to "-g -O2 -O3". This is fine,
because the later -O3 will override the earlier -O2. (The only assumption is
that all compilers that AX_CC_MAXOPT knows behave in this sane way.)

3 years agoFix formatting
Anthony Green [Tue, 23 Mar 2021 18:24:54 +0000 (14:24 -0400)]
Fix formatting

3 years agoMention KVX
Anthony Green [Tue, 23 Mar 2021 16:26:37 +0000 (12:26 -0400)]
Mention KVX

3 years agoBug #680. Don't accept floats or small ints as var args. (#628)
Anthony Green [Tue, 23 Mar 2021 15:31:08 +0000 (11:31 -0400)]
Bug #680.  Don't accept floats or small ints as var args. (#628)

* Bug #680.  Don't accept floats or small ints as var args.

* Bug #680.  Don't accept floats or small ints as var args.

* Bug #680.  Don't accept floats or small ints as var args.

3 years agoAdd some missing #if conditionals from Apple's code drop (#620)
Jeremy Huddleston Sequoia [Sat, 20 Mar 2021 13:06:28 +0000 (06:06 -0700)]
Add some missing #if conditionals from Apple's code drop (#620)

* arm/aarch64: Add FFI_CLOSURES conditionals where appropriate

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
* aarch64: Don't emit the do_closure label when building without FFI_GO_CLOSURES

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
3 years agoAdd configuration generator for tvOS and watchOS. (#625)
Russell Keith-Magee [Fri, 5 Mar 2021 16:09:17 +0000 (00:09 +0800)]
Add configuration generator for tvOS and watchOS. (#625)

3 years agoStatic tramp v5 (#624)
Madhavan T. Venkataraman [Fri, 5 Mar 2021 16:07:30 +0000 (10:07 -0600)]
Static tramp v5 (#624)

* Static Trampolines

Closure Trampoline Security Issue
=================================

Currently, the trampoline code used in libffi is not statically defined in
a source file (except for MACH). The trampoline is either pre-defined
machine code in a data buffer. Or, it is generated at runtime. In order to
execute a trampoline, it needs to be placed in a page with executable
permissions.

Executable data pages are attack surfaces for attackers who may try to
inject their own code into the page and contrive to have it executed. The
security settings in a system may prevent various tricks used in user land
to write code into a page and to have it executed somehow. On such systems,
libffi trampolines would not be able to run.

Static Trampoline
=================

To solve this problem, the trampoline code needs to be defined statically
in a source file, compiled and placed in the text segment so it can be
mapped and executed naturally without any tricks. However, the trampoline
needs to be able to access the closure pointer at runtime.

PC-relative data referencing
============================

The solution implemented in this patch set uses PC-relative data references.
The trampoline is mapped in a code page. Adjacent to the code page, a data
page is mapped that contains the parameters of the trampoline:

- the closure pointer
- pointer to the ABI handler to jump to

The trampoline code uses an offset relative to its current PC to access its
data.

Some architectures support PC-relative data references in the ISA itself.
E.g., X64 supports RIP-relative references. For others, the PC has to
somehow be loaded into a general purpose register to do PC-relative data
referencing. To do this, we need to define a get_pc() kind of function and
call it to load the PC in a desired register.

There are two cases:

1. The call instruction pushes the return address on the stack.

   In this case, get_pc() will extract the return address from the stack
   and load it in the desired register and return.

2. The call instruction stores the return address in a designated register.

   In this case, get_pc() will copy the return address to the desired
   register and return.

Either way, the PC next to the call instruction is obtained.

Scratch register
================

In order to do its job, the trampoline code would need to use a scratch
register. Depending on the ABI, there may not be a register available for
scratch. This problem needs to be solved so that all ABIs will work.

The trampoline will save two values on the stack:

- the closure pointer
- the original value of the scratch register

This is what the stack will look like:

sp before trampoline ------> --------------------
| closure pointer  |
--------------------
| scratch register |
sp after trampoline -------> --------------------

The ABI handler can do the following as needed by the ABI:

- the closure pointer can be loaded in a desired register

- the scratch register can be restored to its original value

- the stack pointer can be restored to its original value
  (the value when the trampoline was invoked)

To do this, I have defined prolog code for each ABI handler. The legacy
trampoline jumps to the ABI handler directly. But the static trampoline
defined in this patch jumps tp the prolog code which performs the above
actions before jumping to the ABI handler.

Trampoline Table
================

In order to reduce the trampoline memory footprint, the trampoline code
would be defined as a code array in the text segment. This array would be
mapped into the address space of the caller. The mapping would, therefore,
contain a trampoline table.

Adjacent to the trampoline table mapping, there will be a data mapping that
contains a parameter table, one parameter block for each trampoline. The
parameter block will contain:

- a pointer to the closure
- a pointer to the ABI handler

The static trampoline code would finally look like this:

- Make space on the stack for the closure and the scratch register
  by moving the stack pointer down
- Store the original value of the scratch register on the stack
- Using PC-relative reference, get the closure pointer
- Store the closure pointer on the stack
- Using PC-relative reference, get the ABI handler pointer
- Jump to the ABI handler

Mapping size
============

The size of the code mapping that contains the trampoline table needs to be
determined on a per architecture basis. If a particular architecture
supports multiple base page sizes, then the largest supported base page size
needs to be chosen. E.g., we choose 16K for ARM64.

Trampoline allocation and free
==============================

Static trampolines are allocated in ffi_closure_alloc() and freed in
ffi_closure_free().

Normally, applications use these functions. But there are some cases out
there where the user of libffi allocates and manages its own closure
memory. In such cases, static trampolines cannot be used. These will
fall back to using legacy trampolines. The user has to make sure that
the memory is executable.

ffi_closure structure
=====================

I did not want to make any changes to the size of the closure structure for
this feature to guarantee compatibility. But the opaque static trampoline
handle needs to be stored in the closure. I have defined it as follows:

-  char tramp[FFI_TRAMPOLINE_SIZE];
+  union {
+    char tramp[FFI_TRAMPOLINE_SIZE];
+    void *ftramp;
+  };

If static trampolines are used, then tramp[] is not needed to store a
dynamic trampoline. That space can be reused to store the handle. Hence,
the union.

Architecture Support
====================

Support has been added for x64, i386, aarch64 and arm. Support for other
architectures can be added very easily in the future.

OS Support
==========

Support has been added for Linux. Support for other OSes can be added very
easily.

Signed-off-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
* x86: Support for Static Trampolines

- Define the arch-specific initialization function ffi_tramp_arch ()
  that returns trampoline size information to common code.

- Define the trampoline code mapping and data mapping sizes.

- Define the trampoline code table statically. Define two tables,
  actually, one with CET and one without.

- Introduce a tiny prolog for each ABI handling function. The ABI
  handlers addressed are:

   - ffi_closure_unix64
- ffi_closure_unix64_sse
- ffi_closure_win64

  The prolog functions are called:

- ffi_closure_unix64_alt
- ffi_closure_unix64_sse_alt
- ffi_closure_win64_alt

  The legacy trampoline jumps to the ABI handler. The static
  trampoline jumps to the prolog function. The prolog function uses
  the information provided by the static trampoline, sets things up
  for the ABI handler and then jumps to the ABI handler.

- Call ffi_tramp_set_parms () in ffi_prep_closure_loc () to
  initialize static trampoline parameters.

Signed-off-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
* i386: Support for Static Trampolines

- Define the arch-specific initialization function ffi_tramp_arch ()
  that returns trampoline size information to common code.

- Define the trampoline code table statically. Define two tables,
  actually, one with CET and one without.

- Define the trampoline code table statically.

- Introduce a tiny prolog for each ABI handling function. The ABI
  handlers addressed are:

   - ffi_closure_i386
- ffi_closure_STDCALL
- ffi_closure_REGISTER

  The prolog functions are called:

   - ffi_closure_i386_alt
- ffi_closure_STDCALL_alt
- ffi_closure_REGISTER_alt

  The legacy trampoline jumps to the ABI handler. The static
  trampoline jumps to the prolog function. The prolog function uses
  the information provided by the static trampoline, sets things up
  for the ABI handler and then jumps to the ABI handler.

- Call ffi_tramp_set_parms () in ffi_prep_closure_loc () to
  initialize static trampoline parameters.

Signed-off-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
* arm64: Support for Static Trampolines

- Define the arch-specific initialization function ffi_tramp_arch ()
  that returns trampoline size information to common code.

- Define the trampoline code mapping and data mapping sizes.

- Define the trampoline code table statically.

- Introduce a tiny prolog for each ABI handling function. The ABI
  handlers addressed are:

   - ffi_closure_SYSV
- ffi_closure_SYSV_V

  The prolog functions are called:

   - ffi_closure_SYSV_alt
- ffi_closure_SYSV_V_alt

  The legacy trampoline jumps to the ABI handler. The static
  trampoline jumps to the prolog function. The prolog function uses
  the information provided by the static trampoline, sets things up
  for the ABI handler and then jumps to the ABI handler.

- Call ffi_tramp_set_parms () in ffi_prep_closure_loc () to
  initialize static trampoline parameters.

Signed-off-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
* arm: Support for Static Trampolines

- Define the arch-specific initialization function ffi_tramp_arch ()
  that returns trampoline size information to common code.

- Define the trampoline code mapping and data mapping sizes.

- Define the trampoline code table statically.

- Introduce a tiny prolog for each ABI handling function. The ABI
  handlers addressed are:

   - ffi_closure_SYSV
- ffi_closure_VFP

  The prolog functions are called:

   - ffi_closure_SYSV_alt
- ffi_closure_VFP_alt

  The legacy trampoline jumps to the ABI handler. The static
  trampoline jumps to the prolog function. The prolog function uses
  the information provided by the static trampoline, sets things up
  for the ABI handler and then jumps to the ABI handler.

- Call ffi_tramp_set_parms () in ffi_prep_closure_loc () to
  initialize static trampoline parameters.

Signed-off-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
3 years agoUse memfd_create() (#604)
DJ Delorie [Wed, 2 Dec 2020 21:14:27 +0000 (16:14 -0500)]
Use memfd_create() (#604)

memfd_create creates a file in a memory-only filesystem that may
bypass strict security protocols in filesystem-based temporary
files.

3 years agolibffi/x86: Always check __x86_64__ for x32 hosts (#601) (#602)
hjl-tools [Wed, 2 Dec 2020 20:52:12 +0000 (12:52 -0800)]
libffi/x86: Always check __x86_64__ for x32 hosts (#601) (#602)

Since for x86_64-*x32 and x86_64-x32-* hosts, -m32 generates ia32 codes.
We should always check __x86_64__ for x32 hosts.

3 years agoProperly quote and resolve msvcc.sh params (#596)
Tres Finocchiaro [Wed, 25 Nov 2020 00:13:57 +0000 (19:13 -0500)]
Properly quote and resolve msvcc.sh params (#596)

3 years agoAllow to build with mingw-clang (#579)
Mike Hommey [Tue, 10 Nov 2020 11:41:33 +0000 (20:41 +0900)]
Allow to build with mingw-clang (#579)

For some reason, compiling sysv.S with mingw-clang fails with:
```
error: invalid variant 'ffi_closure_inner@8'
```

This can be fixed (worked around?) by quoting the symbol. This works
fine with mingw-gcc too.

3 years agoDon't use FFI_TYPE_LONGDOUBLE in the jump table in win64*.S (#580)
Mike Hommey [Tue, 10 Nov 2020 11:39:25 +0000 (20:39 +0900)]
Don't use FFI_TYPE_LONGDOUBLE in the jump table in win64*.S (#580)

It may have the same value as FFI_TYPE_DOUBLE per ffi.h, which
possibly can make things go wrong with .org/ORG.

For instance, GCC complains about "Error: attempt to move .org
backwards"

3 years agoaarch64: Allow FFI_WIN64 for winelib (#593)
AndreRH [Tue, 10 Nov 2020 11:27:59 +0000 (12:27 +0100)]
aarch64: Allow FFI_WIN64 for winelib (#593)

3 years agoAdd support for powerpc64le-*-freebsd*. (#581)
Brandon Bergren [Tue, 27 Oct 2020 14:07:38 +0000 (09:07 -0500)]
Add support for powerpc64le-*-freebsd*. (#581)

Tests pass with no additional changes needed, tested on hardware.

3 years agodarwin powerpc: use go closures only if enabled (#583)
Ken [Tue, 27 Oct 2020 14:07:07 +0000 (07:07 -0700)]
darwin powerpc: use go closures only if enabled (#583)

SHA: 0ff9419f2e75652426469e256cb7d0748064ad58 added go closures for darwin powerpc AIX, but
these have not yet been implemented for non-AIX systems

use the go closures only if enabled

3 years agoSupport building x86 and arm64 without FFI_GO_CLOSURES (#586)
Jeremy Huddleston Sequoia [Tue, 27 Oct 2020 14:06:21 +0000 (07:06 -0700)]
Support building x86 and arm64 without FFI_GO_CLOSURES (#586)

* x86: Support building without FFI_GO_CLOSURES

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
* arm: Support building without FFI_GO_CLOSURES

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
3 years agotestsuite: Add a missing include of <inttypes.h> to fix build failure in test suite...
Jeremy Huddleston Sequoia [Tue, 27 Oct 2020 14:05:28 +0000 (07:05 -0700)]
testsuite: Add a missing include of <inttypes.h> to fix build failure in test suite (#587)

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
3 years agoRemoving unnecessary instruction from ffi_call_unix64 (#588)
petersn [Tue, 27 Oct 2020 14:02:36 +0000 (07:02 -0700)]
Removing unnecessary instruction from ffi_call_unix64 (#588)

unix64.S's `ffi_call_unix64` looks like it used to take six parameters,
where the sixth said the number of SSE register arguments. However,
currently the function only takes five parameters, and the number of SSE
register arguments is encoded in the `struct register_args *` passed as
the first parameter to `ffi_call_unix64`. This change removes an
instruction that tries to use this missing sixth parameter as the number
of SSE arguments.

This fix should not change any behavior, nor fix any bugs, because a few
instructions later the value moved from %r9d into %eax is overwritten by
the correct value anyway. This change merely makes the code a tad less
confusing, because currently the assembly moves from a register (r9)
whose value is never set.

3 years agoFix read-only .eh_frame section test when CFLAGS contains -flto. (#590)
jacobly0 [Tue, 27 Oct 2020 14:00:03 +0000 (10:00 -0400)]
Fix read-only .eh_frame section test when CFLAGS contains -flto. (#590)

3 years agoPower10 libffi fixes (#585)
Alan Modra [Tue, 27 Oct 2020 13:06:21 +0000 (23:36 +1030)]
Power10 libffi fixes (#585)

Power10 pc-relative code doesn't use or preserve r2 as a TOC pointer.
That means calling between pc-relative and TOC using code can't be
done without intervening linker stubs, and a call from TOC code to
pc-relative code must have a nop after the bl in order to restore r2.

Now the PowerPC libffi assembly code doesn't use r2 except for the
implicit use when making calls back to C, ffi_closure_helper_LINUX64
and ffi_prep_args64.  So changing the assembly to interoperate with
pc-relative code without stubs is easily done.

* src/powerpc/linux64.S (ffi_call_LINUX64): Don't emit global
entry when __PCREL__.  Call using @notoc.  Add nops.
* src/powerpc/linux64_closure.S (ffi_closure_LINUX64): Likewise.
(ffi_go_closure_linux64): Likewise.

3 years agodocs: fix simple typo, paramters -> parameters (#589)
Tim Gates [Sun, 11 Oct 2020 04:07:40 +0000 (15:07 +1100)]
docs: fix simple typo, paramters -> parameters (#589)

There is a small typo in src/x86/ffi.c.

Should read `parameters` rather than `paramters`.

3 years agoRe-enable s390x testing
Anthony Green [Wed, 19 Aug 2020 12:34:09 +0000 (08:34 -0400)]
Re-enable s390x testing

3 years agoUpstream local FreeBSD patches (#567)
Niclas Zeising [Fri, 7 Aug 2020 19:05:23 +0000 (21:05 +0200)]
Upstream local FreeBSD patches (#567)

* Add support for FreeBSD mips

Add support for FreeBSD mips, this has been a local patch in the FreeBSD
ports tree for quite some time.

Originally submitted by sson, and committed by sbruno AT FreeBSD DOT org
See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=191909 for
background details.

Signed-off-by: Niclas Zeising <zeising@daemonic.se>
* Add support for FreeBSD powerpcspe

Add support for powerpcspe on FreeBSD
This has been in the FreeBSD ports tree for some time.
Originally submitted by jhibbits AT FreeBSD DOT org.

Signed-off-by: Niclas Zeising <zeising@daemonic.se>
* Fix abort() on FreeBSD arm related to __clear_cache()

This patch has been in the FreeBSD ports tree for a number of years.
Original commit by koobs AT FreeBSD DOT org

Original commit message:
> devel/libffi: Fix abort() on ARM related to __clear_cache()
>
> The current FreeBSD/ARM __clear_cache() implementation does nothing #if
> __i386__ || __x86_64__ #else abort();
>
> cognet@ advises this is an issue for anything !Apple that is using the
> libcompiler_rt provided by Clang on ARM, and requires upstreaming.

See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=149167 for some
background details.

Signed-off-by: Niclas Zeising <zeising@daemonic.se>
3 years agoDon't test s390. Travis-ci is broken.
Anthony Green [Thu, 6 Aug 2020 01:38:51 +0000 (21:38 -0400)]
Don't test s390.  Travis-ci is broken.

3 years agoAdd support for eabisim back. This was removed upstream.
Anthony Green [Wed, 5 Aug 2020 21:59:59 +0000 (17:59 -0400)]
Add support for eabisim back.  This was removed upstream.

3 years agoMerge pull request #576 from froydnj/config-updates
Tom Tromey [Tue, 4 Aug 2020 17:08:19 +0000 (11:08 -0600)]
Merge pull request #576 from froydnj/config-updates

update config.{guess,sub}

3 years agoupdate config.{guess,sub}
Nathan Froyd [Tue, 4 Aug 2020 16:17:04 +0000 (12:17 -0400)]
update config.{guess,sub}

This change is primarily for aarch64 macOS support, since that configuration
is now properly supported upstream.

3 years agoMerge pull request #570 from jwilk-forks/spelling
Tom Tromey [Wed, 1 Jul 2020 15:32:37 +0000 (09:32 -0600)]
Merge pull request #570 from jwilk-forks/spelling

aarch64: Fix typo

3 years agoaarch64: Fix typo
Jakub Wilk [Tue, 30 Jun 2020 20:59:28 +0000 (22:59 +0200)]
aarch64: Fix typo

3 years agoAdd support for csky
Ma Jun [Mon, 29 Jun 2020 12:02:20 +0000 (08:02 -0400)]
Add support for csky

3 years agoMakefile: increase compatibility with bmake (#551)
M. Herdiansyah [Thu, 11 Jun 2020 12:40:24 +0000 (19:40 +0700)]
Makefile: increase compatibility with bmake (#551)

3 years agoFixes macOS build on Python 3 (#563)
Andre Miras [Thu, 11 Jun 2020 12:38:59 +0000 (14:38 +0200)]
Fixes macOS build on Python 3 (#563)

The error was:
```
Traceback (most recent call last):
  File "_generate-darwin-source-and-headers.py", line 209, in <module>
    generate_source_and_headers(generate_osx=not args.only_ios, generate_ios=not args.only_osx)
  File "_generate-darwin-source-and-headers.py", line 197, in generate_source_and_headers
    for header_name, tag_tuples in platform_headers.iteritems():
AttributeError: 'collections.defaultdict' object has no attribute 'iteritems'
```

3 years agoFix Free software foundation address (#564)
Kentaro Hayashi [Thu, 11 Jun 2020 12:37:41 +0000 (21:37 +0900)]
Fix Free software foundation address (#564)

ref. https://www.fsf.org/about/contact/

3 years agoAdd gcc bug tests back
Anthony Green [Sun, 7 Jun 2020 18:31:06 +0000 (14:31 -0400)]
Add gcc bug tests back

4 years agoAdd support for Kalray KVX architecture (#559)
Yann Sionneau [Fri, 1 May 2020 11:59:11 +0000 (13:59 +0200)]
Add support for Kalray KVX architecture (#559)

4 years agoffi_powerpc.h: fix build failure with powerpc7 (#561)
Andrew Geissler [Fri, 1 May 2020 11:58:30 +0000 (06:58 -0500)]
ffi_powerpc.h: fix build failure with powerpc7 (#561)

This is a patch pulled down from the following:
https://github.com/buildroot/buildroot/blob/78926f610b1411b03464152472fd430012deb9ac/package/libffi/0004-ffi_powerpc.h-fix-build-failure-with-powerpc7.patch

This issue is being hit on OpenBMC code when pulling the latest
libffi tag and building on a P8 ppc64le machine. I verified this
patch fixes the issue we are seeing.

Below is the original commit message:

Sicne commit 73dd43afc8a447ba98ea02e9aad4c6898dc77fb0, build on powerpc7
fails on:

In file included from ../src/powerpc/ffi.c:33:0:
../src/powerpc/ffi_powerpc.h:61:9: error: '_Float128' is not supported on this target
 typedef _Float128 float128;
         ^~~~~~~~~

Fix this build failure by checking for __HAVE_FLOAT128 before using
_Float128, as _Float128 is enabled only on specific conditions, see
output/host/powerpc64-buildroot-linux-gnu/sysroot/usr/include/bits/floatn.h:

 /* Defined to 1 if the current compiler invocation provides a
    floating-point type with the IEEE 754 binary128 format, and this glibc
    includes corresponding *f128 interfaces for it.  */
 #if defined _ARCH_PWR8 && defined __LITTLE_ENDIAN__ && (_CALL_ELF == 2) \
     && defined __FLOAT128__ && !defined __NO_LONG_DOUBLE_MATH
 # define __HAVE_FLOAT128 1
 #else
 # define __HAVE_FLOAT128 0
 #endif

Fixes:
 - http://autobuild.buildroot.org/results/5c9dd8fb3b6a128882b6250f197c80232d8a3b53

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Co-authored-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
4 years agoarm: Fix the clang specific version of the assembly (#556)
Martin Storsjö [Sun, 26 Apr 2020 02:02:14 +0000 (05:02 +0300)]
arm: Fix the clang specific version of the assembly (#556)

Also fix the same error in the comment for the non-clang case.
That typo there seems to have existed since the code was written
in that form, in e7f15f60e86 - and when the clang specific codepath
was added in e3d2812ce43, the typo in the comment made it into the
actual code.

4 years agowin64_armasm: Fix the spelling of ALIGN (#553)
Martin Storsjö [Sun, 26 Apr 2020 02:01:03 +0000 (05:01 +0300)]
win64_armasm: Fix the spelling of ALIGN (#553)

4 years agoUse __builtin_ffs instead of ffs (#554)
Martin Storsjö [Sun, 26 Apr 2020 01:59:35 +0000 (04:59 +0300)]
Use __builtin_ffs instead of ffs (#554)

USE_BUILTIN_FFS is defined to 1 within __GNUC__, and the __builtin_ffs
function is available since GCC 3.x at least, while the ffs function
only exists on some OSes.

This fixes compilation for non-x86 mingw platforms. For x86,
USE_BUILTIN_FFS is explicitly disabled for windows targets - but
if USE_BUILTIN_FFS is enabled based on __GNUC__, it should also use
the builtin which actually is available correspondingly, not dependent
on the target OS.

4 years agoFix building for aarch64 windows with mingw toolchains (#555)
Martin Storsjö [Sun, 26 Apr 2020 01:58:33 +0000 (04:58 +0300)]
Fix building for aarch64 windows with mingw toolchains (#555)

* aarch64: Check _WIN32 instead of _M_ARM64 for detecting windows

This fixes building for aarch64 with mingw toolchains. _M_ARM64 is
predefined by MSVC, while mingw compilers predefine __aarch64__.

In aarch64 specific code, change checks for _M_ARM64 into checks for
_WIN32.

In arch independent code, check for
(defined(_M_ARM64) || defined(__aarch64__)) && defined(_WIN32)
instead of just _M_ARM64.

In src/closures.c, coalesce checks like
defined(X86_WIN32) || defined(X86_WIN64) || defined(_M_ARM64)
into plain defined(_WIN32). Technically, this enables code for
ARM32 windows where it wasn't, but as far as I can see it, those
codepaths should be fine for that architecture variant as well.

* aarch64: Only use armasm source when building with MSVC

When building for windows/arm64 with clang, the normal gas style .S
source works fine. sysv.S and win64_armasm.S seem to be functionally
equivalent, with only differences being due to assembler syntax.

4 years agoImprove read-write .eh_frame check (#546)
Fangrui Song [Tue, 10 Mar 2020 11:36:09 +0000 (04:36 -0700)]
Improve read-write .eh_frame check (#546)

llvm-objdump -h does not print BFD SEC_* constants like "READONLY",
so the check will consider .eh_frame writable.
clang 11 (since https://reviews.llvm.org/D73999) will error for mismatching section flags.

Use readelf -S and check "WA" instead.

4 years agoMention ARM Pointer Authentication
Moxie Bot [Tue, 10 Mar 2020 01:10:53 +0000 (21:10 -0400)]
Mention ARM Pointer Authentication

4 years agoTest on aarch64 Linux with clang
Moxie Bot [Tue, 10 Mar 2020 01:10:33 +0000 (21:10 -0400)]
Test on aarch64 Linux with clang

4 years agoPort to iOS/arm64e (#548)
Ole André Vadla Ravnås [Tue, 10 Mar 2020 01:05:42 +0000 (02:05 +0100)]
Port to iOS/arm64e (#548)

4 years agoTry to fix RLGL_KEY nonsense (#547)
Anthony Green [Mon, 9 Mar 2020 16:39:22 +0000 (12:39 -0400)]
Try to fix RLGL_KEY nonsense (#547)

* Try to fix RLGL_KEY nonsense

* Hard code policy bound API key

Co-authored-by: Anthony Green <green@moxielogic.com>
4 years agoRevamp PA_LINUX and PA_HPUX target closures to use function descriptors.
Moxie Bot [Mon, 24 Feb 2020 15:29:20 +0000 (10:29 -0500)]
Revamp PA_LINUX and PA_HPUX target closures to use function descriptors.

2020-02-23  John David Anglin  <danglin@gcc.gnu.org>

* include/ffi.h.in (FFI_CLOSURE_PTR, FFI_RESTORE_PTR): Define.
* src/closures.c (ffi_closure_alloc): Convert closure pointer
return by malloc to function pointer.
(ffi_closure_free): Convert function pointer back to malloc pointer.
* src/pa/ffi.c (ffi_closure_inner_pa32): Use union to double word
align return address on stack.  Adjust statements referencing return
address.  Convert closure argument from function pointer to standard
closure pointer.
(ffi_prep_closure_loc): Likewise convert closure argument back to
closure pointer.  Remove assembler trampolines.  Setup simulated
function descriptor as on ia64.
src/pa/ffitarget.h (FFI_TRAMPOLINE_SIZE): Reduce to 12.
src/pa/hpux32.S (ffi_closure_pa32): Retrieve closure pointer and real
gp from fake gp value in register %r19.
src/pa/linux.S (ffi_closure_pa32): Likewise.

4 years agoUpdate the ABI version to LIBFFI_BASE_8.0 (#544)
hjl-tools [Sun, 23 Feb 2020 15:45:42 +0000 (07:45 -0800)]
Update the ABI version to LIBFFI_BASE_8.0 (#544)

Since x86 and x86-64 FFI_TRAMPOLINE_SIZE have been increased, we must
bump the ABI version.  This fixes:

https://github.com/libffi/libffi/issues/543

4 years agox86: Fix ffi_prep_closure_loc (#542)
hjl-tools [Sat, 22 Feb 2020 14:32:22 +0000 (06:32 -0800)]
x86: Fix ffi_prep_closure_loc (#542)

Since FFI_TRAMPOLINE_SIZE is increased by 4 bytes to add ENDBR32, adjust
jump displacement by 4 bytes.

4 years agoMerge branch 'master' of github.com:/libffi/libffi
Moxie Bot [Sat, 22 Feb 2020 03:13:14 +0000 (22:13 -0500)]
Merge branch 'master' of github.com:/libffi/libffi

4 years agoUpdate for pending 3.4 release.
Moxie Bot [Sat, 22 Feb 2020 03:12:34 +0000 (22:12 -0500)]
Update for pending 3.4 release.

4 years agox86: Add indirect branch tracking support (#540)
hjl-tools [Sat, 22 Feb 2020 03:08:06 +0000 (19:08 -0800)]
x86: Add indirect branch tracking support (#540)

Intel Control-flow Enforcement Technology (CET):

https://software.intel.com/en-us/articles/intel-sdm

contains shadow stack (SHSTK) and indirect branch tracking (IBT).  When
CET is enabled, ELF object files must be marked with .note.gnu.property
section.  When Intel CET is enabled, include <cet.h> in assembly codes
to mark Intel CET support.

Also when IBT is enabled, all indirect branch targets must start with
ENDBR instruction and notrack prefix can be used to disable IBT on
indirect branch.  <cet.h> defines _CET_ENDBR which can be used in
assembly codes for ENDBR instruction.  If <cet.h> isn't included,
define _CET_ENDBR as empty so that _CET_ENDBR can be used in assembly
codes.

Trampoline must be enlarged to add ENDBR instruction unconditionally,
which is NOP on non-CET processors.  This is required regardless if
libffi is enabled with CET since libffi.so will be marked in legacy
bitmap, but trampoline won't.  Update library version for larger
FFI_TRAMPOLINE_SIZE.

This fixed:

https://github.com/libffi/libffi/issues/474

Tested with

$ CC="gcc -Wl,-z,cet-report=error -fcf-protection" CXX="g++ -Wl,-z,cet-report=error -fcf-protection" .../configure

on Linux CET machines in i686, x32 and x86-64 modes.