public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 0/6] Reliable CPU compatibility diagnostics in ld.so
@ 2022-01-14 16:51 Florian Weimer
  2022-01-14 16:52 ` [PATCH v2 1/6] elf/Makefile: Reflow and sort most variable assignments Florian Weimer
                   ` (6 more replies)
  0 siblings, 7 replies; 16+ messages in thread
From: Florian Weimer @ 2022-01-14 16:51 UTC (permalink / raw)
  To: libc-alpha

v2: Rebased after the first two patches went.  New first patch to reflow
elf/Makefile.  configure option has been renamed.

Florian Weimer (6):
  elf/Makefile: Reflow and sort most variable assignments
  elf: Split dl-printf.c from dl-misc.c
  Add --with-rtld-early-cflags configure option
  powerpc64le: Use <gcc-macros.h> in early HWCAP check
  x86: Add x86-64-vN check to early startup
  s390x: Use <gcc-macros.h> in early HWCAP check

 INSTALL                                       |   8 +
 config.make.in                                |   1 +
 configure                                     |  13 +
 configure.ac                                  |   6 +
 elf/Makefile                                  | 429 +++++++++++++-----
 elf/dl-misc.c                                 | 281 +-----------
 elf/dl-printf.c                               | 292 ++++++++++++
 manual/install.texi                           |   7 +
 sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h |   9 +-
 sysdeps/s390/s390-64/dl-hwcap-check.h         |   5 +-
 sysdeps/x86/Makefile                          |   1 +
 sysdeps/x86/dl-get-cpu-features.c             |  31 +-
 12 files changed, 697 insertions(+), 386 deletions(-)
 create mode 100644 elf/dl-printf.c


base-commit: ef7c6d42fe163a5e49a478c43e655ce4633fa5ba
-- 
2.34.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 1/6] elf/Makefile: Reflow and sort most variable assignments
  2022-01-14 16:51 [PATCH v2 0/6] Reliable CPU compatibility diagnostics in ld.so Florian Weimer
@ 2022-01-14 16:52 ` Florian Weimer
  2022-01-14 18:39   ` H.J. Lu
  2022-01-14 16:52 ` [PATCH v2 2/6] elf: Split dl-printf.c from dl-misc.c Florian Weimer
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Florian Weimer @ 2022-01-14 16:52 UTC (permalink / raw)
  To: libc-alpha

---
v2: new patch
 elf/Makefile | 420 ++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 318 insertions(+), 102 deletions(-)

diff --git a/elf/Makefile b/elf/Makefile
index b86d116be9..3065efc485 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -21,24 +21,67 @@ subdir		:= elf
 
 include ../Makeconfig
 
-headers		= elf.h bits/elfclass.h link.h bits/link.h bits/link_lavcurrent.h
-routines	= $(all-dl-routines) dl-support dl-iteratephdr \
-		  dl-addr dl-addr-obj enbl-secure dl-profstub \
-		  dl-origin dl-libc dl-sym dl-sysdep dl-error \
-		  dl-reloc-static-pie libc_early_init rtld_static_init \
-		  libc-dl_find_object
+headers = \
+  bits/elfclass.h \
+  bits/link.h \
+  bits/link_lavcurrent.h \
+  elf.h \
+  link.h \
+  # headers
+
+routines = \
+  $(all-dl-routines) \
+  dl-addr \
+  dl-addr-obj \
+  dl-error \
+  dl-iteratephdr \
+  dl-libc \
+  dl-origin \
+  dl-profstub \
+  dl-reloc-static-pie \
+  dl-support \
+  dl-sym \
+  dl-sysdep \
+  enbl-secure \
+  libc-dl_find_object \
+  libc_early_init \
+  rtld_static_init \
+  # routines
 
 # The core dynamic linking functions are in libc for the static and
 # profiled libraries.
-dl-routines	= $(addprefix dl-,load lookup object reloc deps \
-				  runtime init fini debug misc \
-				  version profile tls origin scope \
-				  execstack open close trampoline \
-				  exception sort-maps lookup-direct \
-				  call-libc-early-init write \
-				  thread_gscope_wait tls_init_tp \
-				  debug-symbols minimal-malloc \
-			          find_object)
+dl-routines = \
+  dl-call-libc-early-init \
+  dl-close \
+  dl-debug \
+  dl-debug-symbols \
+  dl-deps \
+  dl-exception \
+  dl-execstack \
+  dl-find_object \
+  dl-fini \
+  dl-init \
+  dl-load \
+  dl-lookup \
+  dl-lookup-direct \
+  dl-minimal-malloc \
+  dl-misc \
+  dl-object \
+  dl-open \
+  dl-origin \
+  dl-profile \
+  dl-reloc \
+  dl-runtime \
+  dl-scope \
+  dl-sort-maps \
+  dl-thread_gscope_wait \
+  dl-tls \
+  dl-tls_init_tp \
+  dl-trampoline \
+  dl-version \
+  dl-write \
+  # dl-routines
+
 ifeq (yes,$(use-ldconfig))
 dl-routines += dl-cache
 endif
@@ -61,19 +104,43 @@ endif
 
 all-dl-routines = $(dl-routines) $(sysdep-dl-routines)
 # But they are absent from the shared libc, because that code is in ld.so.
-elide-routines.os = $(all-dl-routines) dl-support enbl-secure dl-origin \
-		    dl-sysdep dl-exception dl-reloc-static-pie \
-		    thread_gscope_wait rtld_static_init
+elide-routines.os = \
+  $(all-dl-routines) \
+  dl-exception \
+  dl-origin \
+  dl-reloc-static-pie \
+  dl-support \
+  dl-sysdep \
+  enbl-secure \
+  rtld_static_init \
+  thread_gscope_wait \
+  # elide-routines.os
 
 # These object files are only included in the dynamically-linked libc.
 shared-only-routines = libc-dl_find_object
 
 # ld.so uses those routines, plus some special stuff for being the program
 # interpreter and operating independent of libc.
-rtld-routines	= rtld $(all-dl-routines) dl-sysdep dl-environ dl-minimal \
-  dl-error-minimal dl-conflict dl-hwcaps dl-hwcaps_split dl-hwcaps-subdirs \
-  dl-usage dl-diagnostics dl-diagnostics-kernel dl-diagnostics-cpu \
-  dl-mutex dl-libc_freeres dl-audit
+rtld-routines = \
+  $(all-dl-routines) \
+  dl-audit \
+  dl-conflict \
+  dl-diagnostics \
+  dl-diagnostics-cpu \
+  dl-diagnostics-kernel \
+  dl-environ \
+  dl-error-minimal \
+  dl-hwcaps \
+  dl-hwcaps-subdirs \
+  dl-hwcaps_split \
+  dl-libc_freeres \
+  dl-minimal \
+  dl-mutex \
+  dl-sysdep \
+  dl-usage \
+  rtld \
+  # rtld-routines
+
 all-rtld-routines = $(rtld-routines) $(sysdep-rtld-routines)
 
 CFLAGS-dl-runtime.c += -fexceptions -fasynchronous-unwind-tables
@@ -113,8 +180,16 @@ ld-map		= $(common-objpfx)ld.map
 endif
 
 ifeq (yes,$(build-shared))
-extra-objs	= $(all-rtld-routines:%=%.os) sofini.os interp.os
-generated	+= librtld.os dl-allobjs.os ld.so ldd
+extra-objs = \
+  $(all-rtld-routines:%=%.os) \
+  sofini.os \
+  interp.os \
+  # extra-objs
+generated += \
+  dl-allobjs.os \
+  ld.so ldd \
+  librtld.os \
+  # generated
 install-others	= $(inst_rtlddir)/$(rtld-installed-name) $(inst_bindir)/ld.so
 install-bin-script = ldd
 endif
@@ -132,8 +207,15 @@ others-static	+= ldconfig
 others		+= ldconfig
 install-rootsbin += ldconfig
 
-ldconfig-modules := cache readlib xmalloc xstrdup chroot_canon static-stubs \
-  stringtable
+ldconfig-modules := \
+  cache \
+  chroot_canon \
+  readlib \
+  static-stubs \
+  stringtable \
+  xmalloc \
+  xstrdup \
+  # ldconfig-modules
 extra-objs	+= $(ldconfig-modules:=.o)
 others-extras   = $(ldconfig-modules)
 endif
@@ -167,24 +249,36 @@ $(inst_auditdir)/sotruss-lib.so: $(objpfx)sotruss-lib.so $(+force)
 	$(do-install-program)
 endif
 
-tests-static-normal := tst-array1-static tst-array5-static \
-	       tst-dl-iter-static \
-	       tst-tlsalign-static tst-tlsalign-extern-static \
-	       tst-linkall-static tst-env-setuid tst-env-setuid-tunables \
-	       tst-single_threaded-static tst-single_threaded-pthread-static \
-	       tst-dst-static tst-getauxval-static
-
-tests-static-internal := tst-tls1-static \
-	       tst-ptrguard1-static tst-stackguard1-static \
-	       tst-tls1-static-non-pie \
-	       tst-dl_find_object-static
+tests-static-normal := \
+  tst-array1-static \
+  tst-array5-static \
+  tst-dl-iter-static \
+  tst-dst-static \
+  tst-env-setuid \
+  tst-env-setuid-tunables \
+  tst-getauxval-static \
+  tst-linkall-static \
+  tst-single_threaded-pthread-static \
+  tst-single_threaded-static \
+  tst-tlsalign-extern-static \
+  tst-tlsalign-static \
+  # tests-static-normal
+
+tests-static-internal := \
+  tst-dl_find_object-static \
+  tst-ptrguard1-static \
+  tst-stackguard1-static \
+  tst-tls1-static \
+  tst-tls1-static-non-pie \
+  # tests-static-internal
 
 CRT-tst-tls1-static-non-pie := $(csu-objpfx)crt1.o
 tst-tls1-static-non-pie-no-pie = yes
 
 tests-container := \
-			  tst-ldconfig-bad-aux-cache \
-			  tst-ldconfig-ld_so_conf-update
+  tst-ldconfig-bad-aux-cache \
+  tst-ldconfig-ld_so_conf-update \
+  # tests-container
 
 ifeq (no,$(build-hardcoded-path-in-tests))
 # This is an ld.so.cache test, and RPATH/RUNPATH in the executable
@@ -192,14 +286,31 @@ ifeq (no,$(build-hardcoded-path-in-tests))
 tests-container += tst-glibc-hwcaps-prepend-cache
 endif
 
-tests := tst-tls9 tst-leaks1 \
-	tst-array1 tst-array2 tst-array3 tst-array4 tst-array5 \
-	tst-auxv tst-stringtable
-tests-internal := tst-tls1 $(tests-static-internal)
+tests := \
+  tst-array1 \
+  tst-array2 \
+  tst-array3 \
+  tst-array4 \
+  tst-array5 \
+  tst-auxv \
+  tst-leaks1 \
+  tst-stringtable \
+  tst-tls9 \
+  # tests
+
+tests-internal := \
+  $(tests-static-internal) \
+  tst-tls1 \
+  # tests-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-single_threaded-static-dlopen \
+  tst-tls9-static \
+  # tests-static
+
 static-dlopen-environment = \
   LD_LIBRARY_PATH=$(ld-library-path):$(common-objpfx)dlfcn
 tst-tls9-static-ENV = $(static-dlopen-environment)
@@ -327,45 +438,88 @@ tests += \
   unload6 \
   unload7 \
   unload8 \
-#	 reldep9
+  # tests
 tests-cxx = \
   tst-dlopen-nodelete-reloc \
   tst-nodelete \
   tst-unique3 \
   tst-unique4 \
-# tests-cxx
+  # tests-cxx
 
 tests += $(if $(CXX),$(tests-cxx))
-tests-internal += loadtest unload unload2 circleload1 \
-	 neededtest neededtest2 neededtest3 neededtest4 \
-	 tst-tls3 tst-tls6 tst-tls7 tst-tls8 tst-dlmopen2 \
-	 tst-ptrguard1 tst-stackguard1 \
-	 tst-create_format1 tst-tls-surplus tst-dl-hwcaps_split \
-	 tst-audit19a \
-	 tst-dl_find_object tst-dl_find_object-threads
-tests-container += tst-pldd tst-dlopen-tlsmodid-container \
-  tst-dlopen-self-container tst-preload-pthread-libc
-test-srcs = tst-pathopt
+
+tests-internal += \
+  circleload1 \
+  loadtest \
+  neededtest \
+  neededtest2 \
+  neededtest3 \
+  neededtest4 \
+  tst-audit19a \
+  tst-create_format1 \
+  tst-dl-hwcaps_split \
+  tst-dl_find_object \
+  tst-dl_find_object-threads \
+  tst-dlmopen2 \
+  tst-ptrguard1 \
+  tst-stackguard1 \
+  tst-tls-surplus \
+  tst-tls3 \
+  tst-tls6 \
+  tst-tls7 \
+  tst-tls8 \
+  unload \
+  unload2 \
+  # tests-internal
+
+tests-container += \
+  tst-dlopen-self-container \
+  tst-dlopen-tlsmodid-container \
+  tst-pldd \
+  tst-preload-pthread-libc \
+  # tests-container
+
+test-srcs = \
+  tst-pathopt \
+  # tests-srcs
+
 ifeq (yes,$(have-fpie))
 tests-pie += tst-align3
 endif
 selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null)
+
 ifneq ($(selinux-enabled),1)
-tests-execstack-yes = tst-execstack tst-execstack-needed tst-execstack-prog
+tests-execstack-yes = \
+  tst-execstack \
+  tst-execstack-needed \
+  tst-execstack-prog \
+  # tests-execstack-yes
 endif
 ifeq ($(have-depaudit),yes)
-tests += tst-audit14 tst-audit15 tst-audit16 tst-audit14a
+tests += \
+  tst-audit14 \
+  tst-audit14a \
+  tst-audit15 \
+  tst-audit16 \
+  # tests
 ifeq ($(run-built-tests),yes)
-tests-special += $(objpfx)tst-audit14-cmp.out $(objpfx)tst-audit15-cmp.out \
-		 $(objpfx)tst-audit16-cmp.out $(objpfx)tst-audit14a-cmp.out
+tests-special += \
+  $(objpfx)tst-audit14-cmp.out \
+  $(objpfx)tst-audit14a-cmp.out \
+  $(objpfx)tst-audit15-cmp.out \
+  $(objpfx)tst-audit16-cmp.out \
+  # tests-special
 endif
 endif
 endif
 tests += $(tests-execstack-$(have-z-execstack))
 ifeq ($(run-built-tests),yes)
-tests-special += $(objpfx)tst-leaks1-mem.out \
-		 $(objpfx)noload-mem.out \
-		 $(objpfx)tst-ldconfig-X.out $(objpfx)tst-rtld-help.out
+tests-special += \
+  $(objpfx)noload-mem.out \
+  $(objpfx)tst-ldconfig-X.out \
+  $(objpfx)tst-leaks1-mem.out \
+  $(objpfx)tst-rtld-help.out \
+  # tests-special
 endif
 tlsmod17a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 tlsmod18a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
@@ -382,9 +536,16 @@ tst-tls-many-dynamic-modules-dep = \
 tst-tls-many-dynamic-modules-dep-bad-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
 tst-tls-many-dynamic-modules-dep-bad = \
   $(foreach n,$(tst-tls-many-dynamic-modules-dep-bad-suffixes),tst-tls-manydynamic$(n)mod-dep-bad)
-extra-test-objs += $(tlsmod17a-modules:=.os) $(tlsmod18a-modules:=.os) \
-		   tst-tlsalign-vars.o
-test-extras += tst-tlsmod17a tst-tlsmod18a tst-tlsalign-vars
+extra-test-objs += \
+  $(tlsmod17a-modules:=.os) \
+  $(tlsmod18a-modules:=.os) \
+  tst-tlsalign-vars.o \
+  # extra-test-objs
+test-extras += \
+  tst-tlsalign-vars \
+  tst-tlsmod17a \
+  tst-tlsmod18a \
+  # test-extras
 modules-names = \
   circlemod1 \
   circlemod1a \
@@ -653,17 +814,17 @@ modules-names-cxx = \
   tst-unique3lib \
   tst-unique3lib2 \
   tst-unique4lib \
-# modules-names-cxx
+  # modules-names-cxx
 
 modules-names += \
   $(if $(CXX),$(modules-names-cxx)) \
   $(modules-execstack-$(have-z-execstack)) \
+  $(tlsmod17a-modules) \
+  $(tlsmod18a-modules) \
   $(tst-tls-many-dynamic-modules) \
   $(tst-tls-many-dynamic-modules-dep) \
   $(tst-tls-many-dynamic-modules-dep-bad) \
-  $(tlsmod17a-modules) \
-  $(tlsmod18a-modules) \
-# modules-names
+  # modules-names
 
 # Most modules build with _ISOMAC defined, but those filtered out
 # depend on internal headers.
@@ -728,38 +889,73 @@ modules-names-nobuild := filtmod1 tst-big-note-lib tst-ro-dynamic-mod
 tests += $(tests-static)
 
 ifeq (yes,$(have-ifunc))
-tests-ifuncstatic := ifuncmain1static ifuncmain1picstatic \
-		ifuncmain2static ifuncmain2picstatic \
-		ifuncmain4static ifuncmain4picstatic \
-		ifuncmain5static ifuncmain5picstatic \
-		ifuncmain7static ifuncmain7picstatic
+tests-ifuncstatic := \
+  ifuncmain1static \
+  ifuncmain1picstatic \
+  ifuncmain2static \
+  ifuncmain2picstatic \
+  ifuncmain4static \
+  ifuncmain4picstatic \
+  ifuncmain5static \
+  ifuncmain5picstatic \
+  ifuncmain7static \
+  ifuncmain7picstatic \
+  # tests-ifuncstatic
 ifeq (yes,$(have-gcc-ifunc))
 tests-ifuncstatic += ifuncmain9static ifuncmain9picstatic
 endif
 tests-static += $(tests-ifuncstatic)
 tests-internal += $(tests-ifuncstatic)
 ifeq (yes,$(build-shared))
-tests += tst-ifunc-fault-lazy tst-ifunc-fault-bindnow
+tests += \
+  tst-ifunc-fault-bindnow \
+  tst-ifunc-fault-lazy \
+  # tests
 # Note: sysdeps/x86_64/ifuncmain8.c uses ifuncmain8.
 tests-internal += \
-	 ifuncmain1pic ifuncmain1vis ifuncmain1vispic \
-	 ifuncmain1staticpic \
-	 ifuncmain2 ifuncmain2pic ifuncmain3 ifuncmain4 \
-	 ifuncmain5staticpic \
-	 ifuncmain7 ifuncmain7pic
+  ifuncmain1pic \
+  ifuncmain1staticpic \
+  ifuncmain1vis \
+  ifuncmain1vispic \
+  ifuncmain2 \
+  ifuncmain2pic \
+  ifuncmain3 \
+  ifuncmain4 \
+  ifuncmain5staticpic \
+  ifuncmain7 \
+  ifuncmain7pic \
+  # tests-internal
 ifeq (no,$(with-lld))
-tests-internal += ifuncmain1 ifuncmain5 ifuncmain5pic
+tests-internal += \
+  ifuncmain1 \
+  ifuncmain5 \
+  ifuncmain5pic \
+  # tests-internal
 endif
 ifeq (yes,$(have-gcc-ifunc))
-tests-internal += ifuncmain9 ifuncmain9pic
+tests-internal += \
+  ifuncmain9 \
+  ifuncmain9pic \
+  # tests-internal
 endif
-ifunc-test-modules = ifuncdep1 ifuncdep1pic ifuncdep2 ifuncdep2pic \
-		     ifuncdep5 ifuncdep5pic
+ifunc-test-modules = \
+  ifuncdep1 \
+  ifuncdep1pic \
+  ifuncdep2 \
+  ifuncdep2pic \
+  ifuncdep5 \
+  ifuncdep5pic \
+  # ifunc-test-modules
 extra-test-objs += $(ifunc-test-modules:=.o)
 test-internal-extras += $(ifunc-test-modules)
 ifeq (yes,$(have-fpie))
-ifunc-pie-tests = ifuncmain1pie ifuncmain1vispie ifuncmain1staticpie \
-		  ifuncmain6pie ifuncmain7pie
+ifunc-pie-tests = \
+  ifuncmain1pie \
+  ifuncmain1staticpie \
+  ifuncmain1vispie \
+  ifuncmain6pie \
+  ifuncmain7pie \
+  # ifunc-pie-tests
 ifeq (yes,$(have-gcc-ifunc))
 ifunc-pie-tests += ifuncmain9pie
 endif
@@ -772,7 +968,11 @@ endif
 tests-internal += $(ifunc-pie-tests)
 tests-pie += $(ifunc-pie-tests)
 endif
-modules-names += ifuncmod1 ifuncmod3 ifuncmod6
+modules-names += \
+  ifuncmod1 \
+  ifuncmod3 \
+  ifuncmod6 \
+  # module-names
 ifeq (no,$(with-lld))
 modules-names += ifuncmod5
 endif
@@ -781,24 +981,39 @@ endif
 
 ifeq (yes,$(build-shared))
 ifeq ($(run-built-tests),yes)
-tests-special += $(objpfx)tst-pathopt.out $(objpfx)tst-rtld-load-self.out \
-		 $(objpfx)tst-rtld-preload.out $(objpfx)argv0test.out \
-		 $(objpfx)tst-rtld-help.out
+tests-special += \
+  $(objpfx)argv0test.out \
+  $(objpfx)tst-pathopt.out \
+  $(objpfx)tst-rtld-help.out \
+  $(objpfx)tst-rtld-load-self.out \
+  $(objpfx)tst-rtld-preload.out \
+  # tests-special
 endif
-tests-special += $(objpfx)check-textrel.out $(objpfx)check-execstack.out \
-		 $(objpfx)check-wx-segment.out \
-		 $(objpfx)check-localplt.out $(objpfx)check-initfini.out
+tests-special += \
+  $(objpfx)check-execstack.out \
+  $(objpfx)check-initfini.out \
+  $(objpfx)check-localplt.out \
+  $(objpfx)check-textrel.out \
+  $(objpfx)check-wx-segment.out \
+  # tests-special
 endif
 
 ifeq ($(run-built-tests),yes)
-tests-special += $(objpfx)order-cmp.out $(objpfx)tst-array1-cmp.out \
-		 $(objpfx)tst-array1-static-cmp.out \
-		 $(objpfx)tst-array2-cmp.out $(objpfx)tst-array3-cmp.out \
-		 $(objpfx)tst-array4-cmp.out $(objpfx)tst-array5-cmp.out \
-		 $(objpfx)tst-array5-static-cmp.out $(objpfx)order2-cmp.out \
-		 $(objpfx)tst-initorder-cmp.out \
-		 $(objpfx)tst-initorder2-cmp.out $(objpfx)tst-unused-dep.out \
-		 $(objpfx)tst-unused-dep-cmp.out
+tests-special += \
+  $(objpfx)order-cmp.out \
+  $(objpfx)order2-cmp.out \
+  $(objpfx)tst-array1-cmp.out \
+  $(objpfx)tst-array1-static-cmp.out \
+  $(objpfx)tst-array2-cmp.out \
+  $(objpfx)tst-array3-cmp.out \
+  $(objpfx)tst-array4-cmp.out \
+  $(objpfx)tst-array5-cmp.out \
+  $(objpfx)tst-array5-static-cmp.out \
+  $(objpfx)tst-initorder-cmp.out \
+  $(objpfx)tst-initorder2-cmp.out \
+  $(objpfx)tst-unused-dep-cmp.out \
+  $(objpfx)tst-unused-dep.out \
+  # tests-special
 endif
 
 ifndef avoid-generated
@@ -903,6 +1118,7 @@ rtld-stubbed-symbols = \
   free \
   malloc \
   realloc \
+  # rtld-stubbed-symbols
 
 ifeq ($(have-ssp),yes)
 # rtld is not built with the stack protector, so these references will
-- 
2.34.1



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 2/6] elf: Split dl-printf.c from dl-misc.c
  2022-01-14 16:51 [PATCH v2 0/6] Reliable CPU compatibility diagnostics in ld.so Florian Weimer
  2022-01-14 16:52 ` [PATCH v2 1/6] elf/Makefile: Reflow and sort most variable assignments Florian Weimer
