@@ -32,6 +32,10 @@ Major new features:
the dynamic loader ignore empty and relative DT_RPATH and DT_RUNPATH
entries, which are resolved against the current working directory.
+* A new tunable, glibc.rtld.require_relro, makes the dynamic loader refuse
+ to load programs and shared objects without RELRO (partial), or without
+ RELRO and immediate binding (full).
+
Deprecated and removed features, and other changes affecting compatibility:
* The posix_spawn_file_actions_addchdir and posix_spawn_file_actions_addfchdir
@@ -702,9 +702,20 @@ tests += \
tst-rtld-relative-rpath \
tst-rtld-relative-rpath-default \
tst-rtld-relative-rpath-needed \
+ tst-rtld-relro-lazy \
+ tst-rtld-relro-needed \
+ tst-rtld-relro-norelro \
+ tst-rtld-relro-preload \
+ tst-rtld-relro-preload-default \
tst-rtld-wx-segments \
tst-rtld-wx-segments-needed \
# tests
+# These use the glibc.rtld.require_relro enum from dl-tunables.h.
+tests-internal += \
+ tst-rtld-relro \
+ tst-rtld-relro-default \
+ tst-rtld-relro-full \
+ # tests-internal
tst-rtld-relative-rpath-needed-helpers = \
tst-rtld-relative-rpath-needed-rpath \
tst-rtld-relative-rpath-needed-runpath \
@@ -714,8 +725,18 @@ modules-names += \
tst-rtld-bind-now-mod \
tst-rtld-relative-rpath-lib \
tst-rtld-relative-rpath-mod \
+ tst-rtld-relro-mod-lazy \
+ tst-rtld-relro-mod-norelro \
+ tst-rtld-relro-mod-now \
tst-rtld-wx-segments-mod \
# modules-names
+ifeq ($(run-built-tests),yes)
+tests-special += \
+ $(objpfx)tst-rtld-relro-lazy-deny.out \
+ $(objpfx)tst-rtld-relro-needed-deny.out \
+ $(objpfx)tst-rtld-relro-norelro-deny.out \
+ # tests-special
+endif
ifeq ($(have-dt-relr),yes)
tests += \
tst-relr \
@@ -2415,6 +2436,58 @@ $(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-rtld-relro-mod-lazy.so += -Wl,-z,relro,-z,lazy
+LDFLAGS-tst-rtld-relro-mod-norelro.so += -Wl,-z,norelro,-z,lazy
+LDFLAGS-tst-rtld-relro-mod-now.so += -Wl,-z,relro,-z,now
+tst-rtld-relro-modules = \
+ $(patsubst %,$(objpfx)tst-rtld-relro-mod-%.so,lazy norelro now)
+$(objpfx)tst-rtld-relro.out: $(tst-rtld-relro-modules)
+$(objpfx)tst-rtld-relro-default.out: $(tst-rtld-relro-modules)
+$(objpfx)tst-rtld-relro-full.out: $(tst-rtld-relro-modules)
+tst-rtld-relro-TUNABLES = glibc.rtld.require_relro=partial
+$(objpfx)tst-rtld-relro-needed: $(objpfx)tst-rtld-relro-mod-norelro.so
+$(objpfx)tst-rtld-relro-preload.out: $(objpfx)tst-rtld-relro-mod-norelro.so
+$(objpfx)tst-rtld-relro-preload-default.out: \
+ $(objpfx)tst-rtld-relro-mod-norelro.so
+tst-rtld-relro-preload-ENV = LD_PRELOAD=$(objpfx)tst-rtld-relro-mod-norelro.so
+tst-rtld-relro-preload-TUNABLES = glibc.rtld.require_relro=partial
+tst-rtld-relro-preload-default-ENV = \
+ LD_PRELOAD=$(objpfx)tst-rtld-relro-mod-norelro.so
+LDFLAGS-tst-rtld-relro-full += -Wl,-z,now
+LDFLAGS-tst-rtld-relro-lazy += -Wl,-z,lazy
+# $(relro-LDFLAGS) comes after LDFLAGS-*, but before LDLIBS-*.
+LDLIBS-tst-rtld-relro-norelro = -Wl,-z,norelro,-z,lazy
+
+$(objpfx)tst-rtld-relro-lazy-deny.out: $(objpfx)tst-rtld-relro-lazy
+ $(test-program-cmd-before-env) \
+ $(run-program-env) \
+ GLIBC_TUNABLES=glibc.rtld.require_relro=full \
+ $(test-program-cmd-after-env) $< \
+ > $@ 2>&1; echo "status: $$?" >> $@; \
+ grep -q ': full RELRO is required$$' $@ \
+ && grep -q '^status: 127$$' $@; \
+ $(evaluate-test)
+
+$(objpfx)tst-rtld-relro-needed-deny.out: $(objpfx)tst-rtld-relro-needed
+ $(test-program-cmd-before-env) \
+ $(run-program-env) \
+ GLIBC_TUNABLES=glibc.rtld.require_relro=partial \
+ $(test-program-cmd-after-env) $< \
+ > $@ 2>&1; echo "status: $$?" >> $@; \
+ grep -q 'tst-rtld-relro-mod-norelro.so: RELRO is required$$' $@ \
+ && grep -q '^status: 127$$' $@; \
+ $(evaluate-test)
+
+$(objpfx)tst-rtld-relro-norelro-deny.out: $(objpfx)tst-rtld-relro-norelro
+ $(test-program-cmd-before-env) \
+ $(run-program-env) \
+ GLIBC_TUNABLES=glibc.rtld.require_relro=partial \
+ $(test-program-cmd-after-env) $< \
+ > $@ 2>&1; echo "status: $$?" >> $@; \
+ grep -q ': RELRO is required$$' $@ \
+ && grep -q '^status: 127$$' $@; \
+ $(evaluate-test)
+
LDFLAGS-tst-array2 = -Wl,--no-as-needed
LDFLAGS-tst-array5 = -Wl,--no-as-needed
@@ -1327,6 +1327,25 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
goto lose;
}
+ /* The GOT entries used by the PLT are only covered by RELRO if the
+ object was linked for immediate binding. */
+ TUNABLE_VALUE_TYPE (glibc, rtld, require_relro) relro
+ = TUNABLE_GET (glibc, rtld, require_relro, int32_t, NULL);
+ if (__glibc_unlikely (relro
+ != TUNABLE_VALUE (glibc, rtld, require_relro, none))
+ && l->l_relro_size == 0)
+ {
+ errstring = N_("RELRO is required");
+ goto lose;
+ }
+ if (__glibc_unlikely (relro
+ == TUNABLE_VALUE (glibc, rtld, require_relro, full))
+ && l->l_info[DT_BIND_NOW] == NULL)
+ {
+ errstring = N_("full RELRO is required");
+ goto lose;
+ }
+
if (l->l_phdr == NULL)
{
/* The program header is not contained in any of the segments.
@@ -147,6 +147,13 @@ glibc {
maxval: 1
default: 0
}
+ require_relro {
+ type: INT_32
+ minval: 0
+ maxval: 2
+ default: 0
+ values: none partial full
+ }
}
mem {
@@ -1276,6 +1276,15 @@ Fatal glibc error: text relocations are not allowed\n");
&& (ph->p_flags & (PF_W | PF_X)) == (PF_W | PF_X))
_dl_fatal_printf ("\
Fatal glibc error: writable and executable segments are not allowed\n");
+
+ TUNABLE_VALUE_TYPE (glibc, rtld, require_relro) relro
+ = TUNABLE_GET (glibc, rtld, require_relro, int32_t, NULL);
+ if (relro != TUNABLE_VALUE (glibc, rtld, require_relro, none)
+ && main_map->l_relro_size == 0)
+ _dl_fatal_printf ("Fatal glibc error: RELRO is required\n");
+ if (relro == TUNABLE_VALUE (glibc, rtld, require_relro, full)
+ && main_map->l_info[DT_BIND_NOW] == NULL)
+ _dl_fatal_printf ("Fatal glibc error: full RELRO is required\n");
}
/* Set up the program header information for the dynamic linker
@@ -20,3 +20,4 @@ glibc.rtld.optional_static_tls: 0x200 (min: 0x0, max: 0x[f]+)
glibc.rtld.refuse_rwx_segments: 0 (min: 0, max: 1)
glibc.rtld.refuse_textrel: 0 (min: 0, max: 1)
glibc.rtld.require_pie: 0 (min: 0, max: 1)
+glibc.rtld.require_relro: none (values: none, partial, full)
new file mode 100644
@@ -0,0 +1,20 @@
+/* Test that RELRO is not required 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 RELRO_LEVEL none
+#include "tst-rtld-relro.c"
new file mode 100644
@@ -0,0 +1,110 @@
+/* Test glibc.rtld.require_relro=full with dlopen.
+ 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 <getopt.h>
+#include <stdlib.h>
+#include <support/capture_subprocess.h>
+#include <support/subprocess.h>
+#include <support/support.h>
+#include <sys/auxv.h>
+
+#define RELRO_CHECK_MODULES_ONLY
+#include "tst-rtld-relro.c"
+
+static int restart;
+#define CMDLINE_OPTIONS \
+ { "restart", no_argument, &restart, 1 },
+
+static ElfW(Addr) vdso;
+
+/* Count the loaded objects, other than the vDSO (which the loader does not
+ check), that are not linked with full RELRO. */
+static int
+count_partial_relro (struct dl_phdr_info *info, size_t size, void *closure)
+{
+ int *count = closure;
+
+ for (ElfW(Half) i = 0; i < info->dlpi_phnum; i++)
+ {
+ const ElfW(Phdr) *ph = &info->dlpi_phdr[i];
+ if (vdso != 0
+ && ph->p_type == PT_LOAD
+ && vdso >= info->dlpi_addr + ph->p_vaddr
+ && vdso - (info->dlpi_addr + ph->p_vaddr) < ph->p_memsz)
+ return 0;
+ }
+
+ bool relro, now;
+ get_relro_info (info, &relro, &now);
+ if (!relro || !now)
+ {
+ printf ("info: %s is not linked with full RELRO\n",
+ info->dlpi_name[0] != '\0' ? info->dlpi_name : "<main program>");
+ ++*count;
+ }
+
+ return 0;
+}
+
+static int
+do_test (void)
+{
+ if (restart)
+ {
+ check_modules (TUNABLE_VALUE (glibc, rtld, require_relro, full));
+ return 0;
+ }
+
+ vdso = getauxval (AT_SYSINFO_EHDR);
+
+ /* The respawned test can only start if every object it uses is linked
+ with full RELRO, which depends on how glibc and the toolchain libraries
+ (such as libgcc_s on ARM) were built. */
+ int count = 0;
+ dl_iterate_phdr (count_partial_relro, &count);
+ if (count != 0)
+ FAIL_UNSUPPORTED ("loaded objects are not linked with full RELRO");
+
+ /* Run the test again with the tunable set, under the built loader. */
+ char *program = xasprintf ("%s/elf/tst-rtld-relro-full",
+ support_objdir_root);
+ char *args[] =
+ {
+ program, (char *) "--direct",
+ (char *) "--restart",
+ NULL
+ };
+ char *env[] =
+ {
+ (char *) "GLIBC_TUNABLES=glibc.rtld.require_relro=full",
+ NULL
+ };
+ struct support_spawn_wrapped *w = support_spawn_wrap (program, args, env, 0);
+ struct support_capture_subprocess result
+ = support_capture_subprogram (w->path, w->argv, w->envp);
+ support_spawn_wrapped_free (w);
+ support_capture_subprocess_check (&result, "tst-rtld-relro-full", 0,
+ sc_allow_stdout);
+ fputs (result.out.buffer, stdout);
+ support_capture_subprocess_free (&result);
+ free (program);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
new file mode 100644
@@ -0,0 +1,28 @@
+/* Main program with RELRO and lazy binding, for glibc.rtld.require_relro.
+ 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-relro.h"
+
+static int
+do_test (void)
+{
+ check_relro_info ("", true, false);
+ return 0;
+}
+
+#include <support/test-driver.c>
new file mode 100644
@@ -0,0 +1,23 @@
+/* Shared object for tst-rtld-relro, linked with -z relro -z lazy.
+ 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_relro_value (void)
+{
+ return 42;
+}
new file mode 100644
@@ -0,0 +1,19 @@
+/* Shared object for tst-rtld-relro, linked with -z norelro.
+ 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-relro-mod-lazy.c"
new file mode 100644
@@ -0,0 +1,19 @@
+/* Shared object for tst-rtld-relro, linked with -z relro -z now.
+ 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-relro-mod-lazy.c"
new file mode 100644
@@ -0,0 +1,33 @@
+/* Test a program with a dependency without RELRO.
+ 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 <support/check.h>
+
+/* tst-rtld-relro-mod-norelro.so is a DT_NEEDED dependency of this program,
+ so it does not start with glibc.rtld.require_relro=partial, which
+ tst-rtld-relro-needed-deny checks. */
+int tst_rtld_relro_value (void);
+
+static int
+do_test (void)
+{
+ TEST_COMPARE (tst_rtld_relro_value (), 42);
+ return 0;
+}
+
+#include <support/test-driver.c>
new file mode 100644
@@ -0,0 +1,28 @@
+/* Main program without RELRO, used to test glibc.rtld.require_relro.
+ 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-relro.h"
+
+static int
+do_test (void)
+{
+ check_relro_info ("", false, false);
+ return 0;
+}
+
+#include <support/test-driver.c>
new file mode 100644
@@ -0,0 +1,20 @@
+/* Test that LD_PRELOAD of an object without RELRO works 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 RELRO_REQUIRED 0
+#include "tst-rtld-relro-preload.c"
new file mode 100644
@@ -0,0 +1,44 @@
+/* Test LD_PRELOAD of a shared object without RELRO.
+ 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>
+#include <support/check.h>
+#include <support/xdlfcn.h>
+
+/* Both tests run with LD_PRELOAD=tst-rtld-relro-mod-norelro.so.
+ tst-rtld-relro-preload also sets glibc.rtld.require_relro=partial, so
+ the preloaded object is ignored, and tst-rtld-relro-preload-default
+ checks that it is loaded otherwise. */
+#ifndef RELRO_REQUIRED
+# define RELRO_REQUIRED 1
+#endif
+
+static int
+do_test (void)
+{
+#if RELRO_REQUIRED
+ TEST_VERIFY (dlsym (RTLD_DEFAULT, "tst_rtld_relro_value") == NULL);
+#else
+ int (*value) (void) = xdlsym (RTLD_DEFAULT, "tst_rtld_relro_value");
+ TEST_COMPARE (value (), 42);
+#endif
+
+ return 0;
+}
+
+#include <support/test-driver.c>
new file mode 100644
@@ -0,0 +1,96 @@
+/* Test the glibc.rtld.require_relro tunable with dlopen.
+ 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 <support/xdlfcn.h>
+
+#include "dl-tunables.h"
+#include "tst-rtld-relro.h"
+
+static const struct
+{
+ const char *name;
+ bool relro;
+ bool now;
+} modules[] =
+{
+ { "tst-rtld-relro-mod-norelro.so", false, false },
+ { "tst-rtld-relro-mod-lazy.so", true, false },
+ { "tst-rtld-relro-mod-now.so", true, true },
+};
+
+/* Check dlopen of the modules with glibc.rtld.require_relro set to
+ LEVEL. */
+static void
+check_modules (TUNABLE_VALUE_TYPE (glibc, rtld, require_relro) level)
+{
+ for (size_t i = 0; i < array_length (modules); i++)
+ {
+ const char *name = modules[i].name;
+ /* The error with which LEVEL rejects the module, if any. */
+ const char *error = NULL;
+ if (level != TUNABLE_VALUE (glibc, rtld, require_relro, none)
+ && !modules[i].relro)
+ error = ": RELRO is required";
+ else if (level == TUNABLE_VALUE (glibc, rtld, require_relro, full)
+ && !modules[i].now)
+ error = ": full RELRO is required";
+
+ void *h = dlopen (name, RTLD_NOW);
+ if (error != NULL)
+ {
+ if (h != NULL)
+ FAIL_EXIT1 ("dlopen (\"%s\") succeeded", name);
+ const char *err = dlerror ();
+ printf ("info: dlopen (\"%s\"): %s\n", name, err);
+ TEST_VERIFY (strstr (err, error) != NULL);
+ }
+ else
+ {
+ if (h == NULL)
+ FAIL_EXIT1 ("dlopen (\"%s\"): %s", name, dlerror ());
+
+ /* Check that the module was linked as expected. */
+ struct link_map *l;
+ TEST_COMPARE (dlinfo (h, RTLD_DI_LINKMAP, &l), 0);
+ check_relro_info (l->l_name, modules[i].relro, modules[i].now);
+
+ int (*value) (void) = xdlsym (h, "tst_rtld_relro_value");
+ TEST_COMPARE (value (), 42);
+ xdlclose (h);
+ }
+ }
+}
+
+#ifndef RELRO_CHECK_MODULES_ONLY
+
+# ifndef RELRO_LEVEL
+# define RELRO_LEVEL partial
+# endif
+
+static int
+do_test (void)
+{
+ check_modules (TUNABLE_VALUE (glibc, rtld, require_relro, RELRO_LEVEL));
+ return 0;
+}
+
+# include <support/test-driver.c>
+#endif
new file mode 100644
@@ -0,0 +1,78 @@
+/* Helpers to inspect the RELRO properties of loaded objects.
+ 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 <link.h>
+#include <stdbool.h>
+#include <string.h>
+#include <support/check.h>
+
+struct relro_info
+{
+ const char *name;
+ bool found;
+ /* Whether the object has a PT_GNU_RELRO segment. */
+ bool relro;
+ /* Whether the object was linked for immediate binding. */
+ bool now;
+};
+
+/* Set *RELRO and *NOW to the RELRO properties of the object INFO. */
+static void
+get_relro_info (const struct dl_phdr_info *info, bool *relro, bool *now)
+{
+ *relro = false;
+ *now = false;
+ for (ElfW(Half) i = 0; i < info->dlpi_phnum; i++)
+ {
+ const ElfW(Phdr) *ph = &info->dlpi_phdr[i];
+ if (ph->p_type == PT_GNU_RELRO)
+ *relro = true;
+ else if (ph->p_type == PT_DYNAMIC)
+ for (const ElfW(Dyn) *d
+ = (const ElfW(Dyn) *) (info->dlpi_addr + ph->p_vaddr);
+ d->d_tag != DT_NULL; d++)
+ if (d->d_tag == DT_BIND_NOW
+ || (d->d_tag == DT_FLAGS && (d->d_un.d_val & DF_BIND_NOW) != 0)
+ || (d->d_tag == DT_FLAGS_1 && (d->d_un.d_val & DF_1_NOW) != 0))
+ *now = true;
+ }
+}
+
+static int
+relro_info_callback (struct dl_phdr_info *info, size_t size, void *closure)
+{
+ struct relro_info *ri = closure;
+
+ if (strcmp (info->dlpi_name, ri->name) != 0)
+ return 0;
+
+ ri->found = true;
+ get_relro_info (info, &ri->relro, &ri->now);
+ return 1;
+}
+
+/* Check that the object NAME has the expected RELRO properties. */
+static void
+check_relro_info (const char *name, bool relro, bool now)
+{
+ struct relro_info ri = { .name = name };
+ dl_iterate_phdr (relro_info_callback, &ri);
+ TEST_VERIFY_EXIT (ri.found);
+ TEST_COMPARE (ri.relro, relro);
+ TEST_COMPARE (ri.now, now);
+}
@@ -555,6 +555,27 @@ The default value of this tunable is @samp{0}, which uses empty and
relative entries.
@end deftp
+@deftp Tunable glibc.rtld.require_relro
+Setting the @code{glibc.rtld.require_relro} tunable to @code{partial}
+makes the dynamic loader refuse to load programs and shared objects
+without a @code{PT_GNU_RELRO} segment, and setting it to @code{full} also
+refuses those that are not linked for immediate binding (with the
+@code{DF_BIND_NOW} or @code{DF_1_NOW} flags). The main program fails to
+start, and @code{dlopen} of such a shared object fails. Note that
+@theglibc{} only builds its own shared objects for immediate binding when
+configured with @option{--enable-bind-now}; otherwise the value
+@code{full} prevents every dynamically linked program from running.
+
+Other shared objects must be linked for immediate binding as well, and
+the compiler runtime libraries often are not. With @code{full},
+@code{pthread_exit} and @code{pthread_cancel} then abort the process
+because they cannot load @file{libgcc_s.so.1}, and C++ programs that use
+@file{libstdc++.so.6} fail to start.
+
+The default value of this tunable is @samp{none}, which does not require
+RELRO. Other values, including numbers, are ignored.
+@end deftp
+
@node POSIX Thread Tunables
@section POSIX Thread Tunables
@cindex pthread mutex tunables