Integrated: 8309880: Add support for linking libffi on Windows and Mac
Jorn Vernee
jvernee at openjdk.org
Wed Jun 14 12:07:07 UTC 2023
On Tue, 13 Jun 2023 12:48:12 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
> Update the make/autoconf/lib-ffi.m4 script to support using libffi on Windows and Mac.
>
> For Windows I had to tweak `fallbackLinker.c` to be able to build: there was an import of `stdint.h` missing, and since it was using `WSAGetLastError` it needed to link against `ws2_32.lib`.
>
> This PR also contains a fix originally made by @shipilev as part of: https://github.com/openjdk/jdk/pull/13827 (with a minor tweak), in order to be able to build the fallback linker on mac correctly. I also disabled 3 tests that were failing when using the (libffi-based) fallback linker on that platform.
>
> ---
>
> I've updated the `createLibffiBundle.sh` script for Mac, since I got it to work with a devkit, but I didn't manage to do the same for Windows. The steps I took to make my Windows libffi bundle were as follows:
> 1. run 'x64 Native Tools Command Prompt for VS 2022'. cl.exe and link.exe should be on path
> 2. run `ucrt64` (this is one of the shell environments that comes with MSYS2). This should carry over the environment set up by the VS dev prompt.
> 3. then, in the libffi repo root folder:
> 3.a run `autogen.sh`
> 3.b run:
>
> bash configure \
> CC="/path/to/libffi/msvcc.sh -m64" \
> CXX="/path/to/libffi/msvcc.sh -m64" \
> CPPFLAGS="-DFFI_BUILDING_DLL" \
> --disable-docs \
> --prefix=<install dest>
>
> (`<install dest>` can be whatever you like. That's what you point `--with-libffi` to).
>
> 4. run `make install`. This should create the `<intstall dest>` directory with the files: `include/ffi.h`, `include/ffitarget.h`, `lib/libffi.dll`. It also creates a `lib/libffi.lib` file, but it is of the wrong file type, `DLL` rather than `LIBRARY`.
> 5. Manually create a working `.lib` file:
> 5.a use `dumpbin /exports libffi.dll` to get a list of exported symbols
> 5.b put them in a `libffi.def` file: `EXPORTS` on the first line, then a symbol on each line following
> 5.c run `lib /def:libffi.def /machine:x64 /out:libffi.lib` to create the right `.lib` file (`lib` is a visual studio tool)
>
> ---
>
> Testing:
> - manual testing on Windows/x64 and Mac/AArch64, by running the `jdk_foreign` test suite with `-Djdk.internal.foreign.CABI=FALLBACK` (i.e. using the fallback linker).
> - Linux/x64 Zero test run of the `jdk_foreign` suite
> - Linux/AArch64 Zero build
This pull request has now been integrated.
Changeset: 4c18b9e1
Author: Jorn Vernee <jvernee at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/4c18b9e1faba32bd54a5d8b0b3c21b07f694c71b
Stats: 135 lines in 7 files changed: 105 ins; 9 del; 21 mod
8309880: Add support for linking libffi on Windows and Mac
Co-authored-by: Aleksey Shipilev <shade at openjdk.org>
Co-authored-by: Jorn Vernee <jvernee at openjdk.org>
Reviewed-by: erikj
-------------
PR: https://git.openjdk.org/jdk/pull/14446
More information about the core-libs-dev
mailing list