@ 2022-01-14 16:52 ` Florian Weimer
  2022-01-14 18:40   ` H.J. Lu
  2022-01-14 16:52 ` [PATCH v2 3/6] Add --with-rtld-early-cflags configure option Florian Weimer
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Florian Weimer @ 2022-01-14 16:52 UTC (permalink / raw)
  To: libc-alpha

This allows to use different compiler flags for the diagnostics
code.
---
v2: Adjust to Makefile changes in patch 1.
 elf/Makefile    |   1 +
 elf/dl-misc.c   | 281 +---------------------------------------------
 elf/dl-printf.c | 292 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 297 insertions(+), 277 deletions(-)
 create mode 100644 elf/dl-printf.c

diff --git a/elf/Makefile b/elf/Makefile
index 3065efc485..3df49742ff 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -69,6 +69,7 @@ dl-routines = \
   dl-object \
   dl-open \
   dl-origin \
+  dl-printf \
   dl-profile \
   dl-reloc \
   dl-runtime \
diff --git a/elf/dl-misc.c b/elf/dl-misc.c
index 452b79de4a..6f40c28820 100644
--- a/elf/dl-misc.c
+++ b/elf/dl-misc.c
@@ -16,24 +16,16 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <assert.h>
+#include <_itoa.h>
 #include <fcntl.h>
 #include <ldsodefs.h>
-#include <limits.h>
 #include <link.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
+#include <not-cancel.h>
 #include <stdint.h>
+#include <stdlib.h>
 #include <sys/mman.h>
-#include <sys/param.h>
 #include <sys/stat.h>
-#include <sys/uio.h>
-#include <sysdep.h>
-#include <_itoa.h>
-#include <dl-writev.h>
-#include <not-cancel.h>
+#include <unistd.h>
 
 /* Read the whole contents of FILE into new mmap'd space with given
    protections.  *SIZEP gets the size of the file.  On error MAP_FAILED
@@ -70,270 +62,6 @@ _dl_sysdep_read_whole_file (const char *file, size_t *sizep, int prot)
   return result;
 }
 
-
-/* Bare-bones printf implementation.  This function only knows about
-   the formats and flags needed and can handle only up to 64 stripes in
-   the output.  */
-static void
-_dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg)
-{
-# define NIOVMAX 64
-  struct iovec iov[NIOVMAX];
-  int niov = 0;
-  pid_t pid = 0;
-  char pidbuf[12];
-
-  while (*fmt != '\0')
-    {
-      const char *startp = fmt;
-
-      if (tag_p > 0)
-	{
-	  /* Generate the tag line once.  It consists of the PID and a
-	     colon followed by a tab.  */
-	  if (pid == 0)
-	    {
-	      char *p;
-	      pid = __getpid ();
-	      assert (pid >= 0 && sizeof (pid_t) <= 4);
-	      p = _itoa (pid, &pidbuf[10], 10, 0);
-	      while (p > pidbuf)
-		*--p = ' ';
-	      pidbuf[10] = ':';
-	      pidbuf[11] = '\t';
-	    }
-
-	  /* Append to the output.  */
-	  assert (niov < NIOVMAX);
-	  iov[niov].iov_len = 12;
-	  iov[niov++].iov_base = pidbuf;
-
-	  /* No more tags until we see the next newline.  */
-	  tag_p = -1;
-	}
-
-      /* Skip everything except % and \n (if tags are needed).  */
-      while (*fmt != '\0' && *fmt != '%' && (! tag_p || *fmt != '\n'))
-	++fmt;
-
-      /* Append constant string.  */
-      assert (niov < NIOVMAX);
-      if ((iov[niov].iov_len = fmt - startp) != 0)
-	iov[niov++].iov_base = (char *) startp;
-
-      if (*fmt == '%')
-	{
-	  /* It is a format specifier.  */
-	  char fill = ' ';
-	  int width = -1;
-	  int prec = -1;
-#if LONG_MAX != INT_MAX
-	  int long_mod = 0;
-#endif
-
-	  /* Recognize zero-digit fill flag.  */
-	  if (*++fmt == '0')
-	    {
-	      fill = '0';
-	      ++fmt;
-	    }
-
-	  /* See whether with comes from a parameter.  Note that no other
-	     way to specify the width is implemented.  */
-	  if (*fmt == '*')
-	    {
-	      width = va_arg (arg, int);
-	      ++fmt;
-	    }
-
-	  /* Handle precision.  */
-	  if (*fmt == '.' && fmt[1] == '*')
-	    {
-	      prec = va_arg (arg, int);
-	      fmt += 2;
-	    }
-
-	  /* Recognize the l modifier.  It is only important on some
-	     platforms where long and int have a different size.  We
-	     can use the same code for size_t.  */
-	  if (*fmt == 'l' || *fmt == 'Z')
-	    {
-#if LONG_MAX != INT_MAX
-	      long_mod = 1;
-#endif
-	      ++fmt;
-	    }
-
-	  switch (*fmt)
-	    {
-	      /* Integer formatting.  */
-	    case 'd':
-	    case 'u':
-	    case 'x':
-	      {
-		/* We have to make a difference if long and int have a
-		   different size.  */
-#if LONG_MAX != INT_MAX
-		unsigned long int num = (long_mod
-					 ? va_arg (arg, unsigned long int)
-					 : va_arg (arg, unsigned int));
-#else
-		unsigned long int num = va_arg (arg, unsigned int);
-#endif
-		bool negative = false;
-		if (*fmt == 'd')
-		  {
-#if LONG_MAX != INT_MAX
-		    if (long_mod)
-		      {
-			if ((long int) num < 0)
-			  negative = true;
-		      }
-		    else
-		      {
-			if ((int) num < 0)
-			  {
-			    num = (unsigned int) num;
-			    negative = true;
-			  }
-		      }
-#else
-		    if ((int) num < 0)
-		      negative = true;
-#endif
-		  }
-
-		/* We use alloca() to allocate the buffer with the most
-		   pessimistic guess for the size.  Using alloca() allows
-		   having more than one integer formatting in a call.  */
-		char *buf = (char *) alloca (1 + 3 * sizeof (unsigned long int));
-		char *endp = &buf[1 + 3 * sizeof (unsigned long int)];
-		char *cp = _itoa (num, endp, *fmt == 'x' ? 16 : 10, 0);
-
-		/* Pad to the width the user specified.  */
-		if (width != -1)
-		  while (endp - cp < width)
-		    *--cp = fill;
-
-		if (negative)
-		  *--cp = '-';
-
-		iov[niov].iov_base = cp;
-		iov[niov].iov_len = endp - cp;
-		++niov;
-	      }
-	      break;
-
-	    case 's':
-	      /* Get the string argument.  */
-	      iov[niov].iov_base = va_arg (arg, char *);
-	      iov[niov].iov_len = strlen (iov[niov].iov_base);
-	      if (prec != -1)
-		iov[niov].iov_len = MIN ((size_t) prec, iov[niov].iov_len);
-	      ++niov;
-	      break;
-
-	    case '%':
-	      iov[niov].iov_base = (void *) fmt;
-	      iov[niov].iov_len = 1;
-	      ++niov;
-	      break;
-
-	    default:
-	      assert (! "invalid format specifier");
-	    }
-	  ++fmt;
-	}
-      else if (*fmt == '\n')
-	{
-	  /* See whether we have to print a single newline character.  */
-	  if (fmt == startp)
-	    {
-	      iov[niov].iov_base = (char *) startp;
-	      iov[niov++].iov_len = 1;
-	    }
-	  else
-	    /* No, just add it to the rest of the string.  */
-	    ++iov[niov - 1].iov_len;
-
-	  /* Next line, print a tag again.  */
-	  tag_p = 1;
-	  ++fmt;
-	}
-    }
-
-  /* Finally write the result.  */
-  _dl_writev (fd, iov, niov);
-}
-
-
-/* Write to debug file.  */
-void
-_dl_debug_printf (const char *fmt, ...)
-{
-  va_list arg;
-
-  va_start (arg, fmt);
-  _dl_debug_vdprintf (GLRO(dl_debug_fd), 1, fmt, arg);
-  va_end (arg);
-}
-
-
-/* Write to debug file but don't start with a tag.  */
-void
-_dl_debug_printf_c (const char *fmt, ...)
-{
-  va_list arg;
-
-  va_start (arg, fmt);
-  _dl_debug_vdprintf (GLRO(dl_debug_fd), -1, fmt, arg);
-  va_end (arg);
-}
-
-
-/* Write the given file descriptor.  */
-void
-_dl_dprintf (int fd, const char *fmt, ...)
-{
-  va_list arg;
-
-  va_start (arg, fmt);
-  _dl_debug_vdprintf (fd, 0, fmt, arg);
-  va_end (arg);
-}
-
-void
-_dl_printf (const char *fmt, ...)
-{
-  va_list arg;
-
-  va_start (arg, fmt);
-  _dl_debug_vdprintf (STDOUT_FILENO, 0, fmt, arg);
-  va_end (arg);
-}
-
-void
-_dl_error_printf (const char *fmt, ...)
-{
-  va_list arg;
-
-  va_start (arg, fmt);
-  _dl_debug_vdprintf (STDERR_FILENO, 0, fmt, arg);
-  va_end (arg);
-}
-
-void
-_dl_fatal_printf (const char *fmt, ...)
-{
-  va_list arg;
-
-  va_start (arg, fmt);
-  _dl_debug_vdprintf (STDERR_FILENO, 0, fmt, arg);
-  va_end (arg);
-  _exit (127);
-}
-rtld_hidden_def (_dl_fatal_printf)
-
 /* Test whether given NAME matches any of the names of the given object.  */
 int
 _dl_name_match_p (const char *name, const struct link_map *map)
@@ -354,7 +82,6 @@ _dl_name_match_p (const char *name, const struct link_map *map)
   return 0;
 }
 
-
 unsigned long int
 _dl_higher_prime_number (unsigned long int n)
 {
diff --git a/elf/dl-printf.c b/elf/dl-printf.c
new file mode 100644
index 0000000000..d3264ba96c
--- /dev/null
+++ b/elf/dl-printf.c
@@ -0,0 +1,292 @@
+/* printf implementation for the dynamic loader.
+   Copyright (C) 1997-2022 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 <_itoa.h>
+#include <assert.h>
+#include <dl-writev.h>
+#include <ldsodefs.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/uio.h>
+#include <unistd.h>
+
+/* Bare-bones printf implementation.  This function only knows about
+   the formats and flags needed and can handle only up to 64 stripes in
+   the output.  */
+static void
+_dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg)
+{
+# define NIOVMAX 64
+  struct iovec iov[NIOVMAX];
+  int niov = 0;
+  pid_t pid = 0;
+  char pidbuf[12];
+
+  while (*fmt != '\0')
+    {
+      const char *startp = fmt;
+
+      if (tag_p > 0)
+	{
+	  /* Generate the tag line once.  It consists of the PID and a
+	     colon followed by a tab.  */
+	  if (pid == 0)
+	    {
+	      char *p;
+	      pid = __getpid ();
+	      assert (pid >= 0 && sizeof (pid_t) <= 4);
+	      p = _itoa (pid, &pidbuf[10], 10, 0);
+	      while (p > pidbuf)
+		*--p = ' ';
+	      pidbuf[10] = ':';
+	      pidbuf[11] = '\t';
+	    }
+
+	  /* Append to the output.  */
+	  assert (niov < NIOVMAX);
+	  iov[niov].iov_len = 12;
+	  iov[niov++].iov_base = pidbuf;
+
+	  /* No more tags until we see the next newline.  */
+	  tag_p = -1;
+	}
+
+      /* Skip everything except % and \n (if tags are needed).  */
+      while (*fmt != '\0' && *fmt != '%' && (! tag_p || *fmt != '\n'))
+	++fmt;
+
+      /* Append constant string.  */
+      assert (niov < NIOVMAX);
+      if ((iov[niov].iov_len = fmt - startp) != 0)
+	iov[niov++].iov_base = (char *) startp;
+
+      if (*fmt == '%')
+	{
+	  /* It is a format specifier.  */
+	  char fill = ' ';
+	  int width = -1;
+	  int prec = -1;
+#if LONG_MAX != INT_MAX
+	  int long_mod = 0;
+#endif
+
+	  /* Recognize zero-digit fill flag.  */
+	  if (*++fmt == '0')
+	    {
+	      fill = '0';
+	      ++fmt;
+	    }
+
+	  /* See whether with comes from a parameter.  Note that no other
+	     way to specify the width is implemented.  */
+	  if (*fmt == '*')
+	    {
+	      width = va_arg (arg, int);
+	      ++fmt;
+	    }
+
+	  /* Handle precision.  */
+	  if (*fmt == '.' && fmt[1] == '*')
+	    {
+	      prec = va_arg (arg, int);
+	      fmt += 2;
+	    }
+
+	  /* Recognize the l modifier.  It is only important on some
+	     platforms where long and int have a different size.  We
+	     can use the same code for size_t.  */
+	  if (*fmt == 'l' || *fmt == 'Z')
+	    {
+#if LONG_MAX != INT_MAX
+	      long_mod = 1;
+#endif
+	      ++fmt;
+	    }
+
+	  switch (*fmt)
+	    {
+	      /* Integer formatting.  */
+	    case 'd':
+	    case 'u':
+	    case 'x':
+	      {
+		/* We have to make a difference if long and int have a
+		   different size.  */
+#if LONG_MAX != INT_MAX
+		unsigned long int num = (long_mod
+					 ? va_arg (arg, unsigned long int)
+					 : va_arg (arg, unsigned int));
+#else
+		unsigned long int num = va_arg (arg, unsigned int);
+#endif
+		bool negative = false;
+		if (*fmt == 'd')
+		  {
+#if LONG_MAX != INT_MAX
+		    if (long_mod)
+		      {
+			if ((long int) num < 0)
+			  negative = true;
+		      }
+		    else
+		      {
+			if ((int) num < 0)
+			  {
+			    num = (unsigned int) num;
+			    negative = true;
+			  }
+		      }
+#else
+		    if ((int) num < 0)
+		      negative = true;
+#endif
+		  }
+
+		/* We use alloca() to allocate the buffer with the most
+		   pessimistic guess for the size.  Using alloca() allows
+		   having more than one integer formatting in a call.  */
+		char *buf = (char *) alloca (1 + 3 * sizeof (unsigned long int));
+		char *endp = &buf[1 + 3 * sizeof (unsigned long int)];
+		char *cp = _itoa (num, endp, *fmt == 'x' ? 16 : 10, 0);
+
+		/* Pad to the width the user specified.  */
+		if (width != -1)
+		  while (endp - cp < width)
+		    *--cp = fill;
+
+		if (negative)
+		  *--cp = '-';
+
+		iov[niov].iov_base = cp;
+		iov[niov].iov_len = endp - cp;
+		++niov;
+	      }
+	      break;
+
+	    case 's':
+	      /* Get the string argument.  */
+	      iov[niov].iov_base = va_arg (arg, char *);
+	      iov[niov].iov_len = strlen (iov[niov].iov_base);
+	      if (prec != -1)
+		iov[niov].iov_len = MIN ((size_t) prec, iov[niov].iov_len);
+	      ++niov;
+	      break;
+
+	    case '%':
+	      iov[niov].iov_base = (void *) fmt;
+	      iov[niov].iov_len = 1;
+	      ++niov;
+	      break;
+
+	    default:
+	      assert (! "invalid format specifier");
+	    }
+	  ++fmt;
+	}
+      else if (*fmt == '\n')
+	{
+	  /* See whether we have to print a single newline character.  */
+	  if (fmt == startp)
+	    {
+	      iov[niov].iov_base = (char *) startp;
+	      iov[niov++].iov_len = 1;
+	    }
+	  else
+	    /* No, just add it to the rest of the string.  */
+	    ++iov[niov - 1].iov_len;
+
+	  /* Next line, print a tag again.  */
+	  tag_p = 1;
+	  ++fmt;
+	}
+    }
+
+  /* Finally write the result.  */
+  _dl_writev (fd, iov, niov);
+}
+
+
+/* Write to debug file.  */
+void
+_dl_debug_printf (const char *fmt, ...)
+{
+  va_list arg;
+
+  va_start (arg, fmt);
+  _dl_debug_vdprintf (GLRO(dl_debug_fd), 1, fmt, arg);
+  va_end (arg);
+}
+
+
+/* Write to debug file but don't start with a tag.  */
+void
+_dl_debug_printf_c (const char *fmt, ...)
+{
+  va_list arg;
+
+  va_start (arg, fmt);
+  _dl_debug_vdprintf (GLRO(dl_debug_fd), -1, fmt, arg);
+  va_end (arg);
+}
+
+
+/* Write the given file descriptor.  */
+void
+_dl_dprintf (int fd, const char *fmt, ...)
+{
+  va_list arg;
+
+  va_start (arg, fmt);
+  _dl_debug_vdprintf (fd, 0, fmt, arg);
+  va_end (arg);
+}
+
+void
+_dl_printf (const char *fmt, ...)
+{
+  va_list arg;
+
+  va_start (arg, fmt);
+  _dl_debug_vdprintf (STDOUT_FILENO, 0, fmt, arg);
+  va_end (arg);
+}
+
+void
+_dl_error_printf (const char *fmt, ...)
+{
+  va_list arg;
+
+  va_start (arg, fmt);
+  _dl_debug_vdprintf (STDERR_FILENO, 0, fmt, arg);
+  va_end (arg);
+}
+
+void
+_dl_fatal_printf (const char *fmt, ...)
+{
+  va_list arg;
+
+  va_start (arg, fmt);
+  _dl_debug_vdprintf (STDERR_FILENO, 0, fmt, arg);
+  va_end (arg);
+  _exit (127);
+}
+rtld_hidden_def (_dl_fatal_printf)
-- 
2.34.1



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 3/6] Add --with-rtld-early-cflags configure option
  2022-01-14 16:51 [PATCH v2 0/6] Reliable CPU compatibility diagnostics in ld.so Florian Weimer
  2022-01-14 16:52 ` [PATCH v2 1/6] elf/Makefile: Reflow and sort most variable assignments Florian Weimer
  2022-01-14 16:52 ` [PATCH v2 2/6] elf: Split dl-printf.c from dl-misc.c Florian Weimer
@ 2022-01-14 16:52 ` Florian Weimer
  2022-01-14 18:38   ` H.J. Lu
  2022-01-14 16:53 ` [PATCH v2 4/6] powerpc64le: Use <gcc-macros.h> in early HWCAP check Florian Weimer
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Florian Weimer @ 2022-01-14 16:52 UTC (permalink / raw)
  To: libc-alpha

