RFR: JDK-8319516 - Native library suffix impact on the library loading in AIX- Java Class Loader [v4]

Martin Doerr mdoerr at openjdk.org
Fri Mar 22 16:56:29 UTC 2024


On Mon, 18 Mar 2024 17:43:45 GMT, Suchismith Roy <sroy at openjdk.org> wrote:

>> Allow support for both .a and .so files in AIX.
>> If .so file is not found, allow fallback to .a extension.
>> JBS Issue: [JDK-8319516](https://bugs.openjdk.org/browse/JDK-8319516)
>
> Suchismith Roy has updated the pull request incrementally with one additional commit since the last revision:
> 
>   trraling spaces

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.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/17945#issuecomment-2015506765


More information about the core-libs-dev mailing list