RFR: 8309880: Add support for linking libffi on Windows and Mac
Jorn Vernee
jvernee at openjdk.org
Tue Jun 13 13:53:19 UTC 2023
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 failing tests in the jdk_foreign suite 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 `urct64` (this is one of the shell environments that comes with MSYS2)
3. then, in the libffi repo root folder:
3.a run `autogen.sh`
3.b run:
bash configure \
CC="/mnt/h/Projects-new/libffi/msvcc.sh -m64" \
CXX="/mnt/h/Projects-new/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 a 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 `.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
-------------
Commit messages:
- update libffi script for mac
- mac fixes
- working fallback linker on Windows x64
Changes: https://git.openjdk.org/jdk/pull/14446/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=14446&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8309880
Stats: 103 lines in 7 files changed: 73 ins; 9 del; 21 mod
Patch: https://git.openjdk.org/jdk/pull/14446.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/14446/head:pull/14446
PR: https://git.openjdk.org/jdk/pull/14446
More information about the core-libs-dev
mailing list