---
v2: Rename configure option.  Regenerate INSTALL.
 INSTALL             |  8 ++++++++
 config.make.in      |  1 +
 configure           | 13 +++++++++++++
 configure.ac        |  6 ++++++
 elf/Makefile        |  8 ++++++++
 manual/install.texi |  7 +++++++
 6 files changed, 43 insertions(+)

diff --git a/INSTALL b/INSTALL
index 331d405e56..a9dc12fa31 100644
--- a/INSTALL
+++ b/INSTALL
@@ -106,6 +106,14 @@ if 'CFLAGS' is specified it must enable optimization.  For example:
      particular case and potentially change debugging information and
      metadata only).
 
+'--with-rtld-early-cflags=CFLAGS'
+     Use additional compiler flags CFLAGS to build the early startup
+     code of the dynamic linker.  These flags can be used to enable
+     early dynamic linker diagnostics to run on CPUs which are not
+     compatible with the rest of the GNU C Library, for example, due to
+     compiler flags which target a later instruction set architecture
+     (ISA).
+
 '--with-timeoutfactor=NUM'
      Specify an integer NUM to scale the timeout of test programs.  This
      factor can be changed at run time using 'TIMEOUTFACTOR' environment
diff --git a/config.make.in b/config.make.in
index e8630a8d0c..6d43e691f7 100644
--- a/config.make.in
+++ b/config.make.in
@@ -110,6 +110,7 @@ CFLAGS = @CFLAGS@
 CPPFLAGS-config = @CPPFLAGS@
 CPPUNDEFS = @CPPUNDEFS@
 extra-nonshared-cflags = @extra_nonshared_cflags@
+rtld-early-cflags = @rtld_early_cflags@
 ASFLAGS-config = @ASFLAGS_config@
 AR = @AR@
 NM = @NM@
diff --git a/configure b/configure
index 3f956cf777..6a7e5c6164 100755
--- a/configure
+++ b/configure
@@ -681,6 +681,7 @@ force_install
 bindnow
 hardcoded_path_in_tests
 enable_timezone_tools
+rtld_early_cflags
 extra_nonshared_cflags
 use_default_link
 sysheaders
@@ -761,6 +762,7 @@ with_selinux
 with_headers
 with_default_link
 with_nonshared_cflags
+with_rtld_early_cflags
 with_timeoutfactor
 enable_sanity_checks
 enable_shared
@@ -1480,6 +1482,8 @@ Optional Packages:
   --with-default-link     do not use explicit linker scripts
   --with-nonshared-cflags=CFLAGS
                           build nonshared libraries with additional CFLAGS
+  --with-rtld-early-cflags=CFLAGS
+                          build early initialization with additional CFLAGS
   --with-timeoutfactor=NUM
                           specify an integer to scale the timeout
   --with-cpu=CPU          select code for CPU variant
@@ -3386,6 +3390,15 @@ fi
 
 
 
+# Check whether --with-rtld-early-cflags was given.
+if test "${with_rtld_early_cflags+set}" = set; then :
+  withval=$with_rtld_early_cflags; rtld_early_cflags=$withval
+else
+  rtld_early_cflags=
+fi
+
+
+
 
 # Check whether --with-timeoutfactor was given.
 if test "${with_timeoutfactor+set}" = set; then :
diff --git a/configure.ac b/configure.ac
index 277d3527d2..40f2de1661 100644
--- a/configure.ac
+++ b/configure.ac
@@ -162,6 +162,12 @@ AC_ARG_WITH([nonshared-cflags],
 	    [extra_nonshared_cflags=$withval],
 	    [extra_nonshared_cflags=])
 AC_SUBST(extra_nonshared_cflags)
