On Fri, 22 Mar 2024 16:53:58 GMT, Martin Doerr <[email protected]> wrote:
> In case of jextract (jdk22 branch), we would then need something like the
> following if we want AIX to behave like the other platforms?
>
> ```
> diff --git a/src/main/java/org/openjdk/jextract/clang/libclang/Index_h.java
> b/src/main/java/org/openjdk/jextract/clang/libclang/Index_h.java
> index 14eba30..c069c3b 100644
> --- a/src/main/java/org/openjdk/jextract/clang/libclang/Index_h.java
> +++ b/src/main/java/org/openjdk/jextract/clang/libclang/Index_h.java
> @@ -27,11 +27,13 @@
>
> package org.openjdk.jextract.clang.libclang;
>
> +import java.io.File;
> import java.lang.invoke.*;
> import java.lang.foreign.*;
> import java.nio.ByteOrder;
> import java.util.*;
> import java.util.function.*;
> +import java.util.StringTokenizer;
> import java.util.stream.*;
>
> import static java.lang.foreign.ValueLayout.*;
> @@ -101,8 +103,21 @@ public class Index_h {
> }
>
> static {
> - String libName = System.getProperty("os.name").startsWith("Windows")
> ? "libclang" : "clang";
> - System.loadLibrary(libName);
> + String osName = System.getProperty("os.name");
> + String libName = "";
> + if (osName.startsWith("AIX")) {
> + String libPath = System.getProperty("java.library.path");
> + StringTokenizer parser = new StringTokenizer(libPath, ":");
> + while (parser.hasMoreTokens()) {
> + libName = parser.nextToken() + "/libclang.a";
> + File f = new File(libName);
> + if (f.exists() && !f.isDirectory()) break;
> + }
> + SymbolLookup.libraryLookup(libName + "(libclang.so.16)",
> Arena.global());
> + } else {
> + libName = osName.startsWith("Windows") ? "libclang" : "clang";
> + System.loadLibrary(libName);
> + }
> }
>
> static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup()
> ```
>
> If I try this, I get "UnsatisfiedLinkError: unresolved symbol:
> clang_createIndex". So, seems like the lib gets found, but symbols not
> loaded. Seems like there are more changes needed.
Something like that seems good. When you call "find" on that lookup, it should
just forward to dlsym... I suggest you try first to simply use the lookup in a
standalone file (w/o jextract) and try to lookup a symbol in clang (e.g.
`clang_getClangVersion`), and see what happens.
If that doesn't work (likely), I'd suggest to write the equivalent C program
with dlopen/dlsym, and make sure that works, and also note which DLOPEN/DLSYM
parameters are used (maybe those are different from the ones used by the JDK?).
-------------
PR Comment: https://git.openjdk.org/jdk/pull/17945#issuecomment-2015773691