From 3d27ddde96d08249979968b9aed2ea483b3b31ca Mon Sep 17 00:00:00 2001 From: Kristof Dhondt Date: Fri, 16 Jun 2023 22:07:00 +0200 Subject: [PATCH] consider `ClassLoaderHelper.mapAlternativeName` for all possible paths in System.loadLibrary --- .../svm/core/jdk/NativeLibrarySupport.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/NativeLibrarySupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/NativeLibrarySupport.java index f52a9a060921..16553c39128f 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/NativeLibrarySupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/NativeLibrarySupport.java @@ -120,22 +120,29 @@ public void loadLibraryRelative(String name) { usrPaths = tokens; } String libname = System.mapLibraryName(name); - if (sysPath != null && loadLibrary0(new File(sysPath, libname), false)) { + if (sysPath != null && loadLibraryFromPath(sysPath, libname)) { return; } for (String path : usrPaths) { - File libpath = new File(path, libname); - if (loadLibrary0(libpath, false)) { - return; - } - File altpath = Target_jdk_internal_loader_ClassLoaderHelper.mapAlternativeName(libpath); - if (altpath != null && loadLibrary0(altpath, false)) { + if (loadLibraryFromPath(path, libname)) { return; } } throw new UnsatisfiedLinkError("no " + name + " in java.library.path"); } + private boolean loadLibraryFromPath(String path, String libname) { + File libpath = new File(path, libname); + if (loadLibrary0(libpath, false)) { + return true; + } + File altpath = Target_jdk_internal_loader_ClassLoaderHelper.mapAlternativeName(libpath); + if (altpath != null && loadLibrary0(altpath, false)) { + return true; + } + return false; + } + /** Returns the directory containing the native image, or {@code null}. */ @NeverInline("Reads the return address.") private static String getImageDirectory() {