+AC_ARG_WITH([rtld-early-cflags],
+	    AS_HELP_STRING([--with-rtld-early-cflags=CFLAGS],
+			   [build early initialization with additional CFLAGS]),
+	    [rtld_early_cflags=$withval],
+	    [rtld_early_cflags=])
+AC_SUBST(rtld_early_cflags)
 
 AC_ARG_WITH([timeoutfactor],
 	    AS_HELP_STRING([--with-timeoutfactor=NUM],
diff --git a/elf/Makefile b/elf/Makefile
index 3df49742ff..e6a28b243b 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -167,6 +167,14 @@ CFLAGS-.o += $(call elide-stack-protector,.o,$(elide-routines.os))
 CFLAGS-.op += $(call elide-stack-protector,.op,$(elide-routines.os))
 CFLAGS-.os += $(call elide-stack-protector,.os,$(all-rtld-routines))
 
+# Add the requested compiler flags to the early startup code.
+CFLAGS-dl-printf.os += $(rtld-early-cflags)
+CFLAGS-dl-sysdep.os += $(rtld-early-cflags)
+CFLAGS-dl-tunables.os += $(rtld-early-cflags)
+CFLAGS-dl-write.os += $(rtld-early-cflags)
+CFLAGS-dl-writev.os += $(rtld-early-cflags)
+CFLAGS-rtld.os += $(rtld-early-cflags)
+
 ifeq ($(unwind-find-fde),yes)
 routines += unwind-dw2-fde-glibc
 shared-only-routines += unwind-dw2-fde-glibc
diff --git a/manual/install.texi b/manual/install.texi
index b1afc56f5a..accaef45fa 100644
--- a/manual/install.texi
+++ b/manual/install.texi
@@ -131,6 +131,13 @@ that the objects in @file{libc_nonshared.a} are compiled with this flag
 (although this will not affect the generated code in this particular
 case and potentially change debugging information and metadata only).
 
+@item --with-rtld-early-cflags=@var{cflags}
+Use additional compiler flags @var{cflags} to build the early startup
+code of the dynamic linker.  These flags can be used to enable early
+dynamic linker diagnostics to run on CPUs which are not compatible with
+the rest of @theglibc{}, for example, due to compiler flags which target
+a later instruction set architecture (ISA).
+
 @item --with-timeoutfactor=@var{NUM}
 Specify an integer @var{NUM} to scale the timeout of test programs.
 This factor can be changed at run time using @env{TIMEOUTFACTOR}
-- 
2.34.1



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 4/6] powerpc64le: Use <gcc-macros.h> in early HWCAP check
  2022-01-14 16:51 [PATCH v2 0/6] Reliable CPU compatibility diagnostics in ld.so Florian Weimer
                   ` (2 preceding siblings ...)
  2022-01-14 16:52 ` [PATCH v2 3/6] Add --with-rtld-early-cflags configure option Florian Weimer
@ 2022-01-14 16:53 ` Florian Weimer
  2022-01-14 18:51   ` Carlos O'Donell
  2022-01-14 16:53 ` [PATCH v2 5/6] x86: Add x86-64-vN check to early startup Florian Weimer
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Florian Weimer @ 2022-01-14 16:53 UTC (permalink / raw)
  To: libc-alpha

This is required so that the checks still work if $(early-cflags)
selects a different ISA level.
---
 sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h b/sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h
index 713a7f0313..b43c182683 100644
--- a/sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h
+++ b/sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h
@@ -19,17 +19,18 @@
 #ifndef _DL_HWCAP_CHECK_H
 #define _DL_HWCAP_CHECK_H
 
+#include <gcc-macros.h>
 #include <ldsodefs.h>
 
 static inline void
 dl_hwcap_check (void)
 {
-#ifdef _ARCH_PWR9
+#ifdef GCCMACRO_ARCH_PWR9
   if ((GLRO (dl_hwcap2) & PPC_FEATURE2_ARCH_3_00) == 0)
     _dl_fatal_printf ("\
 Fatal glibc error: CPU lacks ISA 3.00 support (POWER9 or later required)\n");
 #endif
-#ifdef __FLOAT128_HARDWARE__
+#ifdef GCCMACRO__FLOAT128_HARDWARE__
   if ((GLRO (dl_hwcap2) & PPC_FEATURE2_HAS_IEEE128) == 0)
     _dl_fatal_printf ("\
 Fatal glibc error: CPU lacks float128 support (POWER 9 or later required)\n");
@@ -37,12 +38,12 @@ Fatal glibc error: CPU lacks float128 support (POWER 9 or later required)\n");
    /* This check is not actually reached when building for POWER10 and
       running on POWER9 because there are faulting PCREL instructions
       before this point.  */
-#if defined _ARCH_PWR10 || defined __PCREL__
+#if defined GCCMACRO_ARCH_PWR10 || defined GCCMACRO__PCREL__
   if ((GLRO (dl_hwcap2) & PPC_FEATURE2_ARCH_3_1) == 0)
     _dl_fatal_printf ("\
 Fatal glibc error: CPU lacks ISA 3.10 support (POWER10 or later required)\n");
 #endif
-#ifdef __MMA__
+#ifdef GCCMACRO__MMA__
   if ((GLRO (dl_hwcap2) & PPC_FEATURE2_MMA) == 0)
     _dl_fatal_printf ("\
 Fatal glibc error: CPU lacks MMA support (POWER10 or later required)\n");
-- 
2.34.1



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 5/6] x86: Add x86-64-vN check to early startup
  2022-01-14 16:51 [PATCH v2 0/6] Reliable CPU compatibility diagnostics in ld.so Florian Weimer
                   ` (3 preceding siblings ...)
  2022-01-14 16:53 ` [PATCH v2 4/6] powerpc64le: Use <gcc-macros.h> in early HWCAP check Florian Weimer
@ 2022-01-14 16:53 ` Florian Weimer
  2022-01-14 18:40   ` H.J. Lu
  2022-01-14 16:53 ` [PATCH 6/6] s390x: Use <gcc-macros.h> in early HWCAP check Florian Weimer
  2022-01-14 17:42 ` [PATCH v2 0/6] Reliable CPU compatibility diagnostics in ld.so Joseph Myers
  6 siblings, 1 reply; 16+ messages in thread
From: Florian Weimer @ 2022-01-14 16:53 UTC (permalink / raw)
  To: libc-alpha

This ISA level covers the glibc build itself.  <dl-hwcap-check.h>
cannot be used because this check (by design) happens before
DL_PLATFORM_INIT and the x86 CPU flags initialization.
---
v2: Reflect renamed Makefile variable.
 sysdeps/x86/Makefile              |  1 +
 sysdeps/x86/dl-get-cpu-features.c | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
index 402986ff68..6cf708335c 100644
--- a/sysdeps/x86/Makefile
+++ b/sysdeps/x86/Makefile
@@ -7,6 +7,7 @@ sysdep_routines += get-cpuid-feature-leaf
 sysdep-dl-routines += dl-get-cpu-features
 sysdep_headers += sys/platform/x86.h bits/platform/x86.h
 
+CFLAGS-dl-get-cpu-features.os += $(rtld-early-cflags)
 CFLAGS-get-cpuid-feature-leaf.o += $(no-stack-protector)
 
 tests += tst-get-cpu-features tst-get-cpu-features-static \
diff --git a/sysdeps/x86/dl-get-cpu-features.c b/sysdeps/x86/dl-get-cpu-features.c
index 6339c9df4e..4ec0e5d2af 100644
--- a/sysdeps/x86/dl-get-cpu-features.c
+++ b/sysdeps/x86/dl-get-cpu-features.c
@@ -20,6 +20,7 @@
 
 #ifdef SHARED
 # include <cpu-features.c>
+# include <gcc-macros.h>
 
 /* NB: Normally, DL_PLATFORM_INIT calls init_cpu_features to initialize
    CPU features in dynamic executable.  But when loading ld.so inside of
@@ -36,7 +37,35 @@ _dl_x86_init_cpu_features (void)
 {
   struct cpu_features *cpu_features = __get_cpu_features ();
   if (cpu_features->basic.kind == arch_kind_unknown)
-    init_cpu_features (cpu_features);
+    {
+      init_cpu_features (cpu_features);
+
+# if IS_IN (rtld)
+      /* See isa-level.c.  */
+#  if defined GCCMACRO__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16		\
+  && defined HAVE_X86_LAHF_SAHF && defined GCCMACRO__POPCNT__		\
+  && defined GCCMACRO__SSE3__ && defined GCCMACRO__SSSE3__		\
+  && defined GCCMACRO__SSE4_1__ && defined GCCMACRO__SSE4_2__
+      if (!(cpu_features->isa_1 & GNU_PROPERTY_X86_ISA_1_V2))
+	_dl_fatal_printf ("\
+Fatal glibc error: CPU does not support x86-64-v%d\n", 2);
+#   if defined GCCMACRO__AVX__ && defined GCCMACRO__AVX2__ \
+  && defined GCCMACRO__F16C__ && defined GCCMACRO__FMA__   \
+  && defined GCCMACRO__LZCNT__ && defined HAVE_X86_MOVBE
+      if (!(cpu_features->isa_1 & GNU_PROPERTY_X86_ISA_1_V3))
+	_dl_fatal_printf ("\
+Fatal glibc error: CPU does not support x86-64-v%d\n", 3);
+#    if defined GCCMACRO__AVX512F__ && defined GCCMACRO__AVX512BW__ \
+     && defined GCCMACRO__AVX512CD__ && defined GCCMACRO__AVX512DQ__ \
+     && defined GCCMACRO__AVX512VL__
+      if (!(cpu_features->isa_1 & GNU_PROPERTY_X86_ISA_1_V4))
+	_dl_fatal_printf ("\
+Fatal glibc error: CPU does not support x86-64-v%d\n", 4);
+#    endif /* ISA level 4 */
+#   endif /* ISA level 3 */
+#  endif /* ISA level 2 */
+# endif /* IS_IN (rtld) */
+    }
 }
 
 __ifunc (__x86_cpu_features, __x86_cpu_features, NULL, void,
-- 
2.34.1



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 6/6] s390x: Use <gcc-macros.h> in early HWCAP check
  2022-01-14 16:51 [PATCH v2 0/6] Reliable CPU compatibility diagnostics in ld.so Florian Weimer
                   ` (4 preceding siblings ...)
  2022-01-14 16:53 ` [PATCH v2 5/6] x86: Add x86-64-vN check to early startup Florian Weimer
@ 2022-01-14 16:53 ` Florian Weimer
  2022-01-14 18:52   ` Carlos O'Donell
  2022-01-14 17:42 ` [PATCH v2 0/6] Reliable CPU compatibility diagnostics in ld.so Joseph Myers
  6 siblings, 1 reply; 16+ messages in thread
From: Florian Weimer @ 2022-01-14 16:53 UTC (permalink / raw)
  To: libc-alpha

This is required so that the checks still work if $(early-cflags)
selects a different ISA level.
---
 sysdeps/s390/s390-64/dl-hwcap-check.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sysdeps/s390/s390-64/dl-hwcap-check.h b/sysdeps/s390/s390-64/dl-hwcap-check.h
index 53e02250b8..f769932325 100644
--- a/sysdeps/s390/s390-64/dl-hwcap-check.h
+++ b/sysdeps/s390/s390-64/dl-hwcap-check.h
@@ -19,17 +19,18 @@
 #ifndef _DL_HWCAP_CHECK_H
 #define _DL_HWCAP_CHECK_H
 
+#include <gcc-macros.h>
 #include <ldsodefs.h>
 
 static inline void
 dl_hwcap_check (void)
 {
 #if defined __ARCH__
-# if __ARCH__ >= 13
+# if GCCMACRO__ARCH__ >= 13
   if (!(GLRO(dl_hwcap) & HWCAP_S390_VXRS_EXT2))
     _dl_fatal_printf ("\
 Fatal glibc error: CPU lacks VXRS_EXT2 support (z15 or later required)\n");
-# elif __ARCH__ >= 12
+# elif GCCMACRO__ARCH__ >= 12
   if (!(GLRO(dl_hwcap) & HWCAP_S390_VXE))
     _dl_fatal_printf ("\
 Fatal glibc error: CPU lacks VXE support (z14 or later required)\n");
-- 
2.34.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 0/6] Reliable CPU compatibility diagnostics in ld.so
  2022-01-14 16:51 [PATCH v2 0/6] Reliable CPU compatibility diagnostics in ld.so Florian Weimer
                   ` (5 preceding siblings ...)
  2022-01-14 16:53 ` [PATCH 6/6] s390x: Use <gcc-macros.h> in early HWCAP check Florian Weimer
@ 2022-01-14 17:42 ` Joseph Myers
  2022-01-14 17:59   ` Florian Weimer
  6 siblings, 1 reply; 16+ messages in thread
From: Joseph Myers @ 2022-01-14 17:42 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha

I think there should be a NEWS entry for the new feature and configure 
option.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 0/6] Reliable CPU compatibility diagnostics in ld.so
  2022-01-14 17:42 ` [PATCH v2 0/6] Reliable CPU compatibility diagnostics in ld.so Joseph Myers
@ 2022-01-14 17:59   ` Florian Weimer
  2022-01-14 18:51     ` Carlos O'Donell
  0 siblings, 1 reply; 16+ messages in thread
From: Florian Weimer @ 2022-01-14 17:59 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha

* Joseph Myers:

> I think there should be a NEWS entry for the new feature and configure 
> option.

Fair enough.  I'm going to add:

* A new configure option, --with-rtld-early-cflags, can be used to
  specify additional compiler flags for building the early startup code
  of the dynamic linker.  On targets which have CPU compatibility
  checks, this can help to ensure that proper diagnostics are printed if
  the dynamic loader runs on an incompatible CPU.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 3/6] Add --with-rtld-early-cflags configure option
  2022-01-14 16:52 ` [PATCH v2 3/6] Add --with-rtld-early-cflags configure option Florian Weimer
