Skip to content

Conversation

HertzDevil
Copy link
Collaborator

No description provided.

billatarm and others added 30 commits February 20, 2025 05:25
While PAC was enabled, the bit to indicate support in the GNU Notes
section of the ELF was missing.

Before:
readelf -n ./aarch64-unknown-linux-gnu/.libs/libffi.so

Displaying notes found in: .note.gnu.property
  Owner                Data size 	Description
  GNU                  0x00000010	NT_GNU_PROPERTY_TYPE_0
      Properties: AArch64 feature: BTI

This was caused by this file not having PAC indicated in GNU Notes and
the linker discarding it:
File: ./aarch64-unknown-linux-gnu/src/aarch64/sysv.o

Displaying notes found in: .note.gnu.property
  Owner                Data size        Description
  GNU                  0x00000010       NT_GNU_PROPERTY_TYPE_0
      Properties: AArch64 feature: BTI

Now it has it:
File: ./aarch64-unknown-linux-gnu/src/aarch64/sysv.o

Displaying notes found in: .note.gnu.property
  Owner                Data size        Description
  GNU                  0x00000010       NT_GNU_PROPERTY_TYPE_0
      Properties: AArch64 feature: BTI, PAC

As well as the output shared object:
readelf -n ./aarch64-unknown-linux-gnu/.libs/libffi.so

Displaying notes found in: .note.gnu.property
  Owner                Data size 	Description
  GNU                  0x00000010	NT_GNU_PROPERTY_TYPE_0
      Properties: AArch64 feature: BTI, PAC

Fixes: libffi#881

