public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/azanella/rtld-shared] elf: Add DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE to glibc DSOs (BZ #22745)
@ 2021-08-10 12:43 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-08-10 12:43 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=83dc194adfa8e5b0747947806409a4582369da24
commit 83dc194adfa8e5b0747947806409a4582369da24
Author: Vivek Das Mohapatra <vivek@collabora.com>
Date: Thu Jul 8 17:32:51 2021 +0100
elf: Add DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE to glibc DSOs (BZ #22745)
libc.so, libpthread.so etc should have the new unique-dso-by-default
flag set to allow dlmopen to work better (libc et al instance shared
by default when DSOs dlmopened into a new namespace).
Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diff:
---
Makeconfig | 3 +++
Makerules | 18 +++++++++++++++++-
config.make.in | 1 +
configure | 48 ++++++++++++++++++++++++++++++++++++++++++++---
configure.ac | 23 ++++++++++++++++++++---
elf/Makefile | 3 +++
elf/dynamic-notes.c | 4 ++++
| 3 +++
htl/Makefile | 3 +++
iconvdata/Makefile | 3 +++
| 4 ++++
11 files changed, 106 insertions(+), 7 deletions(-)
diff --git a/Makeconfig b/Makeconfig
index 68663d984e..1046ebb291 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -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
diff --git a/Makerules b/Makerules
index 596fa68376..66c1251754 100644
--- a/Makerules
+++ b/Makerules
@@ -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
diff --git a/config.make.in b/config.make.in
index cbf59114b0..8755490c13 100644
--- a/config.make.in
+++ b/config.make.in
@@ -72,6 +72,7 @@ have-cc-with-libunwind = @libc_cv_cc_with_libunwind@
fno-unit-at-a-time = @fno_unit_at_a_time@
bind-now = @bindnow@
have-hash-style = @libc_cv_hashstyle@
+ld-zunique = @ld_zunique@
use-default-link = @use_default_link@
have-cxx-thread_local = @libc_cv_cxx_thread_local@
have-loop-to-function = @libc_cv_cc_loop_to_function@
diff --git a/configure b/configure
index 9619c10991..3e6d7ffc49 100755
--- a/configure
+++ b/configure
@@ -625,6 +625,7 @@ libc_cv_cc_nofma
libc_cv_mtls_dialect_gnu2
fno_unit_at_a_time
libc_cv_has_glob_dat
+ld_zunique
libc_cv_hashstyle
libc_cv_fpie
libc_cv_z_execstack
@@ -6074,9 +6075,44 @@ 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 foo (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 foo (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"
+
+
# 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; }
@@ -6119,10 +6155,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:
diff --git a/configure.ac b/configure.ac
index 34ecbba540..6a443007fe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1372,9 +1372,20 @@ 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(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
@@ -1410,10 +1421,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:
diff --git a/elf/Makefile b/elf/Makefile
index d05f410592..f33a761c93 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -103,6 +103,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
diff --git a/elf/dynamic-notes.c b/elf/dynamic-notes.c
new file mode 100644
index 0000000000..d0b487e970
--- /dev/null
+++ b/elf/dynamic-notes.c
@@ -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 };
--git a/extra-lib.mk b/extra-lib.mk
index 72f8d2e1df..9051958ec0 100644
--- a/extra-lib.mk
+++ b/extra-lib.mk
@@ -101,6 +101,9 @@ $(objpfx)$(lib).so: $(firstword $($(lib)-map) \
$(addprefix $(common-objpfx), \
$(filter $(lib).map, \
$(version-maps))))
+ifneq ($(ld-zunique),yes)
+$(objpfx)$(lib).so: $(common-objpfx)/elf/dynamic-notes.os
+endif
endif
endif
diff --git a/htl/Makefile b/htl/Makefile
index cf9d12fc12..c2a25dcd79 100644
--- a/htl/Makefile
+++ b/htl/Makefile
@@ -203,6 +203,9 @@ libc-link.so = $(common-objpfx)libc.so
extra-B-pthread.so = -B$(common-objpfx)htl/
LDFLAGS-pthread.so = -Wl,--enable-new-dtags,-z,nodelete,-z,initfirst
+ifeq ($(ld-zunique),yes)
+LDFLAGS-pthread.so += -Wl,-z,unique
+endif
include ../Rules
diff --git a/iconvdata/Makefile b/iconvdata/Makefile
index c216f959df..b1b46e5a43 100644
--- a/iconvdata/Makefile
+++ b/iconvdata/Makefile
@@ -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))
--git a/iconvdata/extra-module.mk b/iconvdata/extra-module.mk
index ecaf507624..92c3ab4d7b 100644
--- a/iconvdata/extra-module.mk
+++ b/iconvdata/extra-module.mk
@@ -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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/azanella/rtld-shared] elf: Add DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE to glibc DSOs (BZ #22745)
@ 2021-09-27 18:54 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-09-27 18:54 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9702f28ab810a8a2e8c7759f10fc8cab1ab8b11e
commit 9702f28ab810a8a2e8c7759f10fc8cab1ab8b11e
Author: Vivek Das Mohapatra <vivek@collabora.com>
Date: Thu Jul 8 17:32:51 2021 +0100
elf: Add DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE to glibc DSOs (BZ #22745)
libc.so, libpthread.so etc should have the new unique-dso-by-default
flag set to allow dlmopen to work better (libc et al instance shared
by default when DSOs dlmopened into a new namespace).
Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diff:
---
Makeconfig | 3 +++
Makerules | 18 ++++++++++++++++-
configure | 50 ++++++++++++++++++++++++++++++++++++++++++++---
configure.ac | 24 ++++++++++++++++++++---
elf/Makefile | 3 +++
elf/dynamic-notes.c | 4 ++++
| 3 +++
iconvdata/Makefile | 3 +++
| 4 ++++
9 files changed, 105 insertions(+), 7 deletions(-)
diff --git a/Makeconfig b/Makeconfig
index 2fa0884b4e..ae587ce84e 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -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
diff --git a/Makerules b/Makerules
index 596fa68376..66c1251754 100644
--- a/Makerules
+++ b/Makerules
@@ -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
diff --git a/configure b/configure
index 39d75eb4ed..3f749b7635 100755
--- a/configure
+++ b/configure
@@ -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 foo (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 foo (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:
diff --git a/configure.ac b/configure.ac
index 00f49f09f7..928989fac5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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:
diff --git a/elf/Makefile b/elf/Makefile
index 26986c0692..d7eb7cf476 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -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
diff --git a/elf/dynamic-notes.c b/elf/dynamic-notes.c
new file mode 100644
index 0000000000..d0b487e970
--- /dev/null
+++ b/elf/dynamic-notes.c
@@ -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 };
--git a/extra-lib.mk b/extra-lib.mk
index 72f8d2e1df..9051958ec0 100644
--- a/extra-lib.mk
+++ b/extra-lib.mk
@@ -101,6 +101,9 @@ $(objpfx)$(lib).so: $(firstword $($(lib)-map) \
$(addprefix $(common-objpfx), \
$(filter $(lib).map, \
$(version-maps))))
+ifneq ($(ld-zunique),yes)
+$(objpfx)$(lib).so: $(common-objpfx)/elf/dynamic-notes.os
+endif
endif
endif
diff --git a/iconvdata/Makefile b/iconvdata/Makefile
index c216f959df..b1b46e5a43 100644
--- a/iconvdata/Makefile
+++ b/iconvdata/Makefile
@@ -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))
--git a/iconvdata/extra-module.mk b/iconvdata/extra-module.mk
index ecaf507624..92c3ab4d7b 100644
--- a/iconvdata/extra-module.mk
+++ b/iconvdata/extra-module.mk
@@ -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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/azanella/rtld-shared] elf: Add DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE to glibc DSOs (BZ #22745)
@ 2021-08-10 13:42 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-08-10 13:42 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=69b0cffd7362e5827a95df6a690f8dd1d9fb1e77
commit 69b0cffd7362e5827a95df6a690f8dd1d9fb1e77
Author: Vivek Das Mohapatra <vivek@collabora.com>
Date: Thu Jul 8 17:32:51 2021 +0100
elf: Add DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE to glibc DSOs (BZ #22745)
libc.so, libpthread.so etc should have the new unique-dso-by-default
flag set to allow dlmopen to work better (libc et al instance shared
by default when DSOs dlmopened into a new namespace).
Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diff:
---
Makeconfig | 3 +++
Makerules | 18 ++++++++++++++++-
configure | 50 ++++++++++++++++++++++++++++++++++++++++++++---
configure.ac | 24 ++++++++++++++++++++---
elf/Makefile | 3 +++
elf/dynamic-notes.c | 4 ++++
| 3 +++
iconvdata/Makefile | 3 +++
| 4 ++++
9 files changed, 105 insertions(+), 7 deletions(-)
diff --git a/Makeconfig b/Makeconfig
index 68663d984e..1046ebb291 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -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
diff --git a/Makerules b/Makerules
index 596fa68376..66c1251754 100644
--- a/Makerules
+++ b/Makerules
@@ -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
diff --git a/configure b/configure
index 9619c10991..e7eb4d1456 100755
--- a/configure
+++ b/configure
@@ -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
@@ -6074,9 +6075,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 foo (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 foo (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; }
@@ -6119,10 +6157,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:
diff --git a/configure.ac b/configure.ac
index 34ecbba540..711d012ed7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1372,9 +1372,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
@@ -1410,10 +1422,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:
diff --git a/elf/Makefile b/elf/Makefile
index d05f410592..f33a761c93 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -103,6 +103,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
diff --git a/elf/dynamic-notes.c b/elf/dynamic-notes.c
new file mode 100644
index 0000000000..d0b487e970
--- /dev/null
+++ b/elf/dynamic-notes.c
@@ -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 };
--git a/extra-lib.mk b/extra-lib.mk
index 72f8d2e1df..9051958ec0 100644
--- a/extra-lib.mk
+++ b/extra-lib.mk
@@ -101,6 +101,9 @@ $(objpfx)$(lib).so: $(firstword $($(lib)-map) \
$(addprefix $(common-objpfx), \
$(filter $(lib).map, \
$(version-maps))))
+ifneq ($(ld-zunique),yes)
+$(objpfx)$(lib).so: $(common-objpfx)/elf/dynamic-notes.os
+endif
endif
endif
diff --git a/iconvdata/Makefile b/iconvdata/Makefile
index c216f959df..b1b46e5a43 100644
--- a/iconvdata/Makefile
+++ b/iconvdata/Makefile
@@ -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))
--git a/iconvdata/extra-module.mk b/iconvdata/extra-module.mk
index ecaf507624..92c3ab4d7b 100644
--- a/iconvdata/extra-module.mk
+++ b/iconvdata/extra-module.mk
@@ -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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/azanella/rtld-shared] elf: Add DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE to glibc DSOs (BZ #22745)
@ 2021-08-09 20:31 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-08-09 20:31 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=83dc194adfa8e5b0747947806409a4582369da24
commit 83dc194adfa8e5b0747947806409a4582369da24
Author: Vivek Das Mohapatra <vivek@collabora.com>
Date: Thu Jul 8 17:32:51 2021 +0100
elf: Add DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE to glibc DSOs (BZ #22745)
libc.so, libpthread.so etc should have the new unique-dso-by-default
flag set to allow dlmopen to work better (libc et al instance shared
by default when DSOs dlmopened into a new namespace).
Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diff:
---
Makeconfig | 3 +++
Makerules | 18 +++++++++++++++++-
config.make.in | 1 +
configure | 48 ++++++++++++++++++++++++++++++++++++++++++++---
configure.ac | 23 ++++++++++++++++++++---
elf/Makefile | 3 +++
elf/dynamic-notes.c | 4 ++++
| 3 +++
htl/Makefile | 3 +++
iconvdata/Makefile | 3 +++
| 4 ++++
11 files changed, 106 insertions(+), 7 deletions(-)
diff --git a/Makeconfig b/Makeconfig
index 68663d984e..1046ebb291 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -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
diff --git a/Makerules b/Makerules
index 596fa68376..66c1251754 100644
--- a/Makerules
+++ b/Makerules
@@ -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
diff --git a/config.make.in b/config.make.in
index cbf59114b0..8755490c13 100644
--- a/config.make.in
+++ b/config.make.in
@@ -72,6 +72,7 @@ have-cc-with-libunwind = @libc_cv_cc_with_libunwind@
fno-unit-at-a-time = @fno_unit_at_a_time@
bind-now = @bindnow@
have-hash-style = @libc_cv_hashstyle@
+ld-zunique = @ld_zunique@
use-default-link = @use_default_link@
have-cxx-thread_local = @libc_cv_cxx_thread_local@
have-loop-to-function = @libc_cv_cc_loop_to_function@
diff --git a/configure b/configure
index 9619c10991..3e6d7ffc49 100755
--- a/configure
+++ b/configure
@@ -625,6 +625,7 @@ libc_cv_cc_nofma
libc_cv_mtls_dialect_gnu2
fno_unit_at_a_time
libc_cv_has_glob_dat
+ld_zunique
libc_cv_hashstyle
libc_cv_fpie
libc_cv_z_execstack
@@ -6074,9 +6075,44 @@ 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 foo (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 foo (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"
+
+
# 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; }
@@ -6119,10 +6155,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:
diff --git a/configure.ac b/configure.ac
index 34ecbba540..6a443007fe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1372,9 +1372,20 @@ 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(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
@@ -1410,10 +1421,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:
diff --git a/elf/Makefile b/elf/Makefile
index d05f410592..f33a761c93 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -103,6 +103,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
diff --git a/elf/dynamic-notes.c b/elf/dynamic-notes.c
new file mode 100644
index 0000000000..d0b487e970
--- /dev/null
+++ b/elf/dynamic-notes.c
@@ -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 };
--git a/extra-lib.mk b/extra-lib.mk
index 72f8d2e1df..9051958ec0 100644
--- a/extra-lib.mk
+++ b/extra-lib.mk
@@ -101,6 +101,9 @@ $(objpfx)$(lib).so: $(firstword $($(lib)-map) \
$(addprefix $(common-objpfx), \
$(filter $(lib).map, \
$(version-maps))))
+ifneq ($(ld-zunique),yes)
+$(objpfx)$(lib).so: $(common-objpfx)/elf/dynamic-notes.os
+endif
endif
endif
diff --git a/htl/Makefile b/htl/Makefile
index cf9d12fc12..c2a25dcd79 100644
--- a/htl/Makefile
+++ b/htl/Makefile
@@ -203,6 +203,9 @@ libc-link.so = $(common-objpfx)libc.so
extra-B-pthread.so = -B$(common-objpfx)htl/
LDFLAGS-pthread.so = -Wl,--enable-new-dtags,-z,nodelete,-z,initfirst
+ifeq ($(ld-zunique),yes)
+LDFLAGS-pthread.so += -Wl,-z,unique
+endif
include ../Rules
diff --git a/iconvdata/Makefile b/iconvdata/Makefile
index c216f959df..b1b46e5a43 100644
--- a/iconvdata/Makefile
+++ b/iconvdata/Makefile
@@ -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))
--git a/iconvdata/extra-module.mk b/iconvdata/extra-module.mk
index ecaf507624..92c3ab4d7b 100644
--- a/iconvdata/extra-module.mk
+++ b/iconvdata/extra-module.mk
@@ -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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/azanella/rtld-shared] elf: Add DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE to glibc DSOs (BZ #22745)
@ 2021-08-09 20:26 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-08-09 20:26 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=83dc194adfa8e5b0747947806409a4582369da24
commit 83dc194adfa8e5b0747947806409a4582369da24
Author: Vivek Das Mohapatra <vivek@collabora.com>
Date: Thu Jul 8 17:32:51 2021 +0100
elf: Add DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE to glibc DSOs (BZ #22745)
libc.so, libpthread.so etc should have the new unique-dso-by-default
flag set to allow dlmopen to work better (libc et al instance shared
by default when DSOs dlmopened into a new namespace).
Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diff:
---
Makeconfig | 3 +++
Makerules | 18 +++++++++++++++++-
config.make.in | 1 +
configure | 48 ++++++++++++++++++++++++++++++++++++++++++++---
configure.ac | 23 ++++++++++++++++++++---
elf/Makefile | 3 +++
elf/dynamic-notes.c | 4 ++++
| 3 +++
htl/Makefile | 3 +++
iconvdata/Makefile | 3 +++
| 4 ++++
11 files changed, 106 insertions(+), 7 deletions(-)
diff --git a/Makeconfig b/Makeconfig
index 68663d984e..1046ebb291 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -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
diff --git a/Makerules b/Makerules
index 596fa68376..66c1251754 100644
--- a/Makerules
+++ b/Makerules
@@ -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
diff --git a/config.make.in b/config.make.in
index cbf59114b0..8755490c13 100644
--- a/config.make.in
+++ b/config.make.in
@@ -72,6 +72,7 @@ have-cc-with-libunwind = @libc_cv_cc_with_libunwind@
fno-unit-at-a-time = @fno_unit_at_a_time@
bind-now = @bindnow@
have-hash-style = @libc_cv_hashstyle@
+ld-zunique = @ld_zunique@
use-default-link = @use_default_link@
have-cxx-thread_local = @libc_cv_cxx_thread_local@
have-loop-to-function = @libc_cv_cc_loop_to_function@
diff --git a/configure b/configure
index 9619c10991..3e6d7ffc49 100755
--- a/configure
+++ b/configure
@@ -625,6 +625,7 @@ libc_cv_cc_nofma
libc_cv_mtls_dialect_gnu2
fno_unit_at_a_time
libc_cv_has_glob_dat
+ld_zunique
libc_cv_hashstyle
libc_cv_fpie
libc_cv_z_execstack
@@ -6074,9 +6075,44 @@ 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 foo (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 foo (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"
+
+
# 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; }
@@ -6119,10 +6155,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:
diff --git a/configure.ac b/configure.ac
index 34ecbba540..6a443007fe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1372,9 +1372,20 @@ 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(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
@@ -1410,10 +1421,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:
diff --git a/elf/Makefile b/elf/Makefile
index d05f410592..f33a761c93 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -103,6 +103,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
diff --git a/elf/dynamic-notes.c b/elf/dynamic-notes.c
new file mode 100644
index 0000000000..d0b487e970
--- /dev/null
+++ b/elf/dynamic-notes.c
@@ -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 };
--git a/extra-lib.mk b/extra-lib.mk
index 72f8d2e1df..9051958ec0 100644
--- a/extra-lib.mk
+++ b/extra-lib.mk
@@ -101,6 +101,9 @@ $(objpfx)$(lib).so: $(firstword $($(lib)-map) \
$(addprefix $(common-objpfx), \
$(filter $(lib).map, \
$(version-maps))))
+ifneq ($(ld-zunique),yes)
+$(objpfx)$(lib).so: $(common-objpfx)/elf/dynamic-notes.os
+endif
endif
endif
diff --git a/htl/Makefile b/htl/Makefile
index cf9d12fc12..c2a25dcd79 100644
--- a/htl/Makefile
+++ b/htl/Makefile
@@ -203,6 +203,9 @@ libc-link.so = $(common-objpfx)libc.so
extra-B-pthread.so = -B$(common-objpfx)htl/
LDFLAGS-pthread.so = -Wl,--enable-new-dtags,-z,nodelete,-z,initfirst
+ifeq ($(ld-zunique),yes)
+LDFLAGS-pthread.so += -Wl,-z,unique
+endif
include ../Rules
diff --git a/iconvdata/Makefile b/iconvdata/Makefile
index c216f959df..b1b46e5a43 100644
--- a/iconvdata/Makefile
+++ b/iconvdata/Makefile
@@ -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))
--git a/iconvdata/extra-module.mk b/iconvdata/extra-module.mk
index ecaf507624..92c3ab4d7b 100644
--- a/iconvdata/extra-module.mk
+++ b/iconvdata/extra-module.mk
@@ -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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/azanella/rtld-shared] elf: Add DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE to glibc DSOs (BZ #22745)
@ 2021-08-09 20:17 Adhemerval Zanella
0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2021-08-09 20:17 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=83dc194adfa8e5b0747947806409a4582369da24
commit 83dc194adfa8e5b0747947806409a4582369da24
Author: Vivek Das Mohapatra <vivek@collabora.com>
Date: Thu Jul 8 17:32:51 2021 +0100
elf: Add DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE to glibc DSOs (BZ #22745)
libc.so, libpthread.so etc should have the new unique-dso-by-default
flag set to allow dlmopen to work better (libc et al instance shared
by default when DSOs dlmopened into a new namespace).
Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diff:
---
Makeconfig | 3 +++
Makerules | 18 +++++++++++++++++-
config.make.in | 1 +
configure | 48 ++++++++++++++++++++++++++++++++++++++++++++---
configure.ac | 23 ++++++++++++++++++++---
elf/Makefile | 3 +++
elf/dynamic-notes.c | 4 ++++
| 3 +++
htl/Makefile | 3 +++
iconvdata/Makefile | 3 +++
| 4 ++++
11 files changed, 106 insertions(+), 7 deletions(-)
diff --git a/Makeconfig b/Makeconfig
index 68663d984e..1046ebb291 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -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
diff --git a/Makerules b/Makerules
index 596fa68376..66c1251754 100644
--- a/Makerules
+++ b/Makerules
@@ -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
diff --git a/config.make.in b/config.make.in
index cbf59114b0..8755490c13 100644
--- a/config.make.in
+++ b/config.make.in
@@ -72,6 +72,7 @@ have-cc-with-libunwind = @libc_cv_cc_with_libunwind@
fno-unit-at-a-time = @fno_unit_at_a_time@
bind-now = @bindnow@
have-hash-style = @libc_cv_hashstyle@
+ld-zunique = @ld_zunique@
use-default-link = @use_default_link@
have-cxx-thread_local = @libc_cv_cxx_thread_local@
have-loop-to-function = @libc_cv_cc_loop_to_function@
diff --git a/configure b/configure
index 9619c10991..3e6d7ffc49 100755
--- a/configure
+++ b/configure
@@ -625,6 +625,7 @@ libc_cv_cc_nofma
libc_cv_mtls_dialect_gnu2
fno_unit_at_a_time
libc_cv_has_glob_dat
+ld_zunique
libc_cv_hashstyle
libc_cv_fpie
libc_cv_z_execstack
@@ -6074,9 +6075,44 @@ 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 foo (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 foo (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"
+
+
# 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; }
@@ -6119,10 +6155,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:
diff --git a/configure.ac b/configure.ac
index 34ecbba540..6a443007fe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1372,9 +1372,20 @@ 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(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
@@ -1410,10 +1421,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:
diff --git a/elf/Makefile b/elf/Makefile
index d05f410592..f33a761c93 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -103,6 +103,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
diff --git a/elf/dynamic-notes.c b/elf/dynamic-notes.c
new file mode 100644
index 0000000000..d0b487e970
--- /dev/null
+++ b/elf/dynamic-notes.c
@@ -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 };
--git a/extra-lib.mk b/extra-lib.mk
index 72f8d2e1df..9051958ec0 100644
--- a/extra-lib.mk
+++ b/extra-lib.mk
@@ -101,6 +101,9 @@ $(objpfx)$(lib).so: $(firstword $($(lib)-map) \
$(addprefix $(common-objpfx), \
$(filter $(lib).map, \
$(version-maps))))
+ifneq ($(ld-zunique),yes)
+$(objpfx)$(lib).so: $(common-objpfx)/elf/dynamic-notes.os
+endif
endif
endif
diff --git a/htl/Makefile b/htl/Makefile
index cf9d12fc12..c2a25dcd79 100644
--- a/htl/Makefile
+++ b/htl/Makefile
@@ -203,6 +203,9 @@ libc-link.so = $(common-objpfx)libc.so
extra-B-pthread.so = -B$(common-objpfx)htl/
LDFLAGS-pthread.so = -Wl,--enable-new-dtags,-z,nodelete,-z,initfirst
+ifeq ($(ld-zunique),yes)
+LDFLAGS-pthread.so += -Wl,-z,unique
+endif
include ../Rules
diff --git a/iconvdata/Makefile b/iconvdata/Makefile
index c216f959df..b1b46e5a43 100644
--- a/iconvdata/Makefile
+++ b/iconvdata/Makefile
@@ -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))
--git a/iconvdata/extra-module.mk b/iconvdata/extra-module.mk
index ecaf507624..92c3ab4d7b 100644
--- a/iconvdata/extra-module.mk
+++ b/iconvdata/extra-module.mk
@@ -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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-09-27 18:54 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-10 12:43 [glibc/azanella/rtld-shared] elf: Add DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE to glibc DSOs (BZ #22745) Adhemerval Zanella
-- strict thread matches above, loose matches on Subject: below --
2021-09-27 18:54 Adhemerval Zanella
2021-08-10 13:42 Adhemerval Zanella
2021-08-09 20:31 Adhemerval Zanella
2021-08-09 20:26 Adhemerval Zanella
2021-08-09 20:17 Adhemerval Zanella
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).