@ 2022-01-14 18:38   ` H.J. Lu
  0 siblings, 0 replies; 16+ messages in thread
From: H.J. Lu @ 2022-01-14 18:38 UTC (permalink / raw)
  To: Florian Weimer; +Cc: GNU C Library

On Fri, Jan 14, 2022 at 8:54 AM Florian Weimer via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> ---
> v2: Rename configure option.  Regenerate INSTALL.
>  INSTALL             |  8 ++++++++
>  config.make.in      |  1 +
>  configure           | 13 +++++++++++++
>  configure.ac        |  6 ++++++
>  elf/Makefile        |  8 ++++++++
>  manual/install.texi |  7 +++++++
>  6 files changed, 43 insertions(+)
>
> diff --git a/INSTALL b/INSTALL
> index 331d405e56..a9dc12fa31 100644
> --- a/INSTALL
> +++ b/INSTALL
> @@ -106,6 +106,14 @@ if 'CFLAGS' is specified it must enable optimization.  For example:
>       particular case and potentially change debugging information and
>       metadata only).
>
> +'--with-rtld-early-cflags=CFLAGS'
> +     Use additional compiler flags CFLAGS to build the early startup
> +     code of the dynamic linker.  These flags can be used to enable
> +     early dynamic linker diagnostics to run on CPUs which are not
> +     compatible with the rest of the GNU C Library, for example, due to
> +     compiler flags which target a later instruction set architecture
> +     (ISA).
> +
>  '--with-timeoutfactor=NUM'
>       Specify an integer NUM to scale the timeout of test programs.  This
>       factor can be changed at run time using 'TIMEOUTFACTOR' environment
> diff --git a/config.make.in b/config.make.in
> index e8630a8d0c..6d43e691f7 100644
> --- a/config.make.in
> +++ b/config.make.in
> @@ -110,6 +110,7 @@ CFLAGS = @CFLAGS@
>  CPPFLAGS-config = @CPPFLAGS@
>  CPPUNDEFS = @CPPUNDEFS@
>  extra-nonshared-cflags = @extra_nonshared_cflags@
> +rtld-early-cflags = @rtld_early_cflags@
>  ASFLAGS-config = @ASFLAGS_config@
>  AR = @AR@
>  NM = @NM@
> diff --git a/configure b/configure
> index 3f956cf777..6a7e5c6164 100755
> --- a/configure
> +++ b/configure
> @@ -681,6 +681,7 @@ force_install
>  bindnow
>  hardcoded_path_in_tests
>  enable_timezone_tools
> +rtld_early_cflags
>  extra_nonshared_cflags
>  use_default_link
>  sysheaders
> @@ -761,6 +762,7 @@ with_selinux
>  with_headers
>  with_default_link
>  with_nonshared_cflags
> +with_rtld_early_cflags
>  with_timeoutfactor
>  enable_sanity_checks
>  enable_shared
> @@ -1480,6 +1482,8 @@ Optional Packages:
>    --with-default-link     do not use explicit linker scripts
>    --with-nonshared-cflags=CFLAGS
>                            build nonshared libraries with additional CFLAGS
> +  --with-rtld-early-cflags=CFLAGS
> +                          build early initialization with additional CFLAGS
>    --with-timeoutfactor=NUM
>                            specify an integer to scale the timeout
>    --with-cpu=CPU          select code for CPU variant
> @@ -3386,6 +3390,15 @@ fi
>
>
>
> +# Check whether --with-rtld-early-cflags was given.
> +if test "${with_rtld_early_cflags+set}" = set; then :
> +  withval=$with_rtld_early_cflags; rtld_early_cflags=$withval
> +else
> +  rtld_early_cflags=
> +fi
> +
> +
> +
>
>  # Check whether --with-timeoutfactor was given.
>  if test "${with_timeoutfactor+set}" = set; then :
> diff --git a/configure.ac b/configure.ac
> index 277d3527d2..40f2de1661 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -162,6 +162,12 @@ AC_ARG_WITH([nonshared-cflags],
>             [extra_nonshared_cflags=$withval],
>             [extra_nonshared_cflags=])
>  AC_SUBST(extra_nonshared_cflags)
> +AC_ARG_WITH([rtld-early-cflags],
> +           AS_HELP_STRING([--with-rtld-early-cflags=CFLAGS],
> +                          [build early initialization with additional CFLAGS]),
> +           [rtld_early_cflags=$withval],
> +           [rtld_early_cflags=])
> +AC_SUBST(rtld_early_cflags)
>
>  AC_ARG_WITH([timeoutfactor],
>             AS_HELP_STRING([--with-timeoutfactor=NUM],
> diff --git a/elf/Makefile b/elf/Makefile
> index 3df49742ff..e6a28b243b 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -167,6 +167,14 @@ CFLAGS-.o += $(call elide-stack-protector,.o,$(elide-routines.os))
>  CFLAGS-.op += $(call elide-stack-protector,.op,$(elide-routines.os))
>  CFLAGS-.os += $(call elide-stack-protector,.os,$(all-rtld-routines))
>
> +# Add the requested compiler flags to the early startup code.
> +CFLAGS-dl-printf.os += $(rtld-early-cflags)
> +CFLAGS-dl-sysdep.os += $(rtld-early-cflags)
> +CFLAGS-dl-tunables.os += $(rtld-early-cflags)
> +CFLAGS-dl-write.os += $(rtld-early-cflags)
> +CFLAGS-dl-writev.os += $(rtld-early-cflags)
> +CFLAGS-rtld.os += $(rtld-early-cflags)
> +
>  ifeq ($(unwind-find-fde),yes)
>  routines += unwind-dw2-fde-glibc
>  shared-only-routines += unwind-dw2-fde-glibc
> diff --git a/manual/install.texi b/manual/install.texi
> index b1afc56f5a..accaef45fa 100644
> --- a/manual/install.texi
> +++ b/manual/install.texi
> @@ -131,6 +131,13 @@ that the objects in @file{libc_nonshared.a} are compiled with this flag
>  (although this will not affect the generated code in this particular
>  case and potentially change debugging information and metadata only).
>
> +@item --with-rtld-early-cflags=@var{cflags}
> +Use additional compiler flags @var{cflags} to build the early startup
> +code of the dynamic linker.  These flags can be used to enable early
> +dynamic linker diagnostics to run on CPUs which are not compatible with
> +the rest of @theglibc{}, for example, due to compiler flags which target
> +a later instruction set architecture (ISA).
> +
>  @item --with-timeoutfactor=@var{NUM}
>  Specify an integer @var{NUM} to scale the timeout of test programs.
>  This factor can be changed at run time using @env{TIMEOUTFACTOR}
> --
> 2.34.1
>
>

LGTM.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 1/6] elf/Makefile: Reflow and sort most variable assignments
  2022-01-14 16:52 ` [PATCH v2 1/6] elf/Makefile: Reflow and sort most variable assignments Florian Weimer
