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 a22ac46 commit 0606e5a
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Setup flags for C/C++ compiler
#

###############################################################################
################################################################################
#
# How to compile shared libraries.
#
Expand All @@ -37,7 +37,10 @@ AC_DEFUN([FLAGS_SETUP_SHARED_LIBS],
if test "x$TOOLCHAIN_TYPE" = xgcc; then
# 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 @@ -55,6 +58,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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, 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 (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();
}
}

0 comments on commit 0606e5a

Please sign in to comment.