diff mbox series

[RFC,v13,8/9] Drop DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE from merged libraries

Message ID 20210929162642.21985-9-vivek@collabora.com
State New
Headers show
Series Implementation of RTLD_SHARED for dlmopen | expand

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Vivek Das Mohapatra Sept. 29, 2021, 4:26 p.m. UTC
The following extra-libs have been merged into libc proper:
  nptl/libpthread
  htl/libpthread
  dlfcn/libdl
  login/libutil
  resolv/libanl

Since they now exist as contentless stubs to satisfy link requirements
for older applications they do not need to be treated as part of the
core libc cluster when opened in a secondary namespace.
---
 dlfcn/Makefile  |  1 +
 extra-lib.mk    | 25 +++++++++++++++++++++++++
 htl/Makefile    |  5 ++---
 login/Makefile  |  1 +
 nptl/Makefile   |  4 +---
 resolv/Makefile |  2 ++
 6 files changed, 32 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/dlfcn/Makefile b/dlfcn/Makefile
index 6bbfbb8344..13a2684b30 100644
--- a/dlfcn/Makefile
+++ b/dlfcn/Makefile
@@ -35,6 +35,7 @@  routines = \
   libc_dlerror_result \
 
 extra-libs-others := libdl
+not-df-gnu-unique := libdl
 
 libdl-shared-only-routines += libdl-compat
 
diff --git a/extra-lib.mk b/extra-lib.mk
index 9051958ec0..3f17017879 100644
--- a/extra-lib.mk
+++ b/extra-lib.mk
@@ -101,11 +101,36 @@  $(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 htl/libpthread dlfcn/libdl login/libutil resolv/libanl
+
+# 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.
diff --git a/htl/Makefile b/htl/Makefile
index c2a25dcd79..9a04ba2a5f 100644
--- a/htl/Makefile
+++ b/htl/Makefile
@@ -169,6 +169,7 @@  shared-only-routines = forward
 
 extra-libs := libpthread
 extra-libs-others := $(extra-libs)
+not-df-gnu-unique := libpthread
 install-lib := libpthread.so
 install-lib-ldscripts := libpthread_syms.a
 
@@ -202,10 +203,8 @@  $(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
-ifeq ($(ld-zunique),yes)
-LDFLAGS-pthread.so += -Wl,-z,unique
-endif
 
 include ../Rules
 
diff --git a/login/Makefile b/login/Makefile
index 4e6b97734d..703b3f3bd0 100644
--- a/login/Makefile
+++ b/login/Makefile
@@ -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
 
diff --git a/nptl/Makefile b/nptl/Makefile
index bd9bc193e6..015cbd0b96 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -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 \
@@ -376,9 +377,6 @@  CPPFLAGS-tst-pthread-gdb-attach-static.c := \
 tst-pthread-gdb-attach-no-pie = yes
 
 LDFLAGS-pthread.so = -Wl,--enable-new-dtags,-z,nodelete,-z,initfirst
-ifeq ($(ld-zunique),yes)
-LDFLAGS-pthread.so += -Wl,-z,unique
-endif
 
 tests += tst-cancelx7 tst-cancelx17 tst-cleanupx4
 
diff --git a/resolv/Makefile b/resolv/Makefile
index 59e599535c..56afc5c279 100644
--- a/resolv/Makefile
+++ b/resolv/Makefile
@@ -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 += \