@ 2022-01-14 18:39   ` H.J. Lu
  0 siblings, 0 replies; 16+ messages in thread
From: H.J. Lu @ 2022-01-14 18:39 UTC (permalink / raw)
  To: Florian Weimer; +Cc: GNU C Library

On Fri, Jan 14, 2022 at 8:53 AM Florian Weimer via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> ---
> v2: new patch
>  elf/Makefile | 420 ++++++++++++++++++++++++++++++++++++++-------------
>  1 file changed, 318 insertions(+), 102 deletions(-)
>
> diff --git a/elf/Makefile b/elf/Makefile
> index b86d116be9..3065efc485 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -21,24 +21,67 @@ subdir              := elf
>
>  include ../Makeconfig
>
> -headers                = elf.h bits/elfclass.h link.h bits/link.h bits/link_lavcurrent.h
> -routines       = $(all-dl-routines) dl-support dl-iteratephdr \
> -                 dl-addr dl-addr-obj enbl-secure dl-profstub \
> -                 dl-origin dl-libc dl-sym dl-sysdep dl-error \
> -                 dl-reloc-static-pie libc_early_init rtld_static_init \
> -                 libc-dl_find_object
> +headers = \
> +  bits/elfclass.h \
> +  bits/link.h \
> +  bits/link_lavcurrent.h \
> +  elf.h \
> +  link.h \
> +  # headers
> +
> +routines = \
> +  $(all-dl-routines) \
> +  dl-addr \
> +  dl-addr-obj \
> +  dl-error \
> +  dl-iteratephdr \
> +  dl-libc \
> +  dl-origin \
> +  dl-profstub \
> +  dl-reloc-static-pie \
> +  dl-support \
> +  dl-sym \
> +  dl-sysdep \
> +  enbl-secure \
> +  libc-dl_find_object \
> +  libc_early_init \
> +  rtld_static_init \
> +  # routines
>
>  # The core dynamic linking functions are in libc for the static and
>  # profiled libraries.
> -dl-routines    = $(addprefix dl-,load lookup object reloc deps \
> -                                 runtime init fini debug misc \
> -                                 version profile tls origin scope \
> -                                 execstack open close trampoline \
> -                                 exception sort-maps lookup-direct \
> -                                 call-libc-early-init write \
> -                                 thread_gscope_wait tls_init_tp \
> -                                 debug-symbols minimal-malloc \
> -                                 find_object)
> +dl-routines = \
> +  dl-call-libc-early-init \
> +  dl-close \
> +  dl-debug \
> +  dl-debug-symbols \
> +  dl-deps \
> +  dl-exception \
> +  dl-execstack \
> +  dl-find_object \
> +  dl-fini \
> +  dl-init \
> +  dl-load \
> +  dl-lookup \
> +  dl-lookup-direct \
> +  dl-minimal-malloc \
> +  dl-misc \
> +  dl-object \
> +  dl-open \
> +  dl-origin \
> +  dl-profile \
> +  dl-reloc \
> +  dl-runtime \
> +  dl-scope \
> +  dl-sort-maps \
> +  dl-thread_gscope_wait \
> +  dl-tls \
> +  dl-tls_init_tp \
> +  dl-trampoline \
> +  dl-version \
> +  dl-write \
> +  # dl-routines
> +
>  ifeq (yes,$(use-ldconfig))
>  dl-routines += dl-cache
>  endif
> @@ -61,19 +104,43 @@ endif
>
>  all-dl-routines = $(dl-routines) $(sysdep-dl-routines)
>  # But they are absent from the shared libc, because that code is in ld.so.
> -elide-routines.os = $(all-dl-routines) dl-support enbl-secure dl-origin \
> -                   dl-sysdep dl-exception dl-reloc-static-pie \
> -                   thread_gscope_wait rtld_static_init
> +elide-routines.os = \
> +  $(all-dl-routines) \
> +  dl-exception \
> +  dl-origin \
> +  dl-reloc-static-pie \
> +  dl-support \
> +  dl-sysdep \
> +  enbl-secure \
> +  rtld_static_init \
> +  thread_gscope_wait \
> +  # elide-routines.os
>
>  # These object files are only included in the dynamically-linked libc.
>  shared-only-routines = libc-dl_find_object
>
>  # ld.so uses those routines, plus some special stuff for being the program
>  # interpreter and operating independent of libc.
> -rtld-routines  = rtld $(all-dl-routines) dl-sysdep dl-environ dl-minimal \
> -  dl-error-minimal dl-conflict dl-hwcaps dl-hwcaps_split dl-hwcaps-subdirs \
> -  dl-usage dl-diagnostics dl-diagnostics-kernel dl-diagnostics-cpu \
> -  dl-mutex dl-libc_freeres dl-audit
> +rtld-routines = \
> +  $(all-dl-routines) \
> +  dl-audit \
> +  dl-conflict \
> +  dl-diagnostics \
> +  dl-diagnostics-cpu \
> +  dl-diagnostics-kernel \
> +  dl-environ \
> +  dl-error-minimal \
> +  dl-hwcaps \
> +  dl-hwcaps-subdirs \
> +  dl-hwcaps_split \
> +  dl-libc_freeres \
> +  dl-minimal \
> +  dl-mutex \
> +  dl-sysdep \
> +  dl-usage \
> +  rtld \
> +  # rtld-routines
> +
>  all-rtld-routines = $(rtld-routines) $(sysdep-rtld-routines)
>
>  CFLAGS-dl-runtime.c += -fexceptions -fasynchronous-unwind-tables
> @@ -113,8 +180,16 @@ ld-map             = $(common-objpfx)ld.map
>  endif
>
>  ifeq (yes,$(build-shared))
> -extra-objs     = $(all-rtld-routines:%=%.os) sofini.os interp.os
> -generated      += librtld.os dl-allobjs.os ld.so ldd
> +extra-objs = \
> +  $(all-rtld-routines:%=%.os) \
> +  sofini.os \
> +  interp.os \
> +  # extra-objs
> +generated += \
> +  dl-allobjs.os \
> +  ld.so ldd \
> +  librtld.os \
> +  # generated
>  install-others = $(inst_rtlddir)/$(rtld-installed-name) $(inst_bindir)/ld.so
>  install-bin-script = ldd
>  endif
> @@ -132,8 +207,15 @@ others-static      += ldconfig
>  others         += ldconfig
>  install-rootsbin += ldconfig
>
> -ldconfig-modules := cache readlib xmalloc xstrdup chroot_canon static-stubs \
> -  stringtable
> +ldconfig-modules := \
> +  cache \
> +  chroot_canon \
> +  readlib \
> +  static-stubs \
> +  stringtable \
> +  xmalloc \
> +  xstrdup \
> +  # ldconfig-modules
>  extra-objs     += $(ldconfig-modules:=.o)
>  others-extras   = $(ldconfig-modules)
>  endif
> @@ -167,24 +249,36 @@ $(inst_auditdir)/sotruss-lib.so: $(objpfx)sotruss-lib.so $(+force)
>         $(do-install-program)
>  endif
>
> -tests-static-normal := tst-array1-static tst-array5-static \
> -              tst-dl-iter-static \
> -              tst-tlsalign-static tst-tlsalign-extern-static \
> -              tst-linkall-static tst-env-setuid tst-env-setuid-tunables \
> -              tst-single_threaded-static tst-single_threaded-pthread-static \
> -              tst-dst-static tst-getauxval-static
> -
> -tests-static-internal := tst-tls1-static \
> -              tst-ptrguard1-static tst-stackguard1-static \
> -              tst-tls1-static-non-pie \
> -              tst-dl_find_object-static
> +tests-static-normal := \
> +  tst-array1-static \
> +  tst-array5-static \
> +  tst-dl-iter-static \
> +  tst-dst-static \
> +  tst-env-setuid \
> +  tst-env-setuid-tunables \
> +  tst-getauxval-static \
> +  tst-linkall-static \
> +  tst-single_threaded-pthread-static \
> +  tst-single_threaded-static \
> +  tst-tlsalign-extern-static \
> +  tst-tlsalign-static \
> +  # tests-static-normal
> +
> +tests-static-internal := \
> +  tst-dl_find_object-static \
> +  tst-ptrguard1-static \
> +  tst-stackguard1-static \
> +  tst-tls1-static \
> +  tst-tls1-static-non-pie \
> +  # tests-static-internal
>
>  CRT-tst-tls1-static-non-pie := $(csu-objpfx)crt1.o
>  tst-tls1-static-non-pie-no-pie = yes
>
>  tests-container := \
> -                         tst-ldconfig-bad-aux-cache \
> -                         tst-ldconfig-ld_so_conf-update
> +  tst-ldconfig-bad-aux-cache \
> +  tst-ldconfig-ld_so_conf-update \
> +  # tests-container
>
>  ifeq (no,$(build-hardcoded-path-in-tests))
>  # This is an ld.so.cache test, and RPATH/RUNPATH in the executable
> @@ -192,14 +286,31 @@ ifeq (no,$(build-hardcoded-path-in-tests))
>  tests-container += tst-glibc-hwcaps-prepend-cache
>  endif
>
> -tests := tst-tls9 tst-leaks1 \
> -       tst-array1 tst-array2 tst-array3 tst-array4 tst-array5 \
> -       tst-auxv tst-stringtable
> -tests-internal := tst-tls1 $(tests-static-internal)
> +tests := \
> +  tst-array1 \
> +  tst-array2 \
> +  tst-array3 \
> +  tst-array4 \
> +  tst-array5 \
> +  tst-auxv \
> +  tst-leaks1 \
> +  tst-stringtable \
> +  tst-tls9 \
> +  # tests
> +
> +tests-internal := \
> +  $(tests-static-internal) \
> +  tst-tls1 \
> +  # tests-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-single_threaded-static-dlopen \
> +  tst-tls9-static \
> +  # tests-static
> +
>  static-dlopen-environment = \
>    LD_LIBRARY_PATH=$(ld-library-path):$(common-objpfx)dlfcn
>  tst-tls9-static-ENV = $(static-dlopen-environment)
> @@ -327,45 +438,88 @@ tests += \
>    unload6 \
>    unload7 \
>    unload8 \
> -#       reldep9
> +  # tests
>  tests-cxx = \
>    tst-dlopen-nodelete-reloc \
>    tst-nodelete \
>    tst-unique3 \
>    tst-unique4 \
> -# tests-cxx
> +  # tests-cxx
>
>  tests += $(if $(CXX),$(tests-cxx))
> -tests-internal += loadtest unload unload2 circleload1 \
> -        neededtest neededtest2 neededtest3 neededtest4 \
> -        tst-tls3 tst-tls6 tst-tls7 tst-tls8 tst-dlmopen2 \
> -        tst-ptrguard1 tst-stackguard1 \
> -        tst-create_format1 tst-tls-surplus tst-dl-hwcaps_split \
> -        tst-audit19a \
> -        tst-dl_find_object tst-dl_find_object-threads
> -tests-container += tst-pldd tst-dlopen-tlsmodid-container \
> -  tst-dlopen-self-container tst-preload-pthread-libc
> -test-srcs = tst-pathopt
> +
> +tests-internal += \
> +  circleload1 \
> +  loadtest \
> +  neededtest \
> +  neededtest2 \
> +  neededtest3 \
> +  neededtest4 \
> +  tst-audit19a \
> +  tst-create_format1 \
> +  tst-dl-hwcaps_split \
> +  tst-dl_find_object \
> +  tst-dl_find_object-threads \
> +  tst-dlmopen2 \
> +  tst-ptrguard1 \
> +  tst-stackguard1 \
> +  tst-tls-surplus \
> +  tst-tls3 \
> +  tst-tls6 \
> +  tst-tls7 \
> +  tst-tls8 \
> +  unload \
> +  unload2 \
> +  # tests-internal
> +
> +tests-container += \
> +  tst-dlopen-self-container \
> +  tst-dlopen-tlsmodid-container \
> +  tst-pldd \
> +  tst-preload-pthread-libc \
> +  # tests-container
> +
> +test-srcs = \
> +  tst-pathopt \
> +  # tests-srcs
> +
>  ifeq (yes,$(have-fpie))
>  tests-pie += tst-align3
>  endif
>  selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null)
> +
>  ifneq ($(selinux-enabled),1)
> -tests-execstack-yes = tst-execstack tst-execstack-needed tst-execstack-prog
> +tests-execstack-yes = \
> +  tst-execstack \
> +  tst-execstack-needed \
> +  tst-execstack-prog \
> +  # tests-execstack-yes
>  endif
>  ifeq ($(have-depaudit),yes)
> -tests += tst-audit14 tst-audit15 tst-audit16 tst-audit14a
> +tests += \
> +  tst-audit14 \
> +  tst-audit14a \
> +  tst-audit15 \
> +  tst-audit16 \
> +  # tests
>  ifeq ($(run-built-tests),yes)
> -tests-special += $(objpfx)tst-audit14-cmp.out $(objpfx)tst-audit15-cmp.out \
> -                $(objpfx)tst-audit16-cmp.out $(objpfx)tst-audit14a-cmp.out
> +tests-special += \
> +  $(objpfx)tst-audit14-cmp.out \
> +  $(objpfx)tst-audit14a-cmp.out \
> +  $(objpfx)tst-audit15-cmp.out \
> +  $(objpfx)tst-audit16-cmp.out \
> +  # tests-special
>  endif
>  endif
>  endif
>  tests += $(tests-execstack-$(have-z-execstack))
>  ifeq ($(run-built-tests),yes)
> -tests-special += $(objpfx)tst-leaks1-mem.out \
> -                $(objpfx)noload-mem.out \
> -                $(objpfx)tst-ldconfig-X.out $(objpfx)tst-rtld-help.out
> +tests-special += \
> +  $(objpfx)noload-mem.out \
> +  $(objpfx)tst-ldconfig-X.out \
> +  $(objpfx)tst-leaks1-mem.out \
> +  $(objpfx)tst-rtld-help.out \
> +  # tests-special
>  endif
>  tlsmod17a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
>  tlsmod18a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
> @@ -382,9 +536,16 @@ tst-tls-many-dynamic-modules-dep = \
>  tst-tls-many-dynamic-modules-dep-bad-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
>  tst-tls-many-dynamic-modules-dep-bad = \
>    $(foreach n,$(tst-tls-many-dynamic-modules-dep-bad-suffixes),tst-tls-manydynamic$(n)mod-dep-bad)
> -extra-test-objs += $(tlsmod17a-modules:=.os) $(tlsmod18a-modules:=.os) \
> -                  tst-tlsalign-vars.o
> -test-extras += tst-tlsmod17a tst-tlsmod18a tst-tlsalign-vars
> +extra-test-objs += \
> +  $(tlsmod17a-modules:=.os) \
> +  $(tlsmod18a-modules:=.os) \
> +  tst-tlsalign-vars.o \
> +  # extra-test-objs
> +test-extras += \
> +  tst-tlsalign-vars \
> +  tst-tlsmod17a \
> +  tst-tlsmod18a \
> +  # test-extras
>  modules-names = \
>    circlemod1 \
>    circlemod1a \
> @@ -653,17 +814,17 @@ modules-names-cxx = \
>    tst-unique3lib \
>    tst-unique3lib2 \
>    tst-unique4lib \
> -# modules-names-cxx
> +  # modules-names-cxx
>
>  modules-names += \
>    $(if $(CXX),$(modules-names-cxx)) \
>    $(modules-execstack-$(have-z-execstack)) \
> +  $(tlsmod17a-modules) \
> +  $(tlsmod18a-modules) \
>    $(tst-tls-many-dynamic-modules) \
>    $(tst-tls-many-dynamic-modules-dep) \
>    $(tst-tls-many-dynamic-modules-dep-bad) \
> -  $(tlsmod17a-modules) \
> -  $(tlsmod18a-modules) \
> -# modules-names
> +  # modules-names
>
>  # Most modules build with _ISOMAC defined, but those filtered out
>  # depend on internal headers.
> @@ -728,38 +889,73 @@ modules-names-nobuild := filtmod1 tst-big-note-lib tst-ro-dynamic-mod
>  tests += $(tests-static)
>
>  ifeq (yes,$(have-ifunc))
> -tests-ifuncstatic := ifuncmain1static ifuncmain1picstatic \
> -               ifuncmain2static ifuncmain2picstatic \
> -               ifuncmain4static ifuncmain4picstatic \
> -               ifuncmain5static ifuncmain5picstatic \
> -               ifuncmain7static ifuncmain7picstatic
> +tests-ifuncstatic := \
> +  ifuncmain1static \
> +  ifuncmain1picstatic \
> +  ifuncmain2static \
> +  ifuncmain2picstatic \
> +  ifuncmain4static \
> +  ifuncmain4picstatic \
> +  ifuncmain5static \
> +  ifuncmain5picstatic \
> +  ifuncmain7static \
> +  ifuncmain7picstatic \
> +  # tests-ifuncstatic
>  ifeq (yes,$(have-gcc-ifunc))
>  tests-ifuncstatic += ifuncmain9static ifuncmain9picstatic
>  endif
>  tests-static += $(tests-ifuncstatic)
>  tests-internal += $(tests-ifuncstatic)
>  ifeq (yes,$(build-shared))
> -tests += tst-ifunc-fault-lazy tst-ifunc-fault-bindnow
> +tests += \
> +  tst-ifunc-fault-bindnow \
> +  tst-ifunc-fault-lazy \
> +  # tests
>  # Note: sysdeps/x86_64/ifuncmain8.c uses ifuncmain8.
>  tests-internal += \
> -        ifuncmain1pic ifuncmain1vis ifuncmain1vispic \
> -        ifuncmain1staticpic \
> -        ifuncmain2 ifuncmain2pic ifuncmain3 ifuncmain4 \
> -        ifuncmain5staticpic \
> -        ifuncmain7 ifuncmain7pic
> +  ifuncmain1pic \
> +  ifuncmain1staticpic \
> +  ifuncmain1vis \
> +  ifuncmain1vispic \
> +  ifuncmain2 \
> +  ifuncmain2pic \
> +  ifuncmain3 \
> +  ifuncmain4 \
> +  ifuncmain5staticpic \
> +  ifuncmain7 \
> +  ifuncmain7pic \
> +  # tests-internal
>  ifeq (no,$(with-lld))
> -tests-internal += ifuncmain1 ifuncmain5 ifuncmain5pic
> +tests-internal += \
> +  ifuncmain1 \
> +  ifuncmain5 \
> +  ifuncmain5pic \
> +  # tests-internal
>  endif
>  ifeq (yes,$(have-gcc-ifunc))
> -tests-internal += ifuncmain9 ifuncmain9pic
> +tests-internal += \
> +  ifuncmain9 \
> +  ifuncmain9pic \
> +  # tests-internal
>  endif
> -ifunc-test-modules = ifuncdep1 ifuncdep1pic ifuncdep2 ifuncdep2pic \
> -                    ifuncdep5 ifuncdep5pic
> +ifunc-test-modules = \
> +  ifuncdep1 \
> +  ifuncdep1pic \
> +  ifuncdep2 \
> +  ifuncdep2pic \
> +  ifuncdep5 \
> +  ifuncdep5pic \
> +  # ifunc-test-modules
>  extra-test-objs += $(ifunc-test-modules:=.o)
>  test-internal-extras += $(ifunc-test-modules)
>  ifeq (yes,$(have-fpie))
> -ifunc-pie-tests = ifuncmain1pie ifuncmain1vispie ifuncmain1staticpie \
> -                 ifuncmain6pie ifuncmain7pie
> +ifunc-pie-tests = \
> +  ifuncmain1pie \
> +  ifuncmain1staticpie \
> +  ifuncmain1vispie \
> +  ifuncmain6pie \
> +  ifuncmain7pie \
> +  # ifunc-pie-tests
>  ifeq (yes,$(have-gcc-ifunc))
>  ifunc-pie-tests += ifuncmain9pie
>  endif
> @@ -772,7 +968,11 @@ endif
>  tests-internal += $(ifunc-pie-tests)
>  tests-pie += $(ifunc-pie-tests)
>  endif
> -modules-names += ifuncmod1 ifuncmod3 ifuncmod6
> +modules-names += \
> +  ifuncmod1 \
> +  ifuncmod3 \
> +  ifuncmod6 \
> +  # module-names
>  ifeq (no,$(with-lld))
>  modules-names += ifuncmod5
>  endif
> @@ -781,24 +981,39 @@ endif
>
>  ifeq (yes,$(build-shared))
>  ifeq ($(run-built-tests),yes)
> -tests-special += $(objpfx)tst-pathopt.out $(objpfx)tst-rtld-load-self.out \
> -                $(objpfx)tst-rtld-preload.out $(objpfx)argv0test.out \
> -                $(objpfx)tst-rtld-help.out
> +tests-special += \
> +  $(objpfx)argv0test.out \
> +  $(objpfx)tst-pathopt.out \
> +  $(objpfx)tst-rtld-help.out \
> +  $(objpfx)tst-rtld-load-self.out \
> +  $(objpfx)tst-rtld-preload.out \
> +  # tests-special
>  endif
> -tests-special += $(objpfx)check-textrel.out $(objpfx)check-execstack.out \
> -                $(objpfx)check-wx-segment.out \
> -                $(objpfx)check-localplt.out $(objpfx)check-initfini.out
> +tests-special += \
> +  $(objpfx)check-execstack.out \
> +  $(objpfx)check-initfini.out \
> +  $(objpfx)check-localplt.out \
> +  $(objpfx)check-textrel.out \
> +  $(objpfx)check-wx-segment.out \
> +  # tests-special
>  endif
>
>  ifeq ($(run-built-tests),yes)
> -tests-special += $(objpfx)order-cmp.out $(objpfx)tst-array1-cmp.out \
> -                $(objpfx)tst-array1-static-cmp.out \
> -                $(objpfx)tst-array2-cmp.out $(objpfx)tst-array3-cmp.out \
> -                $(objpfx)tst-array4-cmp.out $(objpfx)tst-array5-cmp.out \
> -                $(objpfx)tst-array5-static-cmp.out $(objpfx)order2-cmp.out \
> -                $(objpfx)tst-initorder-cmp.out \
> -                $(objpfx)tst-initorder2-cmp.out $(objpfx)tst-unused-dep.out \
> -                $(objpfx)tst-unused-dep-cmp.out
> +tests-special += \
> +  $(objpfx)order-cmp.out \
> +  $(objpfx)order2-cmp.out \
> +  $(objpfx)tst-array1-cmp.out \
> +  $(objpfx)tst-array1-static-cmp.out \
> +  $(objpfx)tst-array2-cmp.out \
> +  $(objpfx)tst-array3-cmp.out \
> +  $(objpfx)tst-array4-cmp.out \
> +  $(objpfx)tst-array5-cmp.out \
> +  $(objpfx)tst-array5-static-cmp.out \
> +  $(objpfx)tst-initorder-cmp.out \
> +  $(objpfx)tst-initorder2-cmp.out \
> +  $(objpfx)tst-unused-dep-cmp.out \
> +  $(objpfx)tst-unused-dep.out \
> +  # tests-special
>  endif
>
>  ifndef avoid-generated
> @@ -903,6 +1118,7 @@ rtld-stubbed-symbols = \
>    free \
>    malloc \
>    realloc \
> +  # rtld-stubbed-symbols
>
>  ifeq ($(have-ssp),yes)
>  # rtld is not built with the stack protector, so these references will
> --
> 2.34.1
>
>

LGTM.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/6] elf: Split dl-printf.c from dl-misc.c
  2022-01-14 16:52 ` [PATCH v2 2/6] elf: Split dl-printf.c from dl-misc.c Florian Weimer
