RFR: 8319516: AIX System::loadLibrary needs support to load a shared library from an archive object [v22]

Jaikiran Pai jpai at openjdk.org
Thu Apr 11 10:49:48 UTC 2024


On Wed, 10 Apr 2024 16:46:30 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:
> 
>   Files copy method

Hello Martin,

> Maybe using that directory is easier. Does anybody else have a suggestion?

Each jtreg test, when it is run, will be run in a "scratch" directory. Details about that are explained here https://openjdk.org/jtreg/faq.html#scratch-directory. That directory can be used to create test specific content.

As for the test, I think what you will need is something like this (I don't know or have access to AIX, so this obviously isn't tested)


import java.nio.file.Files;
import java.nio.file.Path;

import jdk.test.lib.process.ProcessTools;

/**
 * @test
 * @bug 8319516
 * @summary verify that System.loadLibrary on AIX is able to load libraries from ".a" (archive) file
 * @requires os.family == "aix"
 * @library /test/lib/
 * @build jdk.test.lib.process.ProcessTools
 * @run driver AIXLoadLibraryDriver
 */
public class AIXLoadLibraryDriver {

    private static final String TEST_LIBRARY_NAME = "foobar";

    // creates a ".a" archive file in a test specific directory and then
    // launches a java application passing this directory through "-Djava.library.path".
    // the java application then attempts to load the library using System.loadLibrary()
    public static void main(final String[] args) throws Exception {
        final String javaHome = System.getProperty("java.home");
        final Path libawtSo = Path.of(javaHome).resolve("lib", "libawt.so");
        if (!Files.exists(libawtSo)) {
            throw new AssertionError(libawtSo + " is missing");
        }
        final String archiveFileName = "lib" + TEST_LIBRARY_NAME + ".a";
        // copy over libawt.so as an archive file to test specific scratch dir
        final Path testNativeLibDir = Path.of("native").toAbsolutePath();
        Files.createDirectories(testNativeLibDir);
        final Path libDummyArchive = testNativeLibDir.resolve(archiveFileName);
        Files.copy(libawtSo, libDummyArchive);

        // launch a java application which calls System.loadLibrary and is passed
        // the directory containing the native library archive file, through
        // -Djava.library.path
        System.out.println("Launching application with library path " + testNativeLibDir);
        final ProcessBuilder processBuilder = ProcessTools.createTestJavaProcessBuilder(
                "-Djava.library.path=" + testNativeLibDir,
                AIXLoadLibraryDriver.LoadLibraryApp.class.getName());
        ProcessTools.executeCommand(processBuilder).shouldHaveExitValue(0);
    }

    static class LoadLibraryApp {
        public static void main(final String[] args) throws Exception {
            System.out.println("attempting to load library " + TEST_LIBRARY_NAME);
            System.loadLibrary(TEST_LIBRARY_NAME);
            System.out.println(TEST_LIBRARY_NAME + " successfully loaded");
        }
    }
}

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

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


More information about the core-libs-dev mailing list