Skip to content

Commit

Permalink
8326891: Prefer RPATH over RUNPATH for $ORIGIN rpaths in internal JDK…
Browse files Browse the repository at this point in the history
… binaries

Backport-of: 721bfee53af5bc2e2d67eebc7b82f09a642d5309
  • Loading branch information
Andrew Lu committed Mar 12, 2024
1 parent 21b88db commit 069fbd7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
10 changes: 8 additions & 2 deletions make/autoconf/flags-cflags.m4
Expand Up @@ -28,7 +28,7 @@
# Setup flags for C/C++ compiler
#

###############################################################################
################################################################################
#
# How to compile shared libraries.
#
Expand All @@ -39,7 +39,10 @@ AC_DEFUN([FLAGS_SETUP_SHARED_LIBS],
# Default works for linux, might work on other platforms as well.
SHARED_LIBRARY_FLAGS='-shared'
SET_EXECUTABLE_ORIGIN='-Wl,-rpath,\$$ORIGIN[$]1'
# --disable-new-dtags forces use of RPATH instead of RUNPATH for rpaths.
# This protects internal library dependencies within the JDK from being
# overridden using LD_LIBRARY_PATH. See JDK-8326891 for more information.
SET_EXECUTABLE_ORIGIN='-Wl,-rpath,\$$ORIGIN[$]1 -Wl,--disable-new-dtags'
SET_SHARED_LIBRARY_ORIGIN="-Wl,-z,origin $SET_EXECUTABLE_ORIGIN"
SET_SHARED_LIBRARY_NAME='-Wl,-soname=[$]1'
SET_SHARED_LIBRARY_MAPFILE='-Wl,-version-script=[$]1'
Expand All @@ -59,6 +62,9 @@ AC_DEFUN([FLAGS_SETUP_SHARED_LIBS],
# Default works for linux, might work on other platforms as well.
SHARED_LIBRARY_FLAGS='-shared'
SET_EXECUTABLE_ORIGIN='-Wl,-rpath,\$$ORIGIN[$]1'
if test "x$OPENJDK_TARGET_OS" = xlinux; then
SET_EXECUTABLE_ORIGIN="$SET_EXECUTABLE_ORIGIN -Wl,--disable-new-dtags"
fi
SET_SHARED_LIBRARY_NAME='-Wl,-soname=[$]1'
SET_SHARED_LIBRARY_MAPFILE='-Wl,-version-script=[$]1'
Expand Down
23 changes: 11 additions & 12 deletions test/jdk/tools/launcher/RunpathTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,7 +24,8 @@
/*
* @test
* @bug 7190813 8022719
* @summary Check for extended RPATHs on *nixes
* @summary Check for extended RPATHs on Linux
* @requires os.family == "linux"
* @compile -XDignore.symbol.file RunpathTest.java
* @run main RunpathTest
* @author ksrini
Expand Down Expand Up @@ -57,25 +58,23 @@ void elfCheck(String javacmd, String expectedRpath) {
final TestResult tr = doExec(elfreaderCmd, "-d", javacmd);
if (!tr.matches(expectedRpath)) {
System.out.println(tr);
throw new RuntimeException("FAILED: RPATH/RUNPATH strings " +
throw new RuntimeException("FAILED: RPATH strings " +
expectedRpath + " not found in " + javaCmd);
}
System.out.println(javacmd + " contains expected RPATHS/RUNPATH");
System.out.println(javacmd + " contains expected RPATHS");
}

void testRpath() {
String expectedRpath = ".*R(UN)?PATH.*\\$ORIGIN/../lib.*";
String expectedRpath = ".*RPATH.*\\$ORIGIN/../lib.*";
elfCheck(javaCmd, expectedRpath);
}

public static void main(String... args) throws Exception {
if (isSolaris || isLinux) {
RunpathTest rp = new RunpathTest();
if (rp.elfreaderCmd == null) {
System.err.println("Warning: test passes vacuously");
return;
}
rp.testRpath();
RunpathTest rp = new RunpathTest();
if (rp.elfreaderCmd == null) {
System.err.println("Warning: test passes vacuously");
return;
}
rp.testRpath();
}
}

1 comment on commit 069fbd7

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.