@@ -398,6 +398,9 @@ LDFLAGS-lib.so += -Wl,-z,now
# Extra flags for dynamically linked non-test main programs.
link-extra-flags += -Wl,-z,now
endif
+ifeq ($(ld_zunique),yes)
+LDFLAGS-lib.so += -Wl,-z,unique
+endif
# Command to run after every final link (executable or shared object).
# This is invoked with $(call after-link,...), so it should operate on
@@ -581,7 +581,8 @@ $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
PROVIDE(__start___libc_IO_vtables = .);\
__libc_IO_vtables : { *(__libc_IO_vtables) }\
PROVIDE(__stop___libc_IO_vtables = .);\
- /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
+ /DISCARD/ : { *(.gnu.glibc-stub.*) }@' \
+ -e 's/^.*\*(\.dynamic).*$$/ .dynamic : { *dynamic-notes.os(.dynamic) *(.dynamic) }/'
test -s $@T
mv -f $@T $@
common-generated += shlib.lds
@@ -636,6 +637,16 @@ build-shlib-objlist = $(build-module-helper-objlist) \
# Also omits crti.o and crtn.o, which we do not want
# since we define our own `.init' section specially.
LDFLAGS-c.so = -nostdlib -nostartfiles
+
+# The stub dynamic-notes.os should not have weak/undefined symbol magic in it.
+# It's not really part of the internals, rather it is a vector for linker magic
+# which we need when the linker isn't new enough:
+%/dynamic-notes.os: CPPFLAGS += -UMODULE_NAME
+
+ifeq ($(ld_zunique),yes)
+LDFLAGS-c.so += -Wl,-z,unique
+endif
+
# But we still want to link libc.so against $(libc.so-gnulib).
LDLIBS-c.so += $(libc.so-gnulib)
# Give libc.so an entry point and make it directly runnable itself.
@@ -706,6 +717,11 @@ $(common-objpfx)linkobj/libc.so: $(common-objpfx)linkobj/libc_pic.a \
$(build-shlib)
$(call after-link,$@)
+ifneq ($(ld_zunique),yes)
+$(common-objpfx)libc.so: $(common-objpfx)elf/dynamic-notes.os
+$(common-objpfx)linkobj/libc.so: $(common-objpfx)elf/dynamic-notes.os
+endif
+
ifeq ($(build-shared),yes)
$(common-objpfx)libc.so: $(common-objpfx)libc.map
endif
@@ -625,6 +625,7 @@ libc_cv_cc_nofma
libc_cv_mtls_dialect_gnu2
fno_unit_at_a_time
libc_cv_has_glob_dat
+libc_cv_ld_zunique
libc_cv_hashstyle
libc_cv_fpie
libc_cv_z_execstack
@@ -6181,9 +6182,46 @@ fi
$as_echo "$libc_cv_hashstyle" >&6; }
+old_LDFLAGS="$LDFLAGS"
+LDFLAGS="-Wl,--fatal-warnings -Wl,-z,unique -shared"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker DT_GNU_FLAGS_1/ DF_GNU_1_UNIQUE support" >&5
+$as_echo_n "checking for linker DT_GNU_FLAGS_1/ DF_GNU_1_UNIQUE support... " >&6; }
+if { as_var=cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+void x (void) { }
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ libc_cv_ld_zunique=yes
+else
+ libc_cv_ld_zunique=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext; eval \${$as_var+:} false; }; then :
+ $as_echo_n "(cached) " >&6
+fi
+eval ac_res=\$cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+void x (void) { }
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ libc_cv_ld_zunique=yes
+else
+ libc_cv_ld_zunique=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+LDFLAGS="$old_LDFLAGS"
+
+config_vars="$config_vars
+ld_zunique = $libc_cv_ld_zunique"
+
# The linker's default -shared behavior is good enough if it
# does these things that our custom linker scripts ensure that
-# all allocated NOTE sections come first.
+# all allocated NOTE sections come first AND it understands
+# -z unique should result in DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE
+# sections in its output.
if test "$use_default_link" = default; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sufficient default -shared layout" >&5
$as_echo_n "checking for sufficient default -shared layout... " >&6; }
@@ -6226,10 +6264,16 @@ EOF
esac
shift 2
done
- case "$libc_seen_a$libc_seen_b" in
- yesyes)
+ case "$libc_seen_a$libc_seen_b$libc_cv_ld_zunique" in
+ yesyesyes)
libc_cv_use_default_link=yes
;;
+ yesyesno)
+ echo >&5 "\
+shared layout from:
+$ac_try
+is OK but -Wl,-z,unique is unsupported so linker scripts are required"
+ ;;
*)
echo >&5 "\
$libc_seen_a$libc_seen_b from:
@@ -1389,9 +1389,21 @@ fi
rm -f conftest*])
AC_SUBST(libc_cv_hashstyle)
+old_LDFLAGS="$LDFLAGS"
+LDFLAGS="-Wl,--fatal-warnings -Wl,-z,unique -shared"
+AC_CACHE_CHECK([for linker DT_GNU_FLAGS_1 / DF_GNU_1_UNIQUE support],
+ AC_LINK_IFELSE([AC_LANG_SOURCE([void foo (void) { }])],
+ libc_cv_ld_zunique=yes,
+ libc_cv_ld_zunique=no))
+LDFLAGS="$old_LDFLAGS"
+AC_SUBST(libc_cv_ld_zunique)
+LIBC_CONFIG_VAR([ld_zunique], [$libc_cv_ld_zunique])
+
# The linker's default -shared behavior is good enough if it
# does these things that our custom linker scripts ensure that
-# all allocated NOTE sections come first.
+# all allocated NOTE sections come first AND it understands
+# -z unique should result in DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE
+# sections in its output.
if test "$use_default_link" = default; then
AC_CACHE_CHECK([for sufficient default -shared layout],
libc_cv_use_default_link, [dnl
@@ -1427,10 +1439,16 @@ EOF
esac
shift 2
done
- case "$libc_seen_a$libc_seen_b" in
- yesyes)
+ case "$libc_seen_a$libc_seen_b$libc_cv_ld_zunique" in
+ yesyesyes)
libc_cv_use_default_link=yes
;;
+ yesyesno)
+ echo >&AS_MESSAGE_LOG_FD "\
+shared layout from:
+$ac_try
+is OK but -Wl,-z,unique is unsupported so linker scripts are required"
+ ;;
*)
echo >&AS_MESSAGE_LOG_FD "\
$libc_seen_a$libc_seen_b from:
@@ -35,6 +35,7 @@ routines = \
libc_dlerror_result \
extra-libs-others := libdl
+not-df-gnu-unique := libdl
libdl-shared-only-routines += libdl-compat
@@ -104,6 +104,9 @@ endif
ifeq (yes,$(build-shared))
extra-objs = $(all-rtld-routines:%=%.os) sofini.os interp.os
+ifneq (yes,$(ld_zunique))
+extra-objs += dynamic-notes.os
+endif
generated += librtld.os dl-allobjs.os ld.so ldd
install-others = $(inst_rtlddir)/$(rtld-installed-name)
install-bin-script = ldd
new file mode 100644
@@ -0,0 +1,4 @@
+#include <link.h>
+
+const ElfW(Dyn) __dynamic_note __attribute__ ((section (".dynamic"))) =
+ { .d_tag = DT_GNU_FLAGS_1, .d_un.d_val = DF_GNU_1_UNIQUE };
@@ -101,8 +101,39 @@ $(objpfx)$(lib).so: $(firstword $($(lib)-map) \
$(addprefix $(common-objpfx), \
$(filter $(lib).map, \
$(version-maps))))
+
+############################################################################
+# the following have had all functional contents merged back into libc and
+# are no longer considered part of the implicitly DF_GNU_1_UNIQUE cluster:
+# nptl/libpthread dlfcn/libdl login/libutil resolv/libanl*
+# NOTE: htl/libpthread has NOT been merged
+# resolv/libanl depends on .../libpthread but it _should_ still be OK
+# for resolv/libanl not to be tagged in this case
+
+# NOTE: the mechanisms are reversed depending on linker support:
+# If linker support is present, libraries get the unique flag by default and we
+# _suppress_ this with the -z nounique parameter.
+# If linker support is absent then the flag is _added_ via a hacked up extra
+# object from the elf/ subdir to those DSOs that need it.
+
+# The not-df-gnu-unique variable should contain a space separated list of
+# stub library names (eg pthread for libpthread.so) of extra-libs which should
+# NOT have the uniqueness flag.
+# It should be set in the Makefile of the relevant subdir:
+ifneq ($(ld_zunique),yes)
+ifeq (,$(strip $(filter $(not-df-gnu-unique),$(lib))))
+$(objpfx)$(lib).so: $(common-objpfx)/elf/dynamic-notes.os
+else
endif
+else
+ifneq (,$(strip $(filter $(not-df-gnu-unique),$(lib))))
+LDFLAGS-$(patsubst lib%,%,$(lib)).so += -Wl,-z,nounique
+else
+endif
+endif
+############################################################################
+endif
endif
# This will define `libof-ROUTINE := LIB' for each of the routines.
@@ -169,6 +169,7 @@ shared-only-routines = forward
extra-libs := libpthread
extra-libs-others := $(extra-libs)
+not-df-gnu-unique :=
install-lib := libpthread.so
install-lib-ldscripts := libpthread_syms.a
@@ -202,6 +203,7 @@ $(inst_libdir)/libpthread_syms.a: $(srcdir)/libpthread_syms.a $(+force)
libc-link.so = $(common-objpfx)libc.so
extra-B-pthread.so = -B$(common-objpfx)htl/
+# Turn off DF_GNU_1_UNIQUE for libpthread now that it's a stub.
LDFLAGS-pthread.so = -Wl,--enable-new-dtags,-z,nodelete,-z,initfirst
include ../Rules
@@ -67,6 +67,9 @@ modules := ISO8859-1 ISO8859-2 ISO8859-3 ISO8859-4 ISO8859-5 \
ifeq ($(bind-now),yes)
LDFLAGS.so += -Wl,-z,now
endif
+ifeq ($(ld_zunique),yes)
+LDFLAGS.so += -Wl,-z,unique
+endif
modules.so := $(addsuffix .so, $(modules))
@@ -7,6 +7,10 @@ $(objpfx)$(mod).so: $(addprefix $(objpfx),$(addsuffix .os,$($(mod)-routines)))\
$(shlib-lds) $(link-libc-deps)
$(build-module-asneeded)
+ifneq ($(ld_zunique),yes)
+$(objpfx)$(mod).so: $(common-objpfx)/elf/dynamic-notes.os
+endif
+
ifneq (,$(extra-modules-left))
include extra-module.mk
endif
@@ -50,6 +50,7 @@ ifeq ($(have-GLIBC_2.33),yes)
# Empty compatibility library for old binaries.
extra-libs := libutil
extra-libs-others := $(extra-libs)
+not-df-gnu-unique := libutil
libutil-routines := libutil-compat
libutil-shared-only-routines := libutil-compat
@@ -27,6 +27,7 @@ headers := pthread.h semaphore.h bits/semaphore.h \
extra-libs := libpthread
extra-libs-others := $(extra-libs)
+not-df-gnu-unique := libpthread
routines = \
alloca_cutoff \
@@ -375,7 +376,9 @@ CPPFLAGS-tst-pthread-gdb-attach-static.c := \
# were launched with an explicit ld.so invocation.
tst-pthread-gdb-attach-no-pie = yes
-tests += tst-cancelx7 tst-cancelx17
+LDFLAGS-pthread.so = -Wl,--enable-new-dtags,-z,nodelete,-z,initfirst
+
+tests += tst-cancelx7 tst-cancelx17 tst-cleanupx4
ifeq ($(build-shared),yes)
tests += tst-compat-forwarder tst-audit-threads
@@ -77,8 +77,10 @@ tests-internal += tst-inet_aton_exact
generate := mtrace-tst-leaks.out tst-leaks.mtrace tst-leaks2.mtrace
extra-libs := libresolv libnss_dns
+not-df-gnu-unique :=
ifeq ($(have-thread-library),yes)
extra-libs += libanl
+not-df-gnu-unique += libanl
routines += gai_sigqueue
tests += \