@@ -24,6 +24,10 @@ Major new features:
the dynamic loader refuse to load programs and shared objects with a
loadable segment that is both writable and executable.
+* A new tunable, glibc.rtld.bind_now, disables lazy binding like the
+ LD_BIND_NOW environment variable. When set in /etc/tunables.conf, it
+ also applies to AT_SECURE processes.
+
Deprecated and removed features, and other changes affecting compatibility:
* The posix_spawn_file_actions_addchdir and posix_spawn_file_actions_addfchdir
@@ -689,11 +689,21 @@ modules-names += \
tst-rtld-textrel-mod \
# modules-names
endif
+ifeq ($(run-built-tests),yes)
+tests-special += \
+ $(objpfx)tst-rtld-bind-now-needed-deny.out \
+ # tests-special
+endif
tests += \
+ tst-rtld-bind-now \
+ tst-rtld-bind-now-default \
+ tst-rtld-bind-now-needed \
+ tst-rtld-bind-now-profile \
tst-rtld-wx-segments \
tst-rtld-wx-segments-needed \
# tests
modules-names += \
+ tst-rtld-bind-now-mod \
tst-rtld-wx-segments-mod \
# modules-names
ifeq ($(have-dt-relr),yes)
@@ -2343,6 +2353,27 @@ ifeq ($(have-no-error-rwx-segments),yes)
LDFLAGS-tst-rtld-wx-segments-mod.so += -Wl,--no-error-rwx-segments
endif
+LDFLAGS-tst-rtld-bind-now-mod.so += -Wl,-z,lazy
+tst-rtld-bind-now-mod.so-no-z-defs = yes
+$(objpfx)tst-rtld-bind-now-needed: $(objpfx)tst-rtld-bind-now-mod.so
+LDFLAGS-tst-rtld-bind-now-needed += -Wl,--allow-shlib-undefined
+$(objpfx)tst-rtld-bind-now-needed-deny.out: $(objpfx)tst-rtld-bind-now-needed
+ $(test-program-cmd-before-env) \
+ $(run-program-env) \
+ GLIBC_TUNABLES=glibc.rtld.bind_now=1 \
+ $(test-program-cmd-after-env) $< \
+ > $@ 2>&1; echo "status: $$?" >> $@; \
+ grep -q 'undefined symbol: tst_rtld_bind_now_undefined' $@ \
+ && grep -q '^status: 127$$' $@; \
+ $(evaluate-test)
+$(objpfx)tst-rtld-bind-now.out: $(objpfx)tst-rtld-bind-now-mod.so
+$(objpfx)tst-rtld-bind-now-default.out: $(objpfx)tst-rtld-bind-now-mod.so
+$(objpfx)tst-rtld-bind-now-profile.out: $(objpfx)tst-rtld-bind-now-mod.so
+tst-rtld-bind-now-TUNABLES = glibc.rtld.bind_now=1
+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-array2 = -Wl,--no-as-needed
LDFLAGS-tst-array5 = -Wl,--no-as-needed
@@ -306,7 +306,8 @@ _dl_non_dynamic_init (void)
/* Remember the last search directory added at startup. */
_dl_init_all_dirs = GL(dl_all_dirs);
- _dl_lazy = *(getenv ("LD_BIND_NOW") ?: "") == '\0';
+ _dl_lazy = *(getenv ("LD_BIND_NOW") ?: "") == '\0'
+ && TUNABLE_GET (glibc, rtld, bind_now, int32_t, NULL) == 0;
_dl_bind_not = *(getenv ("LD_BIND_NOT") ?: "") != '\0';
@@ -131,6 +131,12 @@ glibc {
maxval: 1
default: 0
}
+ bind_now {
+ type: INT_32
+ minval: 0
+ maxval: 1
+ default: 0
+ }
}
mem {
@@ -1410,6 +1410,21 @@ dl_main (const ElfW(Phdr) *phdr,
/* Process the environment variable which control the behaviour. */
skip_env = process_envvars (&state);
+ /* The tunable has the same effect as LD_BIND_NOW, but it also applies
+ to AT_SECURE processes, for which process_envvars ignores it. */
+ if (TUNABLE_GET (glibc, rtld, bind_now, int32_t, NULL) != 0)
+ {
+ GLRO(dl_lazy) = 0;
+ /* Profiling requires lazy binding, so LD_PROFILE would override the
+ tunable. */
+ if (GLRO(dl_profile) != NULL)
+ {
+ _dl_error_printf ("\
+warning: LD_PROFILE ignored because glibc.rtld.bind_now is set\n");
+ GLRO(dl_profile) = NULL;
+ }
+ }
+
#ifndef HAVE_INLINED_SYSCALLS
/* Set up a flag which tells we are just starting. */
_dl_starting_up = 1;
new file mode 100644
@@ -0,0 +1,20 @@
+/* Test that symbols are bound lazily 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 LAZY_BINDING 1
+#include "tst-rtld-bind-now.c"
new file mode 100644
@@ -0,0 +1,33 @@
+/* Shared object with an unresolvable lazy binding.
+ 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/>. */
+
+/* Not defined anywhere. The module can only be loaded with lazy
+ binding, since the call below is never made. */
+extern void tst_rtld_bind_now_undefined (void);
+
+void
+tst_rtld_bind_now_call (void)
+{
+ tst_rtld_bind_now_undefined ();
+}
+
+int
+tst_rtld_bind_now_value (void)
+{
+ return 42;
+}
new file mode 100644
@@ -0,0 +1,30 @@
+/* Test glibc.rtld.bind_now with a dependency with an undefined symbol.
+ 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>
+
+int tst_rtld_bind_now_value (void);
+
+static int
+do_test (void)
+{
+ TEST_COMPARE (tst_rtld_bind_now_value (), 42);
+ return 0;
+}
+
+#include <support/test-driver.c>
new file mode 100644
@@ -0,0 +1,19 @@
+/* Test that LD_PROFILE does not re-enable lazy binding.
+ 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-bind-now.c"
new file mode 100644
@@ -0,0 +1,58 @@
+/* Test the glibc.rtld.bind_now 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 <dlfcn.h>
+#include <stdio.h>
+#include <string.h>
+#include <support/check.h>
+#include <support/xdlfcn.h>
+
+/* tst-rtld-bind-now runs with glibc.rtld.bind_now=1, and
+ tst-rtld-bind-now-default with the default value.
+ tst-rtld-bind-now-profile also sets LD_PROFILE, which requires lazy
+ binding. */
+#ifndef LAZY_BINDING
+# define LAZY_BINDING 0
+#endif
+
+#define MODULE "tst-rtld-bind-now-mod.so"
+
+static int
+do_test (void)
+{
+#if LAZY_BINDING
+ /* The undefined symbol is not bound until it is called. */
+ void *h = xdlopen (MODULE, RTLD_LAZY);
+ int (*value) (void) = xdlsym (h, "tst_rtld_bind_now_value");
+ TEST_COMPARE (value (), 42);
+ xdlclose (h);
+#else
+ /* The tunable makes RTLD_LAZY behave as RTLD_NOW. */
+ void *h = dlopen (MODULE, RTLD_LAZY);
+ TEST_VERIFY (h == NULL);
+ const char *err = dlerror ();
+ TEST_VERIFY_EXIT (err != NULL);
+ printf ("info: dlopen error: %s\n", err);
+ TEST_VERIFY (strstr (err, "undefined symbol: tst_rtld_bind_now_undefined")
+ != NULL);
+#endif
+
+ return 0;
+}
+
+#include <support/test-driver.c>
@@ -10,6 +10,7 @@ glibc.malloc.tcache_count: 0x0 (min: 0x0, max: 0x[f]+)
glibc.malloc.tcache_max: 0x0 (min: 0x0, max: 0x[f]+)
glibc.malloc.top_pad: 0x20000 (min: 0x0, max: 0x[f]+)
glibc.malloc.trim_threshold: 0x0 (min: 0x0, max: 0x[f]+)
+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)
@@ -525,6 +525,21 @@ The default value of this tunable is @samp{0}, which allows writable and
executable segments.
@end deftp
+@deftp Tunable glibc.rtld.bind_now
+Setting the @code{glibc.rtld.bind_now} tunable to @code{1} has the same
+effect as setting the @env{LD_BIND_NOW} environment variable. The lazy
+binding trampoline is then not installed, and unresolved symbols are
+reported at load time. Unlike @env{LD_BIND_NOW}, which is ignored for
+@code{AT_SECURE} processes, the tunable can be applied to them through
+@file{/etc/tunables.conf} (@pxref{System-wide Tunables}).
+
+Profiling with @env{LD_PROFILE} requires lazy binding, so the dynamic
+loader ignores @env{LD_PROFILE} when the tunable is set.
+
+The default value of this tunable is @samp{0}, which enables lazy
+binding unless the object was linked with @option{-z now}.
+@end deftp
+
@node POSIX Thread Tunables
@section POSIX Thread Tunables
@cindex pthread mutex tunables