RFR: 7903654: Jextract should use library lookup
Maurizio Cimadamore
mcimadamore at openjdk.org
Wed Feb 7 22:01:17 UTC 2024
On Wed, 7 Feb 2024 16:18:45 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> Historically, jextract has always used `System::loadLibrary` and `System::load` to load libraries specified via the `-l` option. This is suboptimal, as in the most common case, such libraries will be installed using e.g. `apt`, in which case `System::load/loadLibrary` is of little use, as it cannot find libraries in path known to the dynamic linker.
>
> This patch changes the default for library loading to use `SymbolLookup::libraryLookup` instead. That is, in absence of any other options, each library provided via `-l` will create a new `SymbolLookup::loaderLookup`, associated with the library arena.
>
> The `-l` option also supports a new disambiguation mechanism, borrowed from the gcc linker options - that is, if the library name starts with `:`, what follows is parsed as a path. Otherwise, we assume it's a library name, and we add prefix/suffix, using `System::mapLibraryName` before creating the lookup.
>
> In cases where the old behavior is preferred (e.g. if libraries to be loaded sit in `java.library.path`) a fallback option has been provided, namely `--use-system-load-library`.
>
> Regardless of the options used, the header class will feature a composite lookup. Inside this lookup we find:
>
> 1. one or more library lookup (one for each `-l` option)
> 2. the loader lookup
> 3. the native linker's default lookup
>
> When `--use-system-load-library` is used, (1) is empty, and a static initializer block with the corresponding calls to `System::load`, `System::loadLibrary` is added instead.
test/jtreg/generator/allocCallback/TestAllocCallback.java line 36:
> 34: * @summary ofAddress factory of function pointer type is wrong for struct returns
> 35: * @library /lib
> 36: * @run main/othervm JtregJextract -l AllocCallback --use-system-load-library -t test.jextract.allocCallback alloc_callback.h
In this (and other) test, we use the `--use-system-load-library` as the build will put the shared libraries in the `java.library.path`, and pass that variable to jtreg.
test/lib/JtregJextract.java line 74:
> 72: }
> 73:
> 74: if ("-libpath".equals(opt)) {
I've removed this, as I think this was a questionable option. I'm not exactly sure what problems this was meant to address, but the only test using this has been rewritten to use other (supported) options instead.
-------------
PR Review Comment: https://git.openjdk.org/jextract/pull/201#discussion_r1482145660
PR Review Comment: https://git.openjdk.org/jextract/pull/201#discussion_r1482147103
More information about the jextract-dev
mailing list