@ 2022-01-14 18:40   ` H.J. Lu
  0 siblings, 0 replies; 16+ messages in thread
From: H.J. Lu @ 2022-01-14 18:40 UTC (permalink / raw)
  To: Florian Weimer; +Cc: GNU C Library

On Fri, Jan 14, 2022 at 8:53 AM Florian Weimer via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> This allows to use different compiler flags for the diagnostics
> code.
> ---
> v2: Adjust to Makefile changes in patch 1.
>  elf/Makefile    |   1 +
>  elf/dl-misc.c   | 281 +---------------------------------------------
>  elf/dl-printf.c | 292 ++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 297 insertions(+), 277 deletions(-)
>  create mode 100644 elf/dl-printf.c
>
> diff --git a/elf/Makefile b/elf/Makefile
> index 3065efc485..3df49742ff 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -69,6 +69,7 @@ dl-routines = \
>    dl-object \
>    dl-open \
>    dl-origin \
> +  dl-printf \
>    dl-profile \
>    dl-reloc \
>    dl-runtime \
> diff --git a/elf/dl-misc.c b/elf/dl-misc.c
> index 452b79de4a..6f40c28820 100644
> --- a/elf/dl-misc.c
> +++ b/elf/dl-misc.c
> @@ -16,24 +16,16 @@
>     License along with the GNU C Library; if not, see
>     <https://www.gnu.org/licenses/>.  */
>
> -#include <assert.h>
> +#include <_itoa.h>
>  #include <fcntl.h>
>  #include <ldsodefs.h>
> -#include <limits.h>
>  #include <link.h>
> -#include <stdarg.h>
> -#include <stdlib.h>
> -#include <string.h>
> -#include <unistd.h>
> +#include <not-cancel.h>
>  #include <stdint.h>
> +#include <stdlib.h>
>  #include <sys/mman.h>
> -#include <sys/param.h>
>  #include <sys/stat.h>
> -#include <sys/uio.h>
> -#include <sysdep.h>
> -#include <_itoa.h>
> -#include <dl-writev.h>
> -#include <not-cancel.h>
> +#include <unistd.h>
>
>  /* Read the whole contents of FILE into new mmap'd space with given
>     protections.  *SIZEP gets the size of the file.  On error MAP_FAILED
> @@ -70,270 +62,6 @@ _dl_sysdep_read_whole_file (const char *file, size_t *sizep, int prot)
>    return result;
>  }
>
> -
> -/* Bare-bones printf implementation.  This function only knows about
> -   the formats and flags needed and can handle only up to 64 stripes in
> -   the output.  */
> -static void
> -_dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg)
> -{
> -# define NIOVMAX 64
> -  struct iovec iov[NIOVMAX];
> -  int niov = 0;
> -  pid_t pid = 0;
> -  char pidbuf[12];
> -
> -  while (*fmt != '\0')
> -    {
> -      const char *startp = fmt;
> -
> -      if (tag_p > 0)
> -       {
> -         /* Generate the tag line once.  It consists of the PID and a
> -            colon followed by a tab.  */
> -         if (pid == 0)
> -           {
> -             char *p;
> -             pid = __getpid ();
> -             assert (pid >= 0 && sizeof (pid_t) <= 4);
> -             p = _itoa (pid, &pidbuf[10], 10, 0);
> -             while (p > pidbuf)
> -               *--p = ' ';
> -             pidbuf[10] = ':';
> -             pidbuf[11] = '\t';
> -           }
> -
> -         /* Append to the output.  */
> -         assert (niov < NIOVMAX);
> -         iov[niov].iov_len = 12;
> -         iov[niov++].iov_base = pidbuf;
> -
> -         /* No more tags until we see the next newline.  */
> -         tag_p = -1;
> -       }
> -
> -      /* Skip everything except % and \n (if tags are needed).  */
> -      while (*fmt != '\0' && *fmt != '%' && (! tag_p || *fmt != '\n'))
> -       ++fmt;
> -
> -      /* Append constant string.  */
> -      assert (niov < NIOVMAX);
> -      if ((iov[niov].iov_len = fmt - startp) != 0)
> -       iov[niov++].iov_base = (char *) startp;
> -
> -      if (*fmt == '%')
> -       {
> -         /* It is a format specifier.  */
> -         char fill = ' ';
> -         int width = -1;
> -         int prec = -1;
> -#if LONG_MAX != INT_MAX
> -         int long_mod = 0;
> -#endif
> -
> -         /* Recognize zero-digit fill flag.  */
> -         if (*++fmt == '0')
> -           {
> -             fill = '0';
> -             ++fmt;
> -           }
> -
> -         /* See whether with comes from a parameter.  Note that no other
> -            way to specify the width is implemented.  */
> -         if (*fmt == '*')
> -           {
> -             width = va_arg (arg, int);
> -             ++fmt;
> -           }
> -
> -         /* Handle precision.  */
> -         if (*fmt == '.' && fmt[1] == '*')
> -           {
> -             prec = va_arg (arg, int);
> -             fmt += 2;
> -           }
> -
> -         /* Recognize the l modifier.  It is only important on some
> -            platforms where long and int have a different size.  We
> -            can use the same code for size_t.  */
> -         if (*fmt == 'l' || *fmt == 'Z')
> -           {
> -#if LONG_MAX != INT_MAX
> -             long_mod = 1;
> -#endif
> -             ++fmt;
> -           }
> -
> -         switch (*fmt)
> -           {
> -             /* Integer formatting.  */
> -           case 'd':
> -           case 'u':
> -           case 'x':
> -             {
> -               /* We have to make a difference if long and int have a
> -                  different size.  */
> -#if LONG_MAX != INT_MAX
> -               unsigned long int num = (long_mod
> -                                        ? va_arg (arg, unsigned long int)
> -                                        : va_arg (arg, unsigned int));
> -#else
> -               unsigned long int num = va_arg (arg, unsigned int);
> -#endif
> -               bool negative = false;
> -               if (*fmt == 'd')
> -                 {
> -#if LONG_MAX != INT_MAX
> -                   if (long_mod)
> -                     {
> -                       if ((long int) num < 0)
> -                         negative = true;
> -                     }
> -                   else
> -                     {
> -                       if ((int) num < 0)
> -                         {
> -                           num = (unsigned int) num;
> -                           negative = true;
> -                         }
> -                     }
> -#else
> -                   if ((int) num < 0)
> -                     negative = true;
> -#endif
> -                 }
> -
> -               /* We use alloca() to allocate the buffer with the most
> -                  pessimistic guess for the size.  Using alloca() allows
> -                  having more than one integer formatting in a call.  */
> -               char *buf = (char *) alloca (1 + 3 * sizeof (unsigned long int));
> -               char *endp = &buf[1 + 3 * sizeof (unsigned long int)];
> -               char *cp = _itoa (num, endp, *fmt == 'x' ? 16 : 10, 0);
> -
> -               /* Pad to the width the user specified.  */
> -               if (width != -1)
> -                 while (endp - cp < width)
> -                   *--cp = fill;
> -
> -               if (negative)
> -                 *--cp = '-';
> -
> -               iov[niov].iov_base = cp;
> -               iov[niov].iov_len = endp - cp;
> -               ++niov;
> -             }
> -             break;
> -
> -           case 's':
> -             /* Get the string argument.  */
> -             iov[niov].iov_base = va_arg (arg, char *);
> -             iov[niov].iov_len = strlen (iov[niov].iov_base);
> -             if (prec != -1)
> -               iov[niov].iov_len = MIN ((size_t) prec, iov[niov].iov_len);
> -             ++niov;
> -             break;
> -
> -           case '%':
> -             iov[niov].iov_base = (void *) fmt;
> -             iov[niov].iov_len = 1;
> -             ++niov;
> -             break;
> -
> -           default:
> -             assert (! "invalid format specifier");
> -           }
> -         ++fmt;
> -       }
> -      else if (*fmt == '\n')
> -       {
> -         /* See whether we have to print a single newline character.  */
> -         if (fmt == startp)
> -           {
> -             iov[niov].iov_base = (char *) startp;
> -             iov[niov++].iov_len = 1;
> -           }
> -         else
> -           /* No, just add it to the rest of the string.  */
> -           ++iov[niov - 1].iov_len;
> -
> -         /* Next line, print a tag again.  */
> -         tag_p = 1;
> -         ++fmt;
> -       }
> -    }
> -
> -  /* Finally write the result.  */
> -  _dl_writev (fd, iov, niov);
> -}
> -
> -
> -/* Write to debug file.  */
> -void
> -_dl_debug_printf (const char *fmt, ...)
> -{
> -  va_list arg;
> -
> -  va_start (arg, fmt);
> -  _dl_debug_vdprintf (GLRO(dl_debug_fd), 1, fmt, arg);
> -  va_end (arg);
> -}
> -
> -
> -/* Write to debug file but don't start with a tag.  */
> -void
> -_dl_debug_printf_c (const char *fmt, ...)
> -{
> -  va_list arg;
> -
> -  va_start (arg, fmt);
> -  _dl_debug_vdprintf (GLRO(dl_debug_fd), -1, fmt, arg);
> -  va_end (arg);
> -}
> -
> -
> -/* Write the given file descriptor.  */
> -void
> -_dl_dprintf (int fd, const char *fmt, ...)
> -{
> -  va_list arg;
> -
> -  va_start (arg, fmt);
> -  _dl_debug_vdprintf (fd, 0, fmt, arg);
> -  va_end (arg);
> -}
> -
> -void
> -_dl_printf (const char *fmt, ...)
> -{
> -  va_list arg;
> -
> -  va_start (arg, fmt);
> -  _dl_debug_vdprintf (STDOUT_FILENO, 0, fmt, arg);
> -  va_end (arg);
> -}
> -
> -void
> -_dl_error_printf (const char *fmt, ...)
> -{
> -  va_list arg;
> -
> -  va_start (arg, fmt);
> -  _dl_debug_vdprintf (STDERR_FILENO, 0, fmt, arg);
> -  va_end (arg);
> -}
> -
> -void
> -_dl_fatal_printf (const char *fmt, ...)
> -{
> -  va_list arg;
> -
> -  va_start (arg, fmt);
> -  _dl_debug_vdprintf (STDERR_FILENO, 0, fmt, arg);
> -  va_end (arg);
> -  _exit (127);
> -}
> -rtld_hidden_def (_dl_fatal_printf)
> -
>  /* Test whether given NAME matches any of the names of the given object.  */
>  int
>  _dl_name_match_p (const char *name, const struct link_map *map)
> @@ -354,7 +82,6 @@ _dl_name_match_p (const char *name, const struct link_map *map)
>    return 0;
>  }
>
> -
>  unsigned long int
>  _dl_higher_prime_number (unsigned long int n)
>  {
> diff --git a/elf/dl-printf.c b/elf/dl-printf.c
> new file mode 100644
> index 0000000000..d3264ba96c
> --- /dev/null
> +++ b/elf/dl-printf.c
> @@ -0,0 +1,292 @@
> +/* printf implementation for the dynamic loader.
> +   Copyright (C) 1997-2022 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 <_itoa.h>
> +#include <assert.h>
> +#include <dl-writev.h>
> +#include <ldsodefs.h>
> +#include <limits.h>
> +#include <stdarg.h>
> +#include <stdint.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <sys/uio.h>
> +#include <unistd.h>
> +
> +/* Bare-bones printf implementation.  This function only knows about
> +   the formats and flags needed and can handle only up to 64 stripes in
> +   the output.  */
> +static void
> +_dl_debug_vdprintf (int fd, int tag_p, const char *fmt, va_list arg)
> +{
> +# define NIOVMAX 64
> +  struct iovec iov[NIOVMAX];
> +  int niov = 0;
> +  pid_t pid = 0;
> +  char pidbuf[12];
> +
> +  while (*fmt != '\0')
> +    {
> +      const char *startp = fmt;
> +
> +      if (tag_p > 0)
> +       {
> +         /* Generate the tag line once.  It consists of the PID and a
> +            colon followed by a tab.  */
> +         if (pid == 0)
> +           {
> +             char *p;
> +             pid = __getpid ();
> +             assert (pid >= 0 && sizeof (pid_t) <= 4);
> +             p = _itoa (pid, &pidbuf[10], 10, 0);
> +             while (p > pidbuf)
> +               *--p = ' ';
> +             pidbuf[10] = ':';
> +             pidbuf[11] = '\t';
> +           }
> +
> +         /* Append to the output.  */
> +         assert (niov < NIOVMAX);
> +         iov[niov].iov_len = 12;
> +         iov[niov++].iov_base = pidbuf;
> +
> +         /* No more tags until we see the next newline.  */
> +         tag_p = -1;
> +       }
> +
> +      /* Skip everything except % and \n (if tags are needed).  */
> +      while (*fmt != '\0' && *fmt != '%' && (! tag_p || *fmt != '\n'))
> +       ++fmt;
> +
> +      /* Append constant string.  */
> +      assert (niov < NIOVMAX);
> +      if ((iov[niov].iov_len = fmt - startp) != 0)
> +       iov[niov++].iov_base = (char *) startp;
> +
> +      if (*fmt == '%')
> +       {
> +         /* It is a format specifier.  */
> +         char fill = ' ';
> +         int width = -1;
> +         int prec = -1;
> +#if LONG_MAX != INT_MAX
> +         int long_mod = 0;
> +#endif
> +
> +         /* Recognize zero-digit fill flag.  */
> +         if (*++fmt == '0')
> +           {
> +             fill = '0';
> +             ++fmt;
> +           }
> +
> +         /* See whether with comes from a parameter.  Note that no other
> +            way to specify the width is implemented.  */
> +         if (*fmt == '*')
> +           {
> +             width = va_arg (arg, int);
> +             ++fmt;
> +           }
> +
> +         /* Handle precision.  */
> +         if (*fmt == '.' && fmt[1] == '*')
> +           {
> +             prec = va_arg (arg, int);
> +             fmt += 2;
> +           }
> +
> +         /* Recognize the l modifier.  It is only important on some
> +            platforms where long and int have a different size.  We
> +            can use the same code for size_t.  */
> +         if (*fmt == 'l' || *fmt == 'Z')
> +           {
> +#if LONG_MAX != INT_MAX
> +             long_mod = 1;
> +#endif
> +             ++fmt;
> +           }
> +
> +         switch (*fmt)
> +           {
> +             /* Integer formatting.  */
> +           case 'd':
> +           case 'u':
> +           case 'x':
> +             {
> +               /* We have to make a difference if long and int have a
> +                  different size.  */
> +#if LONG_MAX != INT_MAX
> +               unsigned long int num = (long_mod
> +                                        ? va_arg (arg, unsigned long int)
> +                                        : va_arg (arg, unsigned int));
> +#else
> +               unsigned long int num = va_arg (arg, unsigned int);
> +#endif
> +               bool negative = false;
> +               if (*fmt == 'd')
> +                 {
> +#if LONG_MAX != INT_MAX
> +                   if (long_mod)
> +                     {
> +                       if ((long int) num < 0)
> +                         negative = true;
> +                     }
> +                   else
> +                     {
> +                       if ((int) num < 0)
> +                         {
> +                           num = (unsigned int) num;
> +                           negative = true;
> +                         }
> +                     }
> +#else
> +                   if ((int) num < 0)
> +                     negative = true;
> +#endif
> +                 }
> +
> +               /* We use alloca() to allocate the buffer with the most
> +                  pessimistic guess for the size.  Using alloca() allows
> +                  having more than one integer formatting in a call.  */
> +               char *buf = (char *) alloca (1 + 3 * sizeof (unsigned long int));
> +               char *endp = &buf[1 + 3 * sizeof (unsigned long int)];
> +               char *cp = _itoa (num, endp, *fmt == 'x' ? 16 : 10, 0);
> +
> +               /* Pad to the width the user specified.  */
> +               if (width != -1)
> +                 while (endp - cp < width)
> +                   *--cp = fill;
> +
> +               if (negative)
> +                 *--cp = '-';
> +
> +               iov[niov].iov_base = cp;
> +               iov[niov].iov_len = endp - cp;
> +               ++niov;
> +             }
> +             break;
> +
> +           case 's':
> +             /* Get the string argument.  */
> +             iov[niov].iov_base = va_arg (arg, char *);
> +             iov[niov].iov_len = strlen (iov[niov].iov_base);
> +             if (prec != -1)
> +               iov[niov].iov_len = MIN ((size_t) prec, iov[niov].iov_len);
> +             ++niov;
> +             break;
> +
> +           case '%':
> +             iov[niov].iov_base = (void *) fmt;
> +             iov[niov].iov_len = 1;
> +             ++niov;
> +             break;
> +
> +           default:
> +             assert (! "invalid format specifier");
> +           }
> +         ++fmt;
> +       }
> +      else if (*fmt == '\n')
> +       {
> +         /* See whether we have to print a single newline character.  */
> +         if (fmt == startp)
> +           {
> +             iov[niov].iov_base = (char *) startp;
> +             iov[niov++].iov_len = 1;
> +           }
> +         else
> +           /* No, just add it to the rest of the string.  */
> +           ++iov[niov - 1].iov_len;
> +
> +         /* Next line, print a tag again.  */
> +         tag_p = 1;
> +         ++fmt;
> +       }
> +    }
> +
> +  /* Finally write the result.  */
> +  _dl_writev (fd, iov, niov);
> +}
> +
> +
> +/* Write to debug file.  */
> +void
> +_dl_debug_printf (const char *fmt, ...)
> +{
> +  va_list arg;
> +
> +  va_start (arg, fmt);
> +  _dl_debug_vdprintf (GLRO(dl_debug_fd), 1, fmt, arg);
> +  va_end (arg);
> +}
> +
> +
> +/* Write to debug file but don't start with a tag.  */
> +void
> +_dl_debug_printf_c (const char *fmt, ...)
> +{
> +  va_list arg;
> +
> +  va_start (arg, fmt);
> +  _dl_debug_vdprintf (GLRO(dl_debug_fd), -1, fmt, arg);
> +  va_end (arg);
> +}
> +
> +
> +/* Write the given file descriptor.  */
> +void
> +_dl_dprintf (int fd, const char *fmt, ...)
> +{
> +  va_list arg;
> +
> +  va_start (arg, fmt);
> +  _dl_debug_vdprintf (fd, 0, fmt, arg);
> +  va_end (arg);
> +}
> +
> +void
> +_dl_printf (const char *fmt, ...)
> +{
> +  va_list arg;
> +
> +  va_start (arg, fmt);
> +  _dl_debug_vdprintf (STDOUT_FILENO, 0, fmt, arg);
> +  va_end (arg);
> +}
> +
> +void
> +_dl_error_printf (const char *fmt, ...)
> +{
> +  va_list arg;
> +
> +  va_start (arg, fmt);
> +  _dl_debug_vdprintf (STDERR_FILENO, 0, fmt, arg);
> +  va_end (arg);
> +}
> +
> +void
> +_dl_fatal_printf (const char *fmt, ...)
> +{
> +  va_list arg;
> +
> +  va_start (arg, fmt);
> +  _dl_debug_vdprintf (STDERR_FILENO, 0, fmt, arg);
> +  va_end (arg);
> +  _exit (127);
> +}
> +rtld_hidden_def (_dl_fatal_printf)
> --
> 2.34.1
>
>

LGTM.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>

Thanks.


-- 
H.J.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 5/6] x86: Add x86-64-vN check to early startup
  2022-01-14 16:53 ` [PATCH v2 5/6] x86: Add x86-64-vN check to early startup Florian Weimer