Signed-off-by: Bill Roberts <[email protected]>
Fixes the following error:
candidate function not viable: no known conversion from 'int (const char *)' to 'void (*)()' for 2nd argument
This commit fixes two bugs in ffi in the x86-64 target. The bugs were
introduced by the commit d21881f ("Fix
x86/ffi64 calls with 6 gp and some sse registers").

The first bug is that when we pass an argument with less than 8 bytes,
ffi will read memory beyond argument end, causing a crash if the argument
is located just before the end of the mapped region.

The second bug is in the x32 ABI - pointers in x32 are 4-byte, but GCC
assumes that the pointer values in the registers are zero-extended. ffi
doesn't respect this assumption, causing crashes in the called library.

For example, when we compile this function for x32:
int fn(int *a)
{
	if (a)
		return *a;
	return -1;
}
we get this code:
fn:
	testq   %rdi, %rdi
	je      .L3
	movl    (%edi), %eax
	ret
.L3:
	movl    $-1, %eax
	ret
When we call this function using ffi with the argument NULL, the function
crashes because top 4 bytes of the RDI register are not cleared.


Fixes: d21881f ("Fix x86/ffi64 calls with 6 gp and some sse registers (libffi#848)")

Signed-off-by: Mikulas Patocka <[email protected]>
…#892)

I accidentally omitted the "ABI_ATTR" attribute, so that the testsuite
fails when testing the Microsoft ABI.

Fixes: fe203ff ("Fix bugs in the x86-64 and x32 target (libffi#887) (libffi#889)")

Signed-off-by: Mikulas Patocka <[email protected]>
Add static trampoline support to all three powerpc Linux ABIs, specifically
powerpc-linux (32-bit SYSV BE), powerpc64-linux (64-bit ELFv1 BE) and
powerpc64le-linux (64-bit ELFv2 LE).  This follows the s390x implementation
and does not introduce a ffi_closure_*_alt function, but rather jumps
directly to the ffi_closure_* function itself.  If compiling with
--with-gcc-arch=power10 and pc-relative is enabled, we use a simpler and
smaller trampoline that utilizes Power10's new pc-relative load instructions.
* Add libffi.call/overread.c and libffi.call/x32.c to Makefile.am
  so they're included in dist tarballs

* Fix indentation and rewrap
Similarly to f515eac, add a .note.GNU-stack
marker to pa/linux.S as it doesn't need an executable stack. Absence of the
note means that GNU Binutils will consider it as needing an executable stack
and mark it as such automatically.

When building libffi on HPPA with `-Wl,--warn-warn-execstack`, we get:
```
ld: warning: src/pa/.libs/linux.o: missing .note.GNU-stack section implies executable stack
ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
```

That becomes more problematic with glibc-2.41 which forbids dlopen()
of a library with an executable stack, and libffi is commonly dlopen()'d,
especially by Python.

I suspect the reason it didn't show up on Debian is that since February,
Debian has been building Binutils with --disable-default-execstack.

Bug: https://bugs.gentoo.org/953805
Bug: libffi#898
…ffi#900) (libffi#902)

Closures on powerpc64-linux using static trampolines do not work when
statically linking libffi.  The problem is the usage of tramp_globals.text
in libffi assumes it contains the entry point address of the first trampoline.
Powerpc's ffi_tramp_arch code returns &trampoline_code_table which for ABIs
that use function descriptors, ends up returning trampoline_code_table's
function descriptor address instead of its entry point address.  Update
the code to always return the entry point address for all ABIs.
… testing. (libffi#912)

This commit removes many platforms from the testing workflow.
They will be added back in future commits.
atgreen and others added 29 commits June 8, 2025 07:56
* ci: add new build configuration in GitHub Actions

* ci: add Windows clang build workflow

* ci: add additional packages to GitHub workflows build

* ci: optimize build workflow and improve commenting

* ci: remove unused MSVC dev command from build workflow

* ci: modify build workflow to support multiple compilers

* build(github-actions): use matrix.compiler for CC and CXX variables
Add CI testing on Windows with both gcc and clang.
* Downgrade Autoconf requirement to version 2.68

* CI: remove redundant Autoconf install scripts
* Create tarballs in CI
…an Weimer.

c# Please enter the commit message for your changes. Lines starting
Similar to PR libffi#265 [1], we need to enable FFI_MMAP_EXEC_WRIT to use
explicit write+exec mapping on DragonFly BSD.

Without this fix, we were having segfaults with Meld [2]; it would crash
with SIGSEGV after 5 diff operations.  The crash was caused by it
attempting to execute code from non-execute memory region.  Moreover, if
we set the `machdep.pmap_nx_enable=2` tunable (i.e., strict NX mode),
Meld would crash upon the first diff operation.

Fix the `configure.ac` script to enable `FFI_MMAP_EXEC_WRIT` for
DragonFly BSD.  In addition, add it to the supported platforms table.

[1] libffi#265
[2] https://meldmerge.org/
* src/wasm32: Allow building with Emscripten with 64bit support

MEMORY64 enables 64bit pointers so this commit updates the accessors for the
libffi data structures accordingly.

Each JS functions in ffi.c receives pointers as BigInt (i64) values and with
casts them to Numer (i53) using bigintToI53Checked. While memory64 supports
64bit addressing, the maximum memory size is currently limited to 16GiB
[1]. Therefore, we can assume that the passed pointers are within the
Number's range.

[1] https://webassembly.github.io/memory64/js-api/#limits

Signed-off-by: Kohei Tokunaga <[email protected]>

* Add wasm64 target to the build scripts

This commit adds support for the wasm64 target via the configure
script. Emscripten supports two modes of the -sMEMORY64 flag[1] so the
script allows users specifying the value through a configuration variable.

Additionally, "src/wasm32" directory has been renamed to the more generic
"src/wasm" because it's now shared between both 32bit and 64bit builds.

[1] https://emscripten.org/docs/tools_reference/settings_reference.html#memory64

Signed-off-by: Kohei Tokunaga <[email protected]>

* GitHub Actions: Add wasm64 tests

This commit adds a test matrix for wasm32, wasm64 and wasm64 with the
-sMEMORY64=2 flag, using the latest version of Emscripten. -Wno-main is
added to suppress the following warning in unwindtest.cc and
unwindtest_ffi_call.cc.

> FAIL: libffi.closures/unwindtest_ffi_call.cc -W -Wall -O2 (test for excess errors)
> Excess errors:
> ./libffi.closures/unwindtest_ffi_call.cc:20:5: warning: 'main' should not be 'extern "C"' [-Wmain]
>    20 | int main (void)
>       |     ^
> 1 warning generated.

Signed-off-by: Kohei Tokunaga <[email protected]>

* testsuite: Fix types of main function

test_libffi.py calls each test's main function without arguments, but some
tests define the main function with parameters. This signature mismatch
causes a runtime error with the recent version of Emscripten.

This commit resolves this issue by updating the function signatures to match
the way they are called.

Signed-off-by: Kohei Tokunaga <[email protected]>

* README: Add document about WASM64

Signed-off-by: Kohei Tokunaga <[email protected]>

---------

Signed-off-by: Kohei Tokunaga <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.