@@ -187,11 +187,14 @@ tests-internal := tst-tls1 tst-tls2 $(tests-static-internal)
tests-static := $(tests-static-normal) $(tests-static-internal)
ifeq (yes,$(build-shared))
-tests-static += tst-tls9-static tst-single_threaded-static-dlopen
+tests-static += tst-tls9-static tst-single_threaded-static-dlopen \
+ tst-dlopen-static
+tests-special += $(objpfx)tst-dlopen-static-_r_debug.out
static-dlopen-environment = \
LD_LIBRARY_PATH=$(ld-library-path):$(common-objpfx)dlfcn
tst-tls9-static-ENV = $(static-dlopen-environment)
tst-single_threaded-static-dlopen-ENV = $(static-dlopen-environment)
+tst-dlopen-static-ENV = $(static-dlopen-environment)
tests += restest1 preloadtest loadfail multiload origtest resolvfail \
constload1 order noload filter \
@@ -609,6 +612,8 @@ $(objpfx)ld.so: $(objpfx)librtld.os $(ld-map)
$(call after-link,$@.new)
$(READELF) -s $@.new \
| $(AWK) '($$7 ~ /^UND(|EF)$$/ && $$1 != "0:" && $$4 != "REGISTER") { print; p=1 } END { exit p != 0 }'
+ $(READELF) -rW $@.new \
+ | $(AWK) '($$5 ~/_r_debug/) { print; p=1 } END { exit p != 0 }'
mv -f $@.new $@
ifeq (yes,$(build-shared))
@@ -1710,6 +1715,13 @@ $(objpfx)tst-single_threaded-pthread.out: \
$(objpfx)tst-single_threaded-mod4.so
$(objpfx)tst-single_threaded-pthread-static: $(static-thread-library)
+$(objpfx)tst-dlopen-static: $(objpfx)tst-single_threaded-mod1.o
+$(objpfx)tst-dlopen-static.out: $(objpfx)tst-single_threaded-mod2.so
+$(objpfx)tst-dlopen-static-_r_debug.out: $(objpfx)tst-dlopen-static
+ $(READELF) -sW $< \
+ | $(AWK) '($$8 ~ /_r_debug$$/) { print; p=1 } END { exit p == 0 }' > $@
+ $(evaluate-test)
+
$(objpfx)tst-tls-ie: $(shared-thread-library)
$(objpfx)tst-tls-ie.out: \
$(objpfx)tst-tls-ie-mod0.so \
@@ -48,6 +48,10 @@ ld {
# stack canary
__stack_chk_guard;
}
+ GLIBC_DEBUG {
+ # Adddess of _r_debug
+ __r_debug_location;
+ }
GLIBC_PRIVATE {
# Those are in the dynamic linker, but used by libc.so.
__libc_enable_secure;
@@ -17,7 +17,7 @@
<https://www.gnu.org/licenses/>. */
#include <ldsodefs.h>
-
+#include <shlib-compat.h>
/* These are the members in the public `struct link_map' type.
Sanity check that the internal type and the public type match. */
@@ -34,11 +34,19 @@ extern const int verify_link_map_members[(VERIFY_MEMBER (l_addr)
normally finds it via the DT_DEBUG entry in the dynamic section, but in
a statically-linked program there is no dynamic section for the debugger
to examine and it looks for this particular symbol name. */
+#undef _r_debug
struct r_debug _r_debug;
+extern struct r_debug _r_debug_internal attribute_hidden;
+strong_alias (_r_debug, _r_debug_internal)
+
+#if SHLIB_COMPAT (rtld, GLIBC_2_0, GLIBC_2_34)
+strong_alias (_r_debug, _r_debug_compat)
+compat_symbol (rtld, _r_debug_compat, _r_debug, GLIBC_2_0);
+#endif
-/* Initialize _r_debug if it has not already been done. The argument is
- the run-time load address of the dynamic linker, to be put in
+/* Initialize _r_debug if it has not already been done. The argument
+ is the run-time load address of the dynamic linker, to be put in
_r_debug.r_ldbase. Returns the address of _r_debug. */
struct r_debug *
@@ -47,7 +55,7 @@ _dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
struct r_debug *r;
if (ns == LM_ID_BASE)
- r = &_r_debug;
+ r = &_r_debug_internal;
else
r = &GL(dl_ns)[ns]._ns_debug;
@@ -55,7 +63,7 @@ _dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
{
/* Tell the debugger where to find the map of loaded objects. */
r->r_version = 1 /* R_DEBUG_VERSION XXX */;
- r->r_ldbase = ldbase ?: _r_debug.r_ldbase;
+ r->r_ldbase = ldbase ?: _r_debug_internal.r_ldbase;
r->r_map = (void *) GL(dl_ns)[ns]._ns_loaded;
r->r_brk = (ElfW(Addr)) &_dl_debug_state;
}
@@ -63,6 +71,11 @@ _dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
return r;
}
+struct r_debug *
+__r_debug_location (void)
+{
+ return &_r_debug_internal;
+}
/* This function exists solely to have a breakpoint set on it by the
debugger. The debugger is supposed to find this function's address by
@@ -63,8 +63,9 @@ struct r_debug
ElfW(Addr) r_ldbase; /* Base address the linker is loaded at. */
};
-/* This is the instance of that structure used by the dynamic linker. */
-extern struct r_debug _r_debug;
+/* Return the address of that structure used by the dynamic linker. */
+extern struct r_debug * __r_debug_location (void) __attribute_const__;
+#define _r_debug (*__r_debug_location ())
/* This symbol refers to the "dynamic structure" in the `.dynamic' section
of whatever module refers to `_DYNAMIC'. So, to find its own
new file mode 100644
@@ -0,0 +1,71 @@
+/* Test static dlopen with _r_debug.
+ Copyright (C) 2021 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 <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <link.h>
+#include <support/check.h>
+#include <support/xdlfcn.h>
+#include <sys/single_threaded.h>
+
+static int
+do_test (void)
+{
+ TEST_VERIFY (__libc_single_threaded);
+
+ /* Defined in tst-single-threaded-mod1.o. */
+ extern _Bool single_threaded_1 (void);
+ TEST_VERIFY (single_threaded_1 ());
+
+ /* A failed dlopen does not change the multi-threaded status. */
+ TEST_VERIFY (dlopen ("tst-single_threaded-does-not-exist.so", RTLD_LAZY)
+ == NULL);
+ TEST_VERIFY (__libc_single_threaded);
+ TEST_VERIFY (single_threaded_1 ());
+
+ /* And neither does a successful dlopen for outer (static) libc. */
+ const char *mod2 = "tst-single_threaded-mod2.so";
+ void *handle_mod2 = xdlopen (mod2, RTLD_LAZY);
+ _Bool (*single_threaded_2) (void)
+ = xdlsym (handle_mod2, "single_threaded_2");
+ TEST_VERIFY (__libc_single_threaded);
+ TEST_VERIFY (single_threaded_1 ());
+ /* The inner libc always assumes multi-threaded use. */
+ TEST_VERIFY (!single_threaded_2 ());
+
+ /* Check the working _r_debug. */
+ struct link_map *map;
+ int missing_mod2 = 1;
+ for (map = _r_debug.r_map; map != NULL; map = map->l_next)
+ {
+ const char *name = basename (map->l_name);
+ printf ("module name = '%s'\n", name);
+ if (strcmp (mod2, name) == 0)
+ missing_mod2 = 0;
+ }
+
+ if (missing_mod2)
+ FAIL_EXIT1 ("'%s' is missing in _r_debug\n", mod2);
+
+ xdlclose (handle_mod2);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
@@ -16,3 +16,4 @@ GLIBC_2.2.6 _r_debug D 0x14
GLIBC_2.2.6 abort F
GLIBC_2.3 ___tls_get_addr F
GLIBC_2.3 __tls_get_addr F
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.17 __stack_chk_guard D 0x8
GLIBC_2.17 __tls_get_addr F
GLIBC_2.17 _dl_mcount F
GLIBC_2.17 _r_debug D 0x28
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.1 __libc_stack_end D 0x8
GLIBC_2.1 _dl_mcount F
GLIBC_2.3 __tls_get_addr F
GLIBC_2.4 __stack_chk_guard D 0x8
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.32 __stack_chk_guard D 0x4
GLIBC_2.32 __tls_get_addr F
GLIBC_2.32 _dl_mcount F
GLIBC_2.32 _r_debug D 0x14
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.4 __stack_chk_guard D 0x4
GLIBC_2.4 __tls_get_addr F
GLIBC_2.4 _dl_mcount F
GLIBC_2.4 _r_debug D 0x14
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.4 __stack_chk_guard D 0x4
GLIBC_2.4 __tls_get_addr F
GLIBC_2.4 _dl_mcount F
GLIBC_2.4 _r_debug D 0x14
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.29 __stack_chk_guard D 0x4
GLIBC_2.29 __tls_get_addr F
GLIBC_2.29 _dl_mcount F
GLIBC_2.29 _r_debug D 0x14
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.2 _dl_mcount F
GLIBC_2.2 _r_debug D 0x14
GLIBC_2.3 __tls_get_addr F
GLIBC_2.4 __stack_chk_guard D 0x4
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.1 __libc_stack_end D 0x4
GLIBC_2.1 _dl_mcount F
GLIBC_2.3 ___tls_get_addr F
GLIBC_2.3 __tls_get_addr F
+GLIBC_DEBUG __r_debug_location F
@@ -2,3 +2,4 @@ GLIBC_2.2 __libc_stack_end D 0x8
GLIBC_2.2 _dl_mcount F
GLIBC_2.2 _r_debug D 0x28
GLIBC_2.3 __tls_get_addr F
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.4 __stack_chk_guard D 0x4
GLIBC_2.4 __tls_get_addr F
GLIBC_2.4 _dl_mcount F
GLIBC_2.4 _r_debug D 0x14
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.1 __libc_stack_end D 0x4
GLIBC_2.1 _dl_mcount F
GLIBC_2.3 __tls_get_addr F
GLIBC_2.4 __stack_chk_guard D 0x4
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.18 __stack_chk_guard D 0x4
GLIBC_2.18 __tls_get_addr F
GLIBC_2.18 _dl_mcount F
GLIBC_2.18 _r_debug D 0x14
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.2 __libc_stack_end D 0x4
GLIBC_2.2 _dl_mcount F
GLIBC_2.3 __tls_get_addr F
GLIBC_2.4 __stack_chk_guard D 0x4
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.2 __libc_stack_end D 0x4
GLIBC_2.2 _dl_mcount F
GLIBC_2.3 __tls_get_addr F
GLIBC_2.4 __stack_chk_guard D 0x4
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.2 __libc_stack_end D 0x8
GLIBC_2.2 _dl_mcount F
GLIBC_2.3 __tls_get_addr F
GLIBC_2.4 __stack_chk_guard D 0x8
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.21 __stack_chk_guard D 0x4
GLIBC_2.21 __tls_get_addr F
GLIBC_2.21 _dl_mcount F
GLIBC_2.21 _r_debug D 0x14
+GLIBC_DEBUG __r_debug_location F
@@ -4,3 +4,4 @@ GLIBC_2.1 _dl_mcount F
GLIBC_2.22 __tls_get_addr_opt F
GLIBC_2.23 __parse_hwcap_and_convert_at_platform F
GLIBC_2.3 __tls_get_addr F
+GLIBC_DEBUG __r_debug_location F
@@ -4,3 +4,4 @@ GLIBC_2.3 __libc_stack_end D 0x8
GLIBC_2.3 __tls_get_addr F
GLIBC_2.3 _dl_mcount F
GLIBC_2.3 _r_debug D 0x28
+GLIBC_DEBUG __r_debug_location F
@@ -4,3 +4,4 @@ GLIBC_2.17 _dl_mcount F
GLIBC_2.17 _r_debug D 0x28
GLIBC_2.22 __tls_get_addr_opt F
GLIBC_2.23 __parse_hwcap_and_convert_at_platform F
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.33 __stack_chk_guard D 0x4
GLIBC_2.33 __tls_get_addr F
GLIBC_2.33 _dl_mcount F
GLIBC_2.33 _r_debug D 0x14
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.27 __stack_chk_guard D 0x8
GLIBC_2.27 __tls_get_addr F
GLIBC_2.27 _dl_mcount F
GLIBC_2.27 _r_debug D 0x28
+GLIBC_DEBUG __r_debug_location F
@@ -2,3 +2,4 @@ GLIBC_2.0 _r_debug D 0x14
GLIBC_2.1 __libc_stack_end D 0x4
GLIBC_2.1 _dl_mcount F
GLIBC_2.3 __tls_get_offset F
+GLIBC_DEBUG __r_debug_location F
@@ -2,3 +2,4 @@ GLIBC_2.2 __libc_stack_end D 0x8
GLIBC_2.2 _dl_mcount F
GLIBC_2.2 _r_debug D 0x28
GLIBC_2.3 __tls_get_offset F
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.2 _dl_mcount F
GLIBC_2.2 _r_debug D 0x14
GLIBC_2.3 __tls_get_addr F
GLIBC_2.4 __stack_chk_guard D 0x4
+GLIBC_DEBUG __r_debug_location F
@@ -3,3 +3,4 @@ GLIBC_2.2 _dl_mcount F
GLIBC_2.2 _r_debug D 0x14
GLIBC_2.3 __tls_get_addr F
GLIBC_2.4 __stack_chk_guard D 0x4
+GLIBC_DEBUG __r_debug_location F
@@ -2,3 +2,4 @@ GLIBC_2.0 _r_debug D 0x14
GLIBC_2.1 __libc_stack_end D 0x4
GLIBC_2.1 _dl_mcount F
GLIBC_2.3 __tls_get_addr F
+GLIBC_DEBUG __r_debug_location F
@@ -2,3 +2,4 @@ GLIBC_2.2 __libc_stack_end D 0x8
GLIBC_2.2 _dl_mcount F
GLIBC_2.2 _r_debug D 0x28
GLIBC_2.3 __tls_get_addr F
+GLIBC_DEBUG __r_debug_location F
@@ -2,3 +2,4 @@ GLIBC_2.2.5 __libc_stack_end D 0x8
GLIBC_2.2.5 _dl_mcount F
GLIBC_2.2.5 _r_debug D 0x28
GLIBC_2.3 __tls_get_addr F
+GLIBC_DEBUG __r_debug_location F
@@ -2,3 +2,4 @@ GLIBC_2.16 __libc_stack_end D 0x4
GLIBC_2.16 __tls_get_addr F
GLIBC_2.16 _dl_mcount F
GLIBC_2.16 _r_debug D 0x14
+GLIBC_DEBUG __r_debug_location F