@ 2022-01-14 18:40   ` H.J. Lu
  0 siblings, 0 replies; 16+ messages in thread
From: H.J. Lu @ 2022-01-14 18:40 UTC (permalink / raw)
  To: Florian Weimer; +Cc: GNU C Library

On Fri, Jan 14, 2022 at 8:53 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> This ISA level covers the glibc build itself.  <dl-hwcap-check.h>
> cannot be used because this check (by design) happens before
> DL_PLATFORM_INIT and the x86 CPU flags initialization.
> ---
> v2: Reflect renamed Makefile variable.
>  sysdeps/x86/Makefile              |  1 +
>  sysdeps/x86/dl-get-cpu-features.c | 31 ++++++++++++++++++++++++++++++-
>  2 files changed, 31 insertions(+), 1 deletion(-)
>
> diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
> index 402986ff68..6cf708335c 100644
> --- a/sysdeps/x86/Makefile
> +++ b/sysdeps/x86/Makefile
> @@ -7,6 +7,7 @@ sysdep_routines += get-cpuid-feature-leaf
>  sysdep-dl-routines += dl-get-cpu-features
>  sysdep_headers += sys/platform/x86.h bits/platform/x86.h
>
> +CFLAGS-dl-get-cpu-features.os += $(rtld-early-cflags)
>  CFLAGS-get-cpuid-feature-leaf.o += $(no-stack-protector)
>
>  tests += tst-get-cpu-features tst-get-cpu-features-static \
> diff --git a/sysdeps/x86/dl-get-cpu-features.c b/sysdeps/x86/dl-get-cpu-features.c
> index 6339c9df4e..4ec0e5d2af 100644
> --- a/sysdeps/x86/dl-get-cpu-features.c
> +++ b/sysdeps/x86/dl-get-cpu-features.c
> @@ -20,6 +20,7 @@
>
>  #ifdef SHARED
>  # include <cpu-features.c>
> +# include <gcc-macros.h>
>
>  /* NB: Normally, DL_PLATFORM_INIT calls init_cpu_features to initialize
>     CPU features in dynamic executable.  But when loading ld.so inside of
> @@ -36,7 +37,35 @@ _dl_x86_init_cpu_features (void)
>  {
>    struct cpu_features *cpu_features = __get_cpu_features ();
>    if (cpu_features->basic.kind == arch_kind_unknown)
> -    init_cpu_features (cpu_features);
> +    {
> +      init_cpu_features (cpu_features);
> +
> +# if IS_IN (rtld)
> +      /* See isa-level.c.  */
> +#  if defined GCCMACRO__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16              \
> +  && defined HAVE_X86_LAHF_SAHF && defined GCCMACRO__POPCNT__          \
> +  && defined GCCMACRO__SSE3__ && defined GCCMACRO__SSSE3__             \
> +  && defined GCCMACRO__SSE4_1__ && defined GCCMACRO__SSE4_2__
> +      if (!(cpu_features->isa_1 & GNU_PROPERTY_X86_ISA_1_V2))
> +       _dl_fatal_printf ("\
> +Fatal glibc error: CPU does not support x86-64-v%d\n", 2);
> +#   if defined GCCMACRO__AVX__ && defined GCCMACRO__AVX2__ \
> +  && defined GCCMACRO__F16C__ && defined GCCMACRO__FMA__   \
> +  && defined GCCMACRO__LZCNT__ && defined HAVE_X86_MOVBE
> +      if (!(cpu_features->isa_1 & GNU_PROPERTY_X86_ISA_1_V3))
> +       _dl_fatal_printf ("\
> +Fatal glibc error: CPU does not support x86-64-v%d\n", 3);
> +#    if defined GCCMACRO__AVX512F__ && defined GCCMACRO__AVX512BW__ \
> +     && defined GCCMACRO__AVX512CD__ && defined GCCMACRO__AVX512DQ__ \
> +     && defined GCCMACRO__AVX512VL__
> +      if (!(cpu_features->isa_1 & GNU_PROPERTY_X86_ISA_1_V4))
> +       _dl_fatal_printf ("\
> +Fatal glibc error: CPU does not support x86-64-v%d\n", 4);
> +#    endif /* ISA level 4 */
> +#   endif /* ISA level 3 */
> +#  endif /* ISA level 2 */
> +# endif /* IS_IN (rtld) */
> +    }
>  }
>
>  __ifunc (__x86_cpu_features, __x86_cpu_features, NULL, void,
> --
> 2.34.1
>
>

LGTM.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 0/6] Reliable CPU compatibility diagnostics in ld.so
  2022-01-14 17:59   ` Florian Weimer
@ 2022-01-14 18:51     ` Carlos O'Donell
  0 siblings, 0 replies; 16+ messages in thread
From: Carlos O'Donell @ 2022-01-14 18:51 UTC (permalink / raw)
  To: Florian Weimer, Joseph Myers; +Cc: libc-alpha

On 1/14/22 12:59, Florian Weimer via Libc-alpha wrote:
> * Joseph Myers:
> 
>> I think there should be a NEWS entry for the new feature and configure 
>> option.
> 
> Fair enough.  I'm going to add:
> 
> * A new configure option, --with-rtld-early-cflags, can be used to
>   specify additional compiler flags for building the early startup code
>   of the dynamic linker.  On targets which have CPU compatibility
>   checks, this can help to ensure that proper diagnostics are printed if
>   the dynamic loader runs on an incompatible CPU.

LGTM.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

-- 
Cheers,
Carlos.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 4/6] powerpc64le: Use <gcc-macros.h> in early HWCAP check
  2022-01-14 16:53 ` [PATCH v2 4/6] powerpc64le: Use <gcc-macros.h> in early HWCAP check Florian Weimer
@ 2022-01-14 18:51   ` Carlos O'Donell
  0 siblings, 0 replies; 16+ messages in thread
From: Carlos O'Donell @ 2022-01-14 18:51 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha

On 1/14/22 11:53, Florian Weimer via Libc-alpha wrote:
> This is required so that the checks still work if $(early-cflags)
> selects a different ISA level.

LGTM. No regressions on x86_64 and i686 builders. No CI/CD regressions.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>

> ---
>  sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 

There are a number of files we *might* have to wrap...

[carlos@athas glibc-pristine]$ grep -rl '_ARCH_PWR9' *
ChangeLog.old/ChangeLog.23
sysdeps/powerpc/fpu/fenv_libc.h
sysdeps/powerpc/fpu/math_private.h
sysdeps/powerpc/powerpc64/le/fpu/multiarch/float128-ifunc-redirect-macros.h
sysdeps/powerpc/powerpc64/le/fpu/e_sqrtf128.c
sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h
sysdeps/powerpc/fpu_control.h
[carlos@athas glibc-pristine]$ vi sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h
[carlos@athas glibc-pristine]$ grep -rl '_ARCH_PWR10' *
sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h
[carlos@athas glibc-pristine]$ grep -rl '__FLOAT128_HARDWARE__' *
sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h
[carlos@athas glibc-pristine]$ grep -rl '__PCREL__' *
sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h
[carlos@athas glibc-pristine]$ grep -rl '__MMA__' *
sysdeps/powerpc/powerpc64/le/dl-hwcaps-subdirs.c
sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h

But the only one matters for early startup: dl-hwcap-check.h.


> diff --git a/sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h b/sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h
> index 713a7f0313..b43c182683 100644
> --- a/sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h
> +++ b/sysdeps/powerpc/powerpc64/le/dl-hwcap-check.h
> @@ -19,17 +19,18 @@
>  #ifndef _DL_HWCAP_CHECK_H
>  #define _DL_HWCAP_CHECK_H
>  
> +#include <gcc-macros.h>

OK. 5 macros need wrapping.

>  #include <ldsodefs.h>
>  
>  static inline void
>  dl_hwcap_check (void)
>  {
> -#ifdef _ARCH_PWR9
> +#ifdef GCCMACRO_ARCH_PWR9

OK. 1/5.

>    if ((GLRO (dl_hwcap2) & PPC_FEATURE2_ARCH_3_00) == 0)
>      _dl_fatal_printf ("\
>  Fatal glibc error: CPU lacks ISA 3.00 support (POWER9 or later required)\n");
>  #endif
> -#ifdef __FLOAT128_HARDWARE__
> +#ifdef GCCMACRO__FLOAT128_HARDWARE__

OK. 2/5.

>    if ((GLRO (dl_hwcap2) & PPC_FEATURE2_HAS_IEEE128) == 0)
>      _dl_fatal_printf ("\
>  Fatal glibc error: CPU lacks float128 support (POWER 9 or later required)\n");
> @@ -37,12 +38,12 @@ Fatal glibc error: CPU lacks float128 support (POWER 9 or later required)\n");
>     /* This check is not actually reached when building for POWER10 and
>        running on POWER9 because there are faulting PCREL instructions
>        before this point.  */
> -#if defined _ARCH_PWR10 || defined __PCREL__
> +#if defined GCCMACRO_ARCH_PWR10 || defined GCCMACRO__PCREL__

OK. 3/5, 4/5.

>    if ((GLRO (dl_hwcap2) & PPC_FEATURE2_ARCH_3_1) == 0)
>      _dl_fatal_printf ("\
>  Fatal glibc error: CPU lacks ISA 3.10 support (POWER10 or later required)\n");
>  #endif
> -#ifdef __MMA__
> +#ifdef GCCMACRO__MMA__

OK. 5/5.

>    if ((GLRO (dl_hwcap2) & PPC_FEATURE2_MMA) == 0)
>      _dl_fatal_printf ("\
>  Fatal glibc error: CPU lacks MMA support (POWER10 or later required)\n");


-- 
Cheers,
Carlos.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 6/6] s390x: Use <gcc-macros.h> in early HWCAP check
  2022-01-14 16:53 ` [PATCH 6/6] s390x: Use <gcc-macros.h> in early HWCAP check Florian Weimer
@ 2022-01-14 18:52   ` Carlos O'Donell
  0 siblings, 0 replies; 16+ messages in thread
From: Carlos O'Donell @ 2022-01-14 18:52 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha

On 1/14/22 11:53, Florian Weimer via Libc-alpha wrote:
> This is required so that the checks still work if $(early-cflags)
> selects a different ISA level.

LGTM. No regressions on x86_64 and i686 builders. No CI/CD regressions.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>


> ---
>  sysdeps/s390/s390-64/dl-hwcap-check.h | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 

[carlos@athas glibc-pristine]$ grep -rl '__ARCH__' *
sysdeps/s390/s390-64/dl-hwcap-check.h

Just one file we care about wrapping.


> diff --git a/sysdeps/s390/s390-64/dl-hwcap-check.h b/sysdeps/s390/s390-64/dl-hwcap-check.h
> index 53e02250b8..f769932325 100644
> --- a/sysdeps/s390/s390-64/dl-hwcap-check.h
> +++ b/sysdeps/s390/s390-64/dl-hwcap-check.h
> @@ -19,17 +19,18 @@
>  #ifndef _DL_HWCAP_CHECK_H
>  #define _DL_HWCAP_CHECK_H
>  
> +#include <gcc-macros.h>

OK. 2 checks need wrapping.

>  #include <ldsodefs.h>
>  
>  static inline void
>  dl_hwcap_check (void)
>  {
>  #if defined __ARCH__
> -# if __ARCH__ >= 13
> +# if GCCMACRO__ARCH__ >= 13

OK. 1/2.

>    if (!(GLRO(dl_hwcap) & HWCAP_S390_VXRS_EXT2))
>      _dl_fatal_printf ("\
>  Fatal glibc error: CPU lacks VXRS_EXT2 support (z15 or later required)\n");
> -# elif __ARCH__ >= 12
> +# elif GCCMACRO__ARCH__ >= 12

OK. 2/2.

>    if (!(GLRO(dl_hwcap) & HWCAP_S390_VXE))
>      _dl_fatal_printf ("\
>  Fatal glibc error: CPU lacks VXE support (z14 or later required)\n");


-- 
Cheers,
Carlos.


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2022-01-14 18:52 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-14 16:51 [PATCH v2 0/6] Reliable CPU compatibility diagnostics in ld.so Florian Weimer
2022-01-14 16:52 ` [PATCH v2 1/6] elf/Makefile: Reflow and sort most variable assignments Florian Weimer
2022-01-14 18:39   ` H.J. Lu
2022-01-14 16:52 ` [PATCH v2 2/6] elf: Split dl-printf.c from dl-misc.c Florian Weimer
2022-01-14 18:40   ` H.J. Lu
2022-01-14 16:52 ` [PATCH v2 3/6] Add --with-rtld-early-cflags configure option Florian Weimer
2022-01-14 18:38   ` H.J. Lu
2022-01-14 16:53 ` [PATCH v2 4/6] powerpc64le: Use <gcc-macros.h> in early HWCAP check Florian Weimer
2022-01-14 18:51   ` Carlos O'Donell
2022-01-14 16:53 ` [PATCH v2 5/6] x86: Add x86-64-vN check to early startup Florian Weimer
2022-01-14 18:40   ` H.J. Lu
2022-01-14 16:53 ` [PATCH 6/6] s390x: Use <gcc-macros.h> in early HWCAP check Florian Weimer
2022-01-14 18:52   ` Carlos O'Donell
2022-01-14 17:42 ` [PATCH v2 0/6] Reliable CPU compatibility diagnostics in ld.so Joseph Myers
2022-01-14 17:59   ` Florian Weimer
2022-01-14 18:51     ` Carlos O'Donell

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).