@@ -28,6 +28,10 @@ Major new features:
LD_BIND_NOW environment variable. When set in /etc/tunables.conf, it
also applies to AT_SECURE processes.
+* A new tunable, glibc.rtld.ignore_relative_rpath, can be set to 1 to make
+ the dynamic loader ignore empty and relative DT_RPATH and DT_RUNPATH
+ entries, which are resolved against the current working directory.
+
Deprecated and removed features, and other changes affecting compatibility:
* The posix_spawn_file_actions_addchdir and posix_spawn_file_actions_addfchdir
@@ -699,11 +699,21 @@ tests += \
tst-rtld-bind-now-default \
tst-rtld-bind-now-needed \
tst-rtld-bind-now-profile \
+ tst-rtld-relative-rpath \
+ tst-rtld-relative-rpath-default \
+ tst-rtld-relative-rpath-needed \
tst-rtld-wx-segments \
tst-rtld-wx-segments-needed \
# tests
+tst-rtld-relative-rpath-needed-helpers = \
+ tst-rtld-relative-rpath-needed-rpath \
+ tst-rtld-relative-rpath-needed-runpath \
+ # tst-rtld-relative-rpath-needed-helpers
+test-srcs += $(tst-rtld-relative-rpath-needed-helpers)
modules-names += \
tst-rtld-bind-now-mod \
+ tst-rtld-relative-rpath-lib \
+ tst-rtld-relative-rpath-mod \
tst-rtld-wx-segments-mod \
# modules-names
ifeq ($(have-dt-relr),yes)
@@ -2374,6 +2384,37 @@ tst-rtld-bind-now-profile-TUNABLES = glibc.rtld.bind_now=1
tst-rtld-bind-now-profile-ENV = \
LD_PROFILE=tst-rtld-bind-now-mod.so LD_PROFILE_OUTPUT=$(objpfx)
+LDFLAGS-tst-rtld-relative-rpath-mod.so += \
+ -Wl,--enable-new-dtags,-rpath,tst-rtld-relative-rpath-dir::/nonexistent
+# The helpers of tst-rtld-relative-rpath-needed depend on the soname, which
+# is only found through their relative search path entry.
+LDFLAGS-tst-rtld-relative-rpath-lib.so += \
+ -Wl,-soname,libtst-rtld-relative-rpath.so
+LDFLAGS-tst-rtld-relative-rpath-needed-runpath += \
+ -Wl,--enable-new-dtags,-rpath,tst-rtld-relative-rpath-dir
+LDFLAGS-tst-rtld-relative-rpath-needed-rpath += \
+ -Wl,--disable-new-dtags,-rpath,tst-rtld-relative-rpath-dir
+ifeq (yes,$(build-hardcoded-path-in-tests))
+# The build directories are added with -Wl,--disable-new-dtags after the
+# LDFLAGS, which would turn the DT_RUNPATH of these objects into DT_RPATH.
+$(objpfx)tst-rtld-relative-rpath-mod.so: \
+ link-test-modules-rpath-link = $(link-libc-rpath)
+$(objpfx)tst-rtld-relative-rpath-needed-runpath: \
+ link-libc-tests-rpath-link = $(link-libc-rpath)
+endif
+$(objpfx)tst-rtld-relative-rpath-needed-runpath: \
+ $(objpfx)tst-rtld-relative-rpath-lib.so
+$(objpfx)tst-rtld-relative-rpath-needed-rpath: \
+ $(objpfx)tst-rtld-relative-rpath-lib.so
+$(objpfx)tst-rtld-relative-rpath-needed.out: \
+ $(objpfx)tst-rtld-relative-rpath-needed-runpath \
+ $(objpfx)tst-rtld-relative-rpath-needed-rpath
+$(objpfx)tst-rtld-relative-rpath.out: \
+ $(objpfx)tst-rtld-relative-rpath-mod.so $(objpfx)tst-rtld-relative-rpath-lib.so
+$(objpfx)tst-rtld-relative-rpath-default.out: \
+ $(objpfx)tst-rtld-relative-rpath-mod.so $(objpfx)tst-rtld-relative-rpath-lib.so
+tst-rtld-relative-rpath-TUNABLES = glibc.rtld.ignore_relative_rpath=1
+
LDFLAGS-tst-array2 = -Wl,--no-as-needed
LDFLAGS-tst-array5 = -Wl,--no-as-needed
@@ -392,11 +392,14 @@ struct r_search_path_struct __rtld_search_dirs attribute_relro;
static size_t max_dirnamelen;
/* Tokenize RPATH (in place) and populate RESULT with one entry per non-empty
- directory. Returns false if a per-entry allocation fails, leaving the
- caller responsible for signaling any error. */
+ directory. If ALLOW_RELATIVE is false, skip the empty and relative
+ entries, which are resolved against the current working directory. Returns
+ false if a per-entry allocation fails, leaving the caller responsible for
+ signaling any error. */
static bool
fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
- const char *what, const char *where, struct link_map *l)
+ const char *what, const char *where, struct link_map *l,
+ bool allow_relative)
{
char *cp;
size_t nelems = 0;
@@ -420,7 +423,7 @@ fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
/* Compute the length after dynamic string token expansion and
ignore empty paths. */
len = strlen (cp);
- if (len == 0)
+ if (len == 0 || (!allow_relative && cp[0] != '/'))
{
free (to_free);
continue;
@@ -434,6 +437,8 @@ fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
if (len > 0 && cp[len - 1] != '/')
cp[len++] = '/';
}
+ else if (!allow_relative)
+ continue;
/* See if this directory is already known. */
for (dirp = GL(dl_all_dirs); dirp != NULL; dirp = dirp->next)
@@ -583,7 +588,9 @@ decompose_rpath (struct r_search_path_struct *sps,
_dl_signal_error (ENOMEM, NULL, NULL, errstring);
}
- if (!fillin_rpath (copy, result, ":", what, where, l))
+ if (!fillin_rpath (copy, result, ":", what, where, l,
+ TUNABLE_GET (glibc, rtld, ignore_relative_rpath, int32_t,
+ NULL) == 0))
{
free (copy);
free (result);
@@ -788,7 +795,7 @@ _dl_init_paths (const char *llp, const char *source,
char *llp_tmp = memcpy (scratch.data, llp, llp_len + 1);
bool ok = fillin_rpath (llp_tmp, __rtld_env_path_list.dirs, ":;",
- source, NULL, l);
+ source, NULL, l, true);
dl_scratch_buffer_free (&scratch);
@@ -137,6 +137,12 @@ glibc {
maxval: 1
default: 0
}
+ ignore_relative_rpath {
+ type: INT_32
+ minval: 0
+ maxval: 1
+ default: 0
+ }
}
mem {
@@ -14,6 +14,7 @@ glibc.rtld.bind_now: 0 (min: 0, max: 1)
glibc.rtld.dynamic_sort: 2 (min: 1, max: 2)
glibc.rtld.enable_secure: 0 (min: 0, max: 1)
glibc.rtld.execstack: 1 (min: 0, max: 2)
+glibc.rtld.ignore_relative_rpath: 0 (min: 0, max: 1)
glibc.rtld.nns: 0x4 (min: 0x1, max: 0x10)
glibc.rtld.optional_static_tls: 0x200 (min: 0x0, max: 0x[f]+)
glibc.rtld.refuse_rwx_segments: 0 (min: 0, max: 1)
new file mode 100644
@@ -0,0 +1,20 @@
+/* Test that empty and relative RUNPATH entries are used by default.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#define RELATIVE_ALLOWED 1
+#include "tst-rtld-relative-rpath.c"
new file mode 100644
@@ -0,0 +1,23 @@
+/* Shared object found through relative RUNPATH entries.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+int
+tst_rtld_relative_rpath_value (void)
+{
+ return 42;
+}
new file mode 100644
@@ -0,0 +1,33 @@
+/* Shared object with relative RUNPATH entries for tst-rtld-relative-rpath.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <dlfcn.h>
+
+int tst_rtld_relative_rpath_dummy;
+
+/* dlopen uses the search path of the calling object. */
+void *
+tst_rtld_relative_rpath_open (const char *name)
+{
+ void *h = dlopen (name, RTLD_NOW);
+
+ /* Ensure this is not a tail call, otherwise the caller of this function
+ would be used. */
+ ++tst_rtld_relative_rpath_dummy;
+ return h;
+}
new file mode 100644
@@ -0,0 +1,19 @@
+/* Program with a relative DT_RPATH for tst-rtld-relative-rpath-needed.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include "tst-rtld-relative-rpath-needed-runpath.c"
new file mode 100644
@@ -0,0 +1,25 @@
+/* Program with a relative DT_RUNPATH for tst-rtld-relative-rpath-needed.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+int tst_rtld_relative_rpath_value (void);
+
+int
+main (void)
+{
+ return tst_rtld_relative_rpath_value () == 42 ? 0 : 1;
+}
new file mode 100644
@@ -0,0 +1,81 @@
+/* Test glibc.rtld.ignore_relative_rpath with the main program search path.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <array_length.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <support/capture_subprocess.h>
+#include <support/check.h>
+#include <support/subprocess.h>
+#include <support/support.h>
+
+#include "tst-rtld-relative-rpath-needed.h"
+
+static void
+prepare (int argc, char **argv)
+{
+ create_relative_rpath_dir ("tst-rtld-relative-rpath-needed-");
+}
+
+static void
+check_program (const char *program, const char *tunables)
+{
+ char *path = xasprintf ("%s/elf/%s", support_objdir_root, program);
+ char *args[] = { path, NULL };
+ char *env[] = { (char *) tunables, NULL };
+
+ printf ("info: running %s %s\n", program, tunables ?: "");
+ struct support_spawn_wrapped *w = support_spawn_wrap (path, args, env, 0);
+ struct support_capture_subprocess result
+ = support_capture_subprogram (w->path, w->argv, w->envp);
+ support_spawn_wrapped_free (w);
+ if (tunables == NULL)
+ support_capture_subprocess_check (&result, program, 0, sc_allow_none);
+ else
+ {
+ support_capture_subprocess_check (&result, program, 127,
+ sc_allow_stderr);
+ printf ("info: stderr: %s", result.err.buffer);
+ TEST_VERIFY (strstr (result.err.buffer,
+ LIB ": cannot open shared object file") != NULL);
+ }
+ support_capture_subprocess_free (&result);
+ free (path);
+}
+
+static int
+do_test (void)
+{
+ static const char *const programs[] =
+ {
+ "tst-rtld-relative-rpath-needed-runpath",
+ "tst-rtld-relative-rpath-needed-rpath",
+ };
+ for (size_t i = 0; i < array_length (programs); i++)
+ {
+ check_program (programs[i], NULL);
+ check_program (programs[i],
+ "GLIBC_TUNABLES=glibc.rtld.ignore_relative_rpath=1");
+ }
+
+ return 0;
+}
+
+#define PREPARE prepare
+#include <support/test-driver.c>
new file mode 100644
@@ -0,0 +1,54 @@
+/* Directory for the programs with a relative search path.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <stdlib.h>
+#include <support/support.h>
+#include <support/temp_file.h>
+#include <support/xunistd.h>
+
+/* The helper programs have the relative DT_RUNPATH or DT_RPATH RELATIVE_DIR,
+ which the dynamic loader resolves against the current directory, and a
+ DT_NEEDED dependency on LIB, the soname of tst-rtld-relative-rpath-lib.so.
+ No file of that name exists in any other search directory, so the programs
+ only start if the relative entry is used. */
+#define RELATIVE_DIR "tst-rtld-relative-rpath-dir"
+#define LIB "libtst-rtld-relative-rpath.so"
+
+/* Create RELATIVE_DIR/LIB in a new temporary directory whose name starts
+ with PREFIX, and make it the current directory. */
+static void
+create_relative_rpath_dir (const char *prefix)
+{
+ char *dir = support_create_temp_directory (prefix);
+ char *lib = xasprintf ("%s/elf/tst-rtld-relative-rpath-lib.so",
+ support_objdir_root);
+
+ char *reldir = xasprintf ("%s/%s", dir, RELATIVE_DIR);
+ xmkdir (reldir, 0700);
+ add_temp_file (reldir);
+ char *link = xasprintf ("%s/%s", reldir, LIB);
+ xsymlink (lib, link);
+ add_temp_file (link);
+
+ xchdir (dir);
+
+ free (link);
+ free (reldir);
+ free (lib);
+ free (dir);
+}
new file mode 100644
@@ -0,0 +1,106 @@
+/* Test the glibc.rtld.ignore_relative_rpath tunable.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <array_length.h>
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <support/check.h>
+#include <support/support.h>
+#include <support/temp_file.h>
+#include <support/xdlfcn.h>
+#include <support/xunistd.h>
+
+/* tst-rtld-relative-rpath runs with glibc.rtld.ignore_relative_rpath=1, and
+ tst-rtld-relative-rpath-default with the default value. */
+#ifndef RELATIVE_ALLOWED
+# define RELATIVE_ALLOWED 0
+#endif
+
+/* tst-rtld-relative-rpath-mod.so has the DT_RUNPATH
+ "tst-rtld-relative-rpath-dir::/nonexistent", a relative entry and an
+ empty one, both resolved against the current directory. Creates a
+ symbolic link to tst-rtld-relative-rpath-lib.so for each of them in a
+ emporary directory, which becomes the current directory:
+
+ RELATIVE_DIR/LIB_RELATIVE found through the relative entry
+ LIB_EMPTY found through the empty entry
+
+ Neither name exists in any other search directory, so each dlopen
+ succeeds only if its entry is used. */
+#define RELATIVE_DIR "tst-rtld-relative-rpath-dir"
+#define LIB_RELATIVE "libtst-rtld-relative-rpath-relative.so"
+#define LIB_EMPTY "libtst-rtld-relative-rpath-empty.so"
+
+static void
+prepare (int argc, char **argv)
+{
+ char *dir = support_create_temp_directory ("tst-rtld-relative-rpath-");
+ char *lib = xasprintf ("%s/elf/tst-rtld-relative-rpath-lib.so",
+ support_objdir_root);
+
+ char *reldir = xasprintf ("%s/%s", dir, RELATIVE_DIR);
+ xmkdir (reldir, 0700);
+ add_temp_file (reldir);
+ char *librel = xasprintf ("%s/%s", reldir, LIB_RELATIVE);
+ xsymlink (lib, librel);
+ add_temp_file (librel);
+ char *libempty = xasprintf ("%s/%s", dir, LIB_EMPTY);
+ xsymlink (lib, libempty);
+ add_temp_file (libempty);
+
+ xchdir (dir);
+
+ free (libempty);
+ free (librel);
+ free (reldir);
+ free (lib);
+ free (dir);
+}
+
+static int
+do_test (void)
+{
+ void *mod = xdlopen ("tst-rtld-relative-rpath-mod.so", RTLD_NOW);
+ void *(*open_lib) (const char *)
+ = xdlsym (mod, "tst_rtld_relative_rpath_open");
+
+ static const char *const names[] = { LIB_RELATIVE, LIB_EMPTY };
+ for (size_t i = 0; i < array_length (names); i++)
+ {
+ void *h = open_lib (names[i]);
+#if RELATIVE_ALLOWED
+ if (h == NULL)
+ FAIL_EXIT1 ("dlopen (\"%s\"): %s", names[i], dlerror ());
+ int (*value) (void) = xdlsym (h, "tst_rtld_relative_rpath_value");
+ TEST_COMPARE (value (), 42);
+ xdlclose (h);
+#else
+ if (h != NULL)
+ FAIL_EXIT1 ("dlopen (\"%s\") succeeded", names[i]);
+ printf ("info: dlopen (\"%s\"): %s\n", names[i], dlerror ());
+#endif
+ }
+
+ xdlclose (mod);
+
+ return 0;
+}
+
+#define PREPARE prepare
+#include <support/test-driver.c>
@@ -540,6 +540,21 @@ The default value of this tunable is @samp{0}, which enables lazy
binding unless the object was linked with @option{-z now}.
@end deftp
+@deftp Tunable glibc.rtld.ignore_relative_rpath
+The @code{DT_RPATH} and @code{DT_RUNPATH} search paths of a program or
+shared object may contain empty entries, or relative directories after
+the expansion of dynamic string tokens such as @code{$ORIGIN}. The
+dynamic loader resolves these against the current working directory of
+the process, so shared objects can be loaded from a directory under the
+control of whoever starts the program. Setting the
+@code{glibc.rtld.ignore_relative_rpath} tunable to @code{1} makes the
+dynamic loader ignore such entries. The @env{LD_LIBRARY_PATH}
+environment variable is not affected.
+
+The default value of this tunable is @samp{0}, which uses empty and
+relative entries.
+@end deftp
+
@node POSIX Thread Tunables
@section POSIX Thread Tunables
@cindex pthread mutex tunables