* [PATCH 0/7] Reliable CPU compatibility diagnostics in ld.so @ 2022-01-14 12:40 Florian Weimer 2022-01-14 12:40 ` [PATCH 1/7] x86: HAVE_X86_LAHF_SAHF, HAVE_X86_MOVBE and -march=x86-64-vN (bug 28782) Florian Weimer ` (6 more replies) 0 siblings, 7 replies; 24+ messages in thread From: Florian Weimer @ 2022-01-14 12:40 UTC (permalink / raw) To: libc-alpha; +Cc: H.J. Lu, Stefan Liebler, Tulio Magno Quites Machado Filho This series enables reliable CPU compatibility diagnostics by building the early parts of the dynamic loader with an older ISA level than the rest of glibc. I tested this with our POWER9 build flags (running on POWER8), and with -march=x86-64-v4 on a x86-64-v3 system. In both cases, an accurate erorr is printed. Also built with build-many-glibcs.py, and tested on i686-linux-gnu and x86_64-linux-gnu,. Florian Weimer (7): x86: HAVE_X86_LAHF_SAHF, HAVE_X86_MOVBE and -march=x86-64-vN (bug 28782) Generate gcc-macros.h elf: Split dl-printf.c from dl-misc.c Add --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 Makeconfig | 9 + config.make.in | 1 + configure | 13 + configure.ac | 6 + elf/Makefile | 10 +- 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/configure | 4 +- sysdeps/x86/configure.ac | 4 +- sysdeps/x86/dl-get-cpu-features.c | 31 +- 14 files changed, 384 insertions(+), 289 deletions(-) create mode 100644 elf/dl-printf.c base-commit: 4997a533ae4b51ef66a6b68862b7578a7acb82df -- 2.34.1 ^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 1/7] x86: HAVE_X86_LAHF_SAHF, HAVE_X86_MOVBE and -march=x86-64-vN (bug 28782) 2022-01-14 12:40 [PATCH 0/7] Reliable CPU compatibility diagnostics in ld.so Florian Weimer @ 2022-01-14 12:40 ` Florian Weimer 2022-01-14 14:21 ` H.J. Lu 2022-01-14 12:40 ` [PATCH 2/7] Generate gcc-macros.h Florian Weimer ` (5 subsequent siblings) 6 siblings, 1 reply; 24+ messages in thread From: Florian Weimer @ 2022-01-14 12:40 UTC (permalink / raw) To: libc-alpha HAVE_X86_LAHF_SAHF is implied by x86-64-v2, and HAVE_X86_MOVBE by x86-64-v3. The individual flag does not appear in -fverbose-asm flag output even if the ISA level implies it. --- sysdeps/x86/configure | 4 ++-- sysdeps/x86/configure.ac | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sysdeps/x86/configure b/sysdeps/x86/configure index 62676bb686..7bdbfdc6dc 100644 --- a/sysdeps/x86/configure +++ b/sysdeps/x86/configure @@ -155,7 +155,7 @@ else (eval $ac_try) 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; } | grep -q "\-msahf"; then + test $ac_status = 0; }; } | grep -qE '(-msahf\b|-march=x86-64-v)'; then libc_cv_have_x86_lahf_sahf=yes fi fi @@ -176,7 +176,7 @@ else (eval $ac_try) 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; } | grep -q "\-mmovbe"; then + test $ac_status = 0; }; } | grep -qE '(-mmovbe\b|-march=x86-64-v([3-9]|[1-9][0-9]))'; then libc_cv_have_x86_movbe=yes fi fi diff --git a/sysdeps/x86/configure.ac b/sysdeps/x86/configure.ac index 04a12ab680..10d5c2e0e5 100644 --- a/sysdeps/x86/configure.ac +++ b/sysdeps/x86/configure.ac @@ -110,7 +110,7 @@ if test $libc_cv_include_x86_isa_level = yes; then AC_CACHE_CHECK([for LAHF/SAHF instruction support], libc_cv_have_x86_lahf_sahf, [dnl libc_cv_have_x86_lahf_sahf=no - if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - -x c /dev/null) | grep -q "\-msahf"; then + if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - -x c /dev/null) | grep -qE '(-msahf\b|-march=x86-64-v)'; then libc_cv_have_x86_lahf_sahf=yes fi]) if test $libc_cv_have_x86_lahf_sahf = yes; then @@ -119,7 +119,7 @@ if test $libc_cv_include_x86_isa_level = yes; then AC_CACHE_CHECK([for MOVBE instruction support], libc_cv_have_x86_movbe, [dnl libc_cv_have_x86_movbe=no - if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - -x c /dev/null) | grep -q "\-mmovbe"; then + if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - -x c /dev/null) | grep -qE '(-mmovbe\b|-march=x86-64-v(@<:@3-9@:>@|@<:@1-9@:>@@<:@0-9@:>@))'; then libc_cv_have_x86_movbe=yes fi]) if test $libc_cv_have_x86_movbe = yes; then -- 2.34.1 ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 1/7] x86: HAVE_X86_LAHF_SAHF, HAVE_X86_MOVBE and -march=x86-64-vN (bug 28782) 2022-01-14 12:40 ` [PATCH 1/7] x86: HAVE_X86_LAHF_SAHF, HAVE_X86_MOVBE and -march=x86-64-vN (bug 28782) Florian Weimer @ 2022-01-14 14:21 ` H.J. Lu 0 siblings, 0 replies; 24+ messages in thread From: H.J. Lu @ 2022-01-14 14:21 UTC (permalink / raw) To: Florian Weimer; +Cc: GNU C Library On Fri, Jan 14, 2022 at 4:40 AM Florian Weimer <fweimer@redhat.com> wrote: > > HAVE_X86_LAHF_SAHF is implied by x86-64-v2, and HAVE_X86_MOVBE by > x86-64-v3. > > The individual flag does not appear in -fverbose-asm flag output > even if the ISA level implies it. > --- > sysdeps/x86/configure | 4 ++-- > sysdeps/x86/configure.ac | 4 ++-- > 2 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/sysdeps/x86/configure b/sysdeps/x86/configure > index 62676bb686..7bdbfdc6dc 100644 > --- a/sysdeps/x86/configure > +++ b/sysdeps/x86/configure > @@ -155,7 +155,7 @@ else > (eval $ac_try) 2>&5 > ac_status=$? > $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 > - test $ac_status = 0; }; } | grep -q "\-msahf"; then > + test $ac_status = 0; }; } | grep -qE '(-msahf\b|-march=x86-64-v)'; then > libc_cv_have_x86_lahf_sahf=yes > fi > fi > @@ -176,7 +176,7 @@ else > (eval $ac_try) 2>&5 > ac_status=$? > $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 > - test $ac_status = 0; }; } | grep -q "\-mmovbe"; then > + test $ac_status = 0; }; } | grep -qE '(-mmovbe\b|-march=x86-64-v([3-9]|[1-9][0-9]))'; then > libc_cv_have_x86_movbe=yes > fi > fi > diff --git a/sysdeps/x86/configure.ac b/sysdeps/x86/configure.ac > index 04a12ab680..10d5c2e0e5 100644 > --- a/sysdeps/x86/configure.ac > +++ b/sysdeps/x86/configure.ac > @@ -110,7 +110,7 @@ if test $libc_cv_include_x86_isa_level = yes; then > AC_CACHE_CHECK([for LAHF/SAHF instruction support], > libc_cv_have_x86_lahf_sahf, [dnl > libc_cv_have_x86_lahf_sahf=no > - if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - -x c /dev/null) | grep -q "\-msahf"; then > + if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - -x c /dev/null) | grep -qE '(-msahf\b|-march=x86-64-v)'; then > libc_cv_have_x86_lahf_sahf=yes > fi]) > if test $libc_cv_have_x86_lahf_sahf = yes; then > @@ -119,7 +119,7 @@ if test $libc_cv_include_x86_isa_level = yes; then > AC_CACHE_CHECK([for MOVBE instruction support], > libc_cv_have_x86_movbe, [dnl > libc_cv_have_x86_movbe=no > - if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - -x c /dev/null) | grep -q "\-mmovbe"; then > + if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -fverbose-asm -S -o - -x c /dev/null) | grep -qE '(-mmovbe\b|-march=x86-64-v(@<:@3-9@:>@|@<:@1-9@:>@@<:@0-9@:>@))'; then > libc_cv_have_x86_movbe=yes > fi]) > if test $libc_cv_have_x86_movbe = yes; then > -- > 2.34.1 > > LGTM. Reviewed-by: H.J. Lu <hjl.tools@gmail.com> Thanks. -- H.J. ^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 2/7] Generate gcc-macros.h 2022-01-14 12:40 [PATCH 0/7] Reliable CPU compatibility diagnostics in ld.so Florian Weimer 2022-01-14 12:40 ` [PATCH 1/7] x86: HAVE_X86_LAHF_SAHF, HAVE_X86_MOVBE and -march=x86-64-vN (bug 28782) Florian Weimer @ 2022-01-14 12:40 ` Florian Weimer 2022-01-14 14:24 ` H.J. Lu 2022-01-14 12:40 ` [PATCH 3/7] elf: Split dl-printf.c from dl-misc.c Florian Weimer ` (4 subsequent siblings) 6 siblings, 1 reply; 24+ messages in thread From: Florian Weimer @ 2022-01-14 12:40 UTC (permalink / raw) To: libc-alpha The file can be used to check the effect of the default compiler flags on code generation even in areas of the build that uses non-default compiler flags. --- Makeconfig | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Makeconfig b/Makeconfig index 9b6fc6b08f..2e79077343 100644 --- a/Makeconfig +++ b/Makeconfig @@ -1202,6 +1202,15 @@ $(common-objpfx)dl-tunable-list.stmp: \ touch $@ endif +# Dump the GCC macros used by the default compiler flags to a header +# file, so that they can be inspected when using different compiler +# flags. Add the GCCMACRO prefix to make these macro names unique. +$(common-objpfx)gcc-macros.h.in: $(common-objpfx)config.status + $(CC) $(CFLAGS) $(CPPFLAGS) -E -dM -x c -o $@ /dev/null +$(common-objpfx)gcc-macros.h: $(common-objpfx)gcc-macros.h.in + sed 's/^#define /#define GCCMACRO/' < $< > $@ +before-compile += $(common-objpfx)gcc-macros.h + # Generate version maps, but wait until sysdep-subdirs is known ifeq ($(sysd-sorted-done),t) ifeq ($(build-shared),yes) -- 2.34.1 ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 2/7] Generate gcc-macros.h 2022-01-14 12:40 ` [PATCH 2/7] Generate gcc-macros.h Florian Weimer @ 2022-01-14 14:24 ` H.J. Lu 0 siblings, 0 replies; 24+ messages in thread From: H.J. Lu @ 2022-01-14 14:24 UTC (permalink / raw) To: Florian Weimer; +Cc: GNU C Library On Fri, Jan 14, 2022 at 4:42 AM Florian Weimer via Libc-alpha <libc-alpha@sourceware.org> wrote: > > The file can be used to check the effect of the default compiler > flags on code generation even in areas of the build that uses > non-default compiler flags. > --- > Makeconfig | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/Makeconfig b/Makeconfig > index 9b6fc6b08f..2e79077343 100644 > --- a/Makeconfig > +++ b/Makeconfig > @@ -1202,6 +1202,15 @@ $(common-objpfx)dl-tunable-list.stmp: \ > touch $@ > endif > > +# Dump the GCC macros used by the default compiler flags to a header > +# file, so that they can be inspected when using different compiler > +# flags. Add the GCCMACRO prefix to make these macro names unique. > +$(common-objpfx)gcc-macros.h.in: $(common-objpfx)config.status > + $(CC) $(CFLAGS) $(CPPFLAGS) -E -dM -x c -o $@ /dev/null > +$(common-objpfx)gcc-macros.h: $(common-objpfx)gcc-macros.h.in > + sed 's/^#define /#define GCCMACRO/' < $< > $@ > +before-compile += $(common-objpfx)gcc-macros.h > + > # Generate version maps, but wait until sysdep-subdirs is known > ifeq ($(sysd-sorted-done),t) > ifeq ($(build-shared),yes) > -- > 2.34.1 > > LGTM. Reviewed-by: H.J. Lu <hjl.tools@gmail.com> Thanks. -- H.J. ^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 3/7] elf: Split dl-printf.c from dl-misc.c 2022-01-14 12:40 [PATCH 0/7] Reliable CPU compatibility diagnostics in ld.so Florian Weimer 2022-01-14 12:40 ` [PATCH 1/7] x86: HAVE_X86_LAHF_SAHF, HAVE_X86_MOVBE and -march=x86-64-vN (bug 28782) Florian Weimer 2022-01-14 12:40 ` [PATCH 2/7] Generate gcc-macros.h Florian Weimer @ 2022-01-14 12:40 ` Florian Weimer 2022-01-14 14:25 ` H.J. Lu 2022-01-14 12:40 ` [PATCH 4/7] Add --early-cflags configure option Florian Weimer ` (3 subsequent siblings) 6 siblings, 1 reply; 24+ messages in thread From: Florian Weimer @ 2022-01-14 12:40 UTC (permalink / raw) To: libc-alpha This allows to use different compiler flags for the diagnostics code. --- elf/Makefile | 2 +- elf/dl-misc.c | 281 +--------------------------------------------- elf/dl-printf.c | 292 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 297 insertions(+), 278 deletions(-) create mode 100644 elf/dl-printf.c diff --git a/elf/Makefile b/elf/Makefile index b86d116be9..0c4be43deb 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -31,7 +31,7 @@ routines = $(all-dl-routines) dl-support dl-iteratephdr \ # 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 \ + runtime init fini debug misc printf \ version profile tls origin scope \ execstack open close trampoline \ exception sort-maps lookup-direct \ 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] 24+ messages in thread
* Re: [PATCH 3/7] elf: Split dl-printf.c from dl-misc.c 2022-01-14 12:40 ` [PATCH 3/7] elf: Split dl-printf.c from dl-misc.c Florian Weimer @ 2022-01-14 14:25 ` H.J. Lu 2022-01-14 14:27 ` Florian Weimer 0 siblings, 1 reply; 24+ messages in thread From: H.J. Lu @ 2022-01-14 14:25 UTC (permalink / raw) To: Florian Weimer; +Cc: GNU C Library On Fri, Jan 14, 2022 at 4:42 AM Florian Weimer via Libc-alpha <libc-alpha@sourceware.org> wrote: > > This allows to use different compiler flags for the diagnostics > code. > --- > elf/Makefile | 2 +- > elf/dl-misc.c | 281 +--------------------------------------------- > elf/dl-printf.c | 292 ++++++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 297 insertions(+), 278 deletions(-) > create mode 100644 elf/dl-printf.c > > diff --git a/elf/Makefile b/elf/Makefile > index b86d116be9..0c4be43deb 100644 > --- a/elf/Makefile > +++ b/elf/Makefile > @@ -31,7 +31,7 @@ routines = $(all-dl-routines) dl-support dl-iteratephdr \ > # 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 \ > + runtime init fini debug misc printf \ > version profile tls origin scope \ > execstack open close trampoline \ > exception sort-maps lookup-direct \ Should we put one item per-line now? -- H.J. ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 3/7] elf: Split dl-printf.c from dl-misc.c 2022-01-14 14:25 ` H.J. Lu @ 2022-01-14 14:27 ` Florian Weimer 2022-01-14 14:32 ` H.J. Lu 0 siblings, 1 reply; 24+ messages in thread From: Florian Weimer @ 2022-01-14 14:27 UTC (permalink / raw) To: H.J. Lu; +Cc: GNU C Library * H. J. Lu: > On Fri, Jan 14, 2022 at 4:42 AM Florian Weimer via Libc-alpha > <libc-alpha@sourceware.org> wrote: >> >> This allows to use different compiler flags for the diagnostics >> code. >> --- >> elf/Makefile | 2 +- >> elf/dl-misc.c | 281 +--------------------------------------------- >> elf/dl-printf.c | 292 ++++++++++++++++++++++++++++++++++++++++++++++++ >> 3 files changed, 297 insertions(+), 278 deletions(-) >> create mode 100644 elf/dl-printf.c >> >> diff --git a/elf/Makefile b/elf/Makefile >> index b86d116be9..0c4be43deb 100644 >> --- a/elf/Makefile >> +++ b/elf/Makefile >> @@ -31,7 +31,7 @@ routines = $(all-dl-routines) dl-support dl-iteratephdr \ >> # 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 \ >> + runtime init fini debug misc printf \ >> version profile tls origin scope \ >> execstack open close trampoline \ >> exception sort-maps lookup-direct \ > > Should we put one item per-line now? And drop the addprefix? I can submit a separate patch for that. Thanks, Florian ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 3/7] elf: Split dl-printf.c from dl-misc.c 2022-01-14 14:27 ` Florian Weimer @ 2022-01-14 14:32 ` H.J. Lu 0 siblings, 0 replies; 24+ messages in thread From: H.J. Lu @ 2022-01-14 14:32 UTC (permalink / raw) To: Florian Weimer; +Cc: GNU C Library On Fri, Jan 14, 2022 at 6:27 AM Florian Weimer <fweimer@redhat.com> wrote: > > * H. J. Lu: > > > On Fri, Jan 14, 2022 at 4:42 AM Florian Weimer via Libc-alpha > > <libc-alpha@sourceware.org> wrote: > >> > >> This allows to use different compiler flags for the diagnostics > >> code. > >> --- > >> elf/Makefile | 2 +- > >> elf/dl-misc.c | 281 +--------------------------------------------- > >> elf/dl-printf.c | 292 ++++++++++++++++++++++++++++++++++++++++++++++++ > >> 3 files changed, 297 insertions(+), 278 deletions(-) > >> create mode 100644 elf/dl-printf.c > >> > >> diff --git a/elf/Makefile b/elf/Makefile > >> index b86d116be9..0c4be43deb 100644 > >> --- a/elf/Makefile > >> +++ b/elf/Makefile > >> @@ -31,7 +31,7 @@ routines = $(all-dl-routines) dl-support dl-iteratephdr \ > >> # 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 \ > >> + runtime init fini debug misc printf \ > >> version profile tls origin scope \ > >> execstack open close trampoline \ > >> exception sort-maps lookup-direct \ > > > > Should we put one item per-line now? > > And drop the addprefix? I can submit a separate patch for that. Yes. It will make adding the next file a bit easier. > Thanks, > Florian > -- H.J. ^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 4/7] Add --early-cflags configure option 2022-01-14 12:40 [PATCH 0/7] Reliable CPU compatibility diagnostics in ld.so Florian Weimer ` (2 preceding siblings ...) 2022-01-14 12:40 ` [PATCH 3/7] elf: Split dl-printf.c from dl-misc.c Florian Weimer @ 2022-01-14 12:40 ` Florian Weimer 2022-01-14 14:27 ` H.J. Lu 2022-01-14 12:40 ` [PATCH 5/7] powerpc64le: Use <gcc-macros.h> in early HWCAP check Florian Weimer ` (2 subsequent siblings) 6 siblings, 1 reply; 24+ messages in thread From: Florian Weimer @ 2022-01-14 12:40 UTC (permalink / raw) To: libc-alpha --- config.make.in | 1 + configure | 13 +++++++++++++ configure.ac | 6 ++++++ elf/Makefile | 8 ++++++++ manual/install.texi | 7 +++++++ 5 files changed, 35 insertions(+) diff --git a/config.make.in b/config.make.in index e8630a8d0c..e06f1ff49f 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@ +early-cflags = @early_cflags@ ASFLAGS-config = @ASFLAGS_config@ AR = @AR@ NM = @NM@ diff --git a/configure b/configure index 3f956cf777..6eedd8c3a7 100755 --- a/configure +++ b/configure @@ -681,6 +681,7 @@ force_install bindnow hardcoded_path_in_tests enable_timezone_tools +early_cflags extra_nonshared_cflags use_default_link sysheaders @@ -761,6 +762,7 @@ with_selinux with_headers with_default_link with_nonshared_cflags +with_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-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-early-cflags was given. +if test "${with_early_cflags+set}" = set; then : + withval=$with_early_cflags; early_cflags=$withval +else + 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..445b0b7f15 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([early-cflags], + AS_HELP_STRING([--with-early-cflags=CFLAGS], + [build early initialization with additional CFLAGS]), + [early_cflags=$withval], + [early_cflags=]) +AC_SUBST(early_cflags) AC_ARG_WITH([timeoutfactor], AS_HELP_STRING([--with-timeoutfactor=NUM], diff --git a/elf/Makefile b/elf/Makefile index 0c4be43deb..9fcb4ebd13 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -99,6 +99,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 += $(early-cflags) +CFLAGS-dl-sysdep.os += $(early-cflags) +CFLAGS-dl-tunables.os += $(early-cflags) +CFLAGS-dl-write.os += $(early-cflags) +CFLAGS-dl-writev.os += $(early-cflags) +CFLAGS-rtld.os += $(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..27d5893c5e 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-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] 24+ messages in thread
* Re: [PATCH 4/7] Add --early-cflags configure option 2022-01-14 12:40 ` [PATCH 4/7] Add --early-cflags configure option Florian Weimer @ 2022-01-14 14:27 ` H.J. Lu 2022-01-14 14:29 ` Florian Weimer 0 siblings, 1 reply; 24+ messages in thread From: H.J. Lu @ 2022-01-14 14:27 UTC (permalink / raw) To: Florian Weimer; +Cc: GNU C Library On Fri, Jan 14, 2022 at 4:43 AM Florian Weimer via Libc-alpha <libc-alpha@sourceware.org> wrote: > > --- > config.make.in | 1 + > configure | 13 +++++++++++++ > configure.ac | 6 ++++++ > elf/Makefile | 8 ++++++++ > manual/install.texi | 7 +++++++ > 5 files changed, 35 insertions(+) > > diff --git a/config.make.in b/config.make.in > index e8630a8d0c..e06f1ff49f 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@ > +early-cflags = @early_cflags@ > ASFLAGS-config = @ASFLAGS_config@ > AR = @AR@ > NM = @NM@ > diff --git a/configure b/configure > index 3f956cf777..6eedd8c3a7 100755 > --- a/configure > +++ b/configure > @@ -681,6 +681,7 @@ force_install > bindnow > hardcoded_path_in_tests > enable_timezone_tools > +early_cflags > extra_nonshared_cflags > use_default_link > sysheaders > @@ -761,6 +762,7 @@ with_selinux > with_headers > with_default_link > with_nonshared_cflags > +with_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-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-early-cflags was given. > +if test "${with_early_cflags+set}" = set; then : > + withval=$with_early_cflags; early_cflags=$withval > +else > + 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..445b0b7f15 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([early-cflags], > + AS_HELP_STRING([--with-early-cflags=CFLAGS], > + [build early initialization with additional CFLAGS]), > + [early_cflags=$withval], > + [early_cflags=]) > +AC_SUBST(early_cflags) > > AC_ARG_WITH([timeoutfactor], > AS_HELP_STRING([--with-timeoutfactor=NUM], > diff --git a/elf/Makefile b/elf/Makefile > index 0c4be43deb..9fcb4ebd13 100644 > --- a/elf/Makefile > +++ b/elf/Makefile > @@ -99,6 +99,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 += $(early-cflags) > +CFLAGS-dl-sysdep.os += $(early-cflags) > +CFLAGS-dl-tunables.os += $(early-cflags) > +CFLAGS-dl-write.os += $(early-cflags) > +CFLAGS-dl-writev.os += $(early-cflags) > +CFLAGS-rtld.os += $(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..27d5893c5e 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-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). > + Isn't it limited to rtld? If yes, I prefer --with-early-rtld-cflags > @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 > > -- H.J. ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 4/7] Add --early-cflags configure option 2022-01-14 14:27 ` H.J. Lu @ 2022-01-14 14:29 ` Florian Weimer 2022-01-14 14:33 ` H.J. Lu 0 siblings, 1 reply; 24+ messages in thread From: Florian Weimer @ 2022-01-14 14:29 UTC (permalink / raw) To: H.J. Lu; +Cc: GNU C Library * H. J. Lu: >> +@item --with-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). > > Isn't it limited to rtld? If yes, I prefer --with-early-rtld-cflags It's currently restricted to ld.so. But we might enhance it to cover static linking in the future, too. Thanks, Florian ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 4/7] Add --early-cflags configure option 2022-01-14 14:29 ` Florian Weimer @ 2022-01-14 14:33 ` H.J. Lu 2022-01-14 14:34 ` Florian Weimer 0 siblings, 1 reply; 24+ messages in thread From: H.J. Lu @ 2022-01-14 14:33 UTC (permalink / raw) To: Florian Weimer; +Cc: GNU C Library On Fri, Jan 14, 2022 at 6:29 AM Florian Weimer <fweimer@redhat.com> wrote: > > * H. J. Lu: > > >> +@item --with-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). > > > > Isn't it limited to rtld? If yes, I prefer --with-early-rtld-cflags > > It's currently restricted to ld.so. But we might enhance it to cover > static linking in the future, too. But static linking may need a different early CFLAGS. -- H.J. ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 4/7] Add --early-cflags configure option 2022-01-14 14:33 ` H.J. Lu @ 2022-01-14 14:34 ` Florian Weimer 0 siblings, 0 replies; 24+ messages in thread From: Florian Weimer @ 2022-01-14 14:34 UTC (permalink / raw) To: H.J. Lu; +Cc: GNU C Library * H. J. Lu: > On Fri, Jan 14, 2022 at 6:29 AM Florian Weimer <fweimer@redhat.com> wrote: >> >> * H. J. Lu: >> >> >> +@item --with-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). >> > >> > Isn't it limited to rtld? If yes, I prefer --with-early-rtld-cflags >> >> It's currently restricted to ld.so. But we might enhance it to cover >> static linking in the future, too. > > But static linking may need a different early CFLAGS. Fair point, I will send an updated patch. Thanks, Florian ^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 5/7] powerpc64le: Use <gcc-macros.h> in early HWCAP check 2022-01-14 12:40 [PATCH 0/7] Reliable CPU compatibility diagnostics in ld.so Florian Weimer ` (3 preceding siblings ...) 2022-01-14 12:40 ` [PATCH 4/7] Add --early-cflags configure option Florian Weimer @ 2022-01-14 12:40 ` Florian Weimer 2022-01-14 12:41 ` [PATCH 6/7] x86: Add x86-64-vN check to early startup Florian Weimer 2022-01-14 12:41 ` [PATCH 7/7] s390x: Use <gcc-macros.h> in early HWCAP check Florian Weimer 6 siblings, 0 replies; 24+ messages in thread From: Florian Weimer @ 2022-01-14 12:40 UTC (permalink / raw) To: libc-alpha; +Cc: Tulio Magno Quites Machado Filho 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] 24+ messages in thread
* [PATCH 6/7] x86: Add x86-64-vN check to early startup 2022-01-14 12:40 [PATCH 0/7] Reliable CPU compatibility diagnostics in ld.so Florian Weimer ` (4 preceding siblings ...) 2022-01-14 12:40 ` [PATCH 5/7] powerpc64le: Use <gcc-macros.h> in early HWCAP check Florian Weimer @ 2022-01-14 12:41 ` Florian Weimer 2022-01-14 12:41 ` [PATCH 7/7] s390x: Use <gcc-macros.h> in early HWCAP check Florian Weimer 6 siblings, 0 replies; 24+ messages in thread From: Florian Weimer @ 2022-01-14 12:41 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. --- 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..0c5ab42667 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 += $(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] 24+ messages in thread
* [PATCH 7/7] s390x: Use <gcc-macros.h> in early HWCAP check 2022-01-14 12:40 [PATCH 0/7] Reliable CPU compatibility diagnostics in ld.so Florian Weimer ` (5 preceding siblings ...) 2022-01-14 12:41 ` [PATCH 6/7] x86: Add x86-64-vN check to early startup Florian Weimer @ 2022-01-14 12:41 ` Florian Weimer 2022-01-18 12:42 ` Stefan Liebler 6 siblings, 1 reply; 24+ messages in thread From: Florian Weimer @ 2022-01-14 12:41 UTC (permalink / raw) To: libc-alpha; +Cc: Stefan Liebler 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] 24+ messages in thread
* Re: [PATCH 7/7] s390x: Use <gcc-macros.h> in early HWCAP check 2022-01-14 12:41 ` [PATCH 7/7] s390x: Use <gcc-macros.h> in early HWCAP check Florian Weimer @ 2022-01-18 12:42 ` Stefan Liebler 2022-01-18 12:54 ` Florian Weimer 0 siblings, 1 reply; 24+ messages in thread From: Stefan Liebler @ 2022-01-18 12:42 UTC (permalink / raw) To: Florian Weimer, libc-alpha On 14/01/2022 13:41, Florian Weimer wrote: > 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"); Hi Florian, I'm not quite sure if all your patches are already committed. I've just give it a try with commit f8b765bec44e6c464a7eabf80e58c6851ca15ac3: - configure glibc with --with-rtld-early-cflags=-march=zEC12 and CFLAGS=-march=z15 on a z15. - Rebooted with novx-kernel-parameter => vector-related HWCAPs are disabled and executing vector-instructions leads to a crash - run a helloworld-program: crash due to vector-instruction in _dl_setup_hash, which is called in _dl_start_final before _dl_sysdep_start is called which runs dl_hwcap_check. I've checked the build-log and see that the following files are compiled with -march=zEC12: - dl-printf.c - ../sysdeps/unix/sysv/linux/dl-write.c - dl-tunables.c - ../sysdeps/unix/sysv/linux/dl-sysdep.c - rtld.c Bye Stefan ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 7/7] s390x: Use <gcc-macros.h> in early HWCAP check 2022-01-18 12:42 ` Stefan Liebler @ 2022-01-18 12:54 ` Florian Weimer 2022-01-18 13:31 ` Stefan Liebler 0 siblings, 1 reply; 24+ messages in thread From: Florian Weimer @ 2022-01-18 12:54 UTC (permalink / raw) To: Stefan Liebler; +Cc: libc-alpha [-- Attachment #1: Type: text/plain, Size: 902 bytes --] * Stefan Liebler: > I'm not quite sure if all your patches are already committed. I've just > give it a try with commit f8b765bec44e6c464a7eabf80e58c6851ca15ac3: > > - configure glibc with --with-rtld-early-cflags=-march=zEC12 and > CFLAGS=-march=z15 on a z15. > > - Rebooted with novx-kernel-parameter => vector-related HWCAPs are > disabled and executing vector-instructions leads to a crash > > - run a helloworld-program: crash due to vector-instruction in > _dl_setup_hash, which is called in _dl_start_final before > _dl_sysdep_start is called which runs dl_hwcap_check. > > I've checked the build-log and see that the following files are compiled > with -march=zEC12: > - dl-printf.c > - ../sysdeps/unix/sysv/linux/dl-write.c > - dl-tunables.c > - ../sysdeps/unix/sysv/linux/dl-sysdep.c > - rtld.c Sorry, I missed that requirement. Would you mind testing the attached patch? Thanks, Florian [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-elf-Move-_dl_setup_hash-to-its-own-file.patch --] [-- Type: text/x-patch, Size: 5233 bytes --] From dae7882e11191cab17afb22dba4ebba69f433d93 Mon Sep 17 00:00:00 2001 Message-Id: <dae7882e11191cab17afb22dba4ebba69f433d93.1642510437.git.fweimer@redhat.com> From: Florian Weimer <fweimer@redhat.com> Date: Tue, 18 Jan 2022 13:53:11 +0100 Subject: [PATCH] elf: Move _dl_setup_hash to its own file To: libc-alpha@sourceware.org And compile it with the early CFLAGS. _dl_setup_hash is called very early for the ld.so link map, so it should be compiled differently. --- elf/Makefile | 2 ++ elf/dl-lookup.c | 45 -------------------------------- elf/dl-setup_hash.c | 63 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 45 deletions(-) create mode 100644 elf/dl-setup_hash.c diff --git a/elf/Makefile b/elf/Makefile index c6c4710e16..692a65b061 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -74,6 +74,7 @@ dl-routines = \ dl-reloc \ dl-runtime \ dl-scope \ + dl-setup_hash \ dl-sort-maps \ dl-thread_gscope_wait \ dl-tls \ @@ -169,6 +170,7 @@ 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-setup_hash.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) diff --git a/elf/dl-lookup.c b/elf/dl-lookup.c index f43ae150b7..cbf46fda62 100644 --- a/elf/dl-lookup.c +++ b/elf/dl-lookup.c @@ -953,51 +953,6 @@ _dl_lookup_symbol_x (const char *undef_name, struct link_map *undef_map, } -/* Cache the location of MAP's hash table. */ - -void -_dl_setup_hash (struct link_map *map) -{ - Elf_Symndx *hash; - - if (__glibc_likely (map->l_info[ELF_MACHINE_GNU_HASH_ADDRIDX] != NULL)) - { - Elf32_Word *hash32 - = (void *) D_PTR (map, l_info[ELF_MACHINE_GNU_HASH_ADDRIDX]); - map->l_nbuckets = *hash32++; - Elf32_Word symbias = *hash32++; - Elf32_Word bitmask_nwords = *hash32++; - /* Must be a power of two. */ - assert ((bitmask_nwords & (bitmask_nwords - 1)) == 0); - map->l_gnu_bitmask_idxbits = bitmask_nwords - 1; - map->l_gnu_shift = *hash32++; - - map->l_gnu_bitmask = (ElfW(Addr) *) hash32; - hash32 += __ELF_NATIVE_CLASS / 32 * bitmask_nwords; - - map->l_gnu_buckets = hash32; - hash32 += map->l_nbuckets; - map->l_gnu_chain_zero = hash32 - symbias; - - /* Initialize MIPS xhash translation table. */ - ELF_MACHINE_XHASH_SETUP (hash32, symbias, map); - - return; - } - - if (!map->l_info[DT_HASH]) - return; - hash = (void *) D_PTR (map, l_info[DT_HASH]); - - map->l_nbuckets = *hash++; - /* Skip nchain. */ - hash++; - map->l_buckets = hash; - hash += map->l_nbuckets; - map->l_chain = hash; -} - - static void _dl_debug_bindings (const char *undef_name, struct link_map *undef_map, const ElfW(Sym) **ref, struct sym_val *value, diff --git a/elf/dl-setup_hash.c b/elf/dl-setup_hash.c new file mode 100644 index 0000000000..6dd57c5c94 --- /dev/null +++ b/elf/dl-setup_hash.c @@ -0,0 +1,63 @@ +/* Cache the location of a link map hash table. + Copyright (C) 1995-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 <assert.h> +#include <link.h> +#include <ldsodefs.h> + +void +_dl_setup_hash (struct link_map *map) +{ + Elf_Symndx *hash; + + if (__glibc_likely (map->l_info[ELF_MACHINE_GNU_HASH_ADDRIDX] != NULL)) + { + Elf32_Word *hash32 + = (void *) D_PTR (map, l_info[ELF_MACHINE_GNU_HASH_ADDRIDX]); + map->l_nbuckets = *hash32++; + Elf32_Word symbias = *hash32++; + Elf32_Word bitmask_nwords = *hash32++; + /* Must be a power of two. */ + assert ((bitmask_nwords & (bitmask_nwords - 1)) == 0); + map->l_gnu_bitmask_idxbits = bitmask_nwords - 1; + map->l_gnu_shift = *hash32++; + + map->l_gnu_bitmask = (ElfW(Addr) *) hash32; + hash32 += __ELF_NATIVE_CLASS / 32 * bitmask_nwords; + + map->l_gnu_buckets = hash32; + hash32 += map->l_nbuckets; + map->l_gnu_chain_zero = hash32 - symbias; + + /* Initialize MIPS xhash translation table. */ + ELF_MACHINE_XHASH_SETUP (hash32, symbias, map); + + return; + } + + if (!map->l_info[DT_HASH]) + return; + hash = (void *) D_PTR (map, l_info[DT_HASH]); + + map->l_nbuckets = *hash++; + /* Skip nchain. */ + hash++; + map->l_buckets = hash; + hash += map->l_nbuckets; + map->l_chain = hash; +} -- 2.34.1 ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 7/7] s390x: Use <gcc-macros.h> in early HWCAP check 2022-01-18 12:54 ` Florian Weimer @ 2022-01-18 13:31 ` Stefan Liebler 2022-01-18 13:33 ` Florian Weimer 0 siblings, 1 reply; 24+ messages in thread From: Stefan Liebler @ 2022-01-18 13:31 UTC (permalink / raw) To: Florian Weimer; +Cc: libc-alpha On 18/01/2022 13:54, Florian Weimer wrote: > * Stefan Liebler: > >> I'm not quite sure if all your patches are already committed. I've just >> give it a try with commit f8b765bec44e6c464a7eabf80e58c6851ca15ac3: >> >> - configure glibc with --with-rtld-early-cflags=-march=zEC12 and >> CFLAGS=-march=z15 on a z15. >> >> - Rebooted with novx-kernel-parameter => vector-related HWCAPs are >> disabled and executing vector-instructions leads to a crash >> >> - run a helloworld-program: crash due to vector-instruction in >> _dl_setup_hash, which is called in _dl_start_final before >> _dl_sysdep_start is called which runs dl_hwcap_check. >> >> I've checked the build-log and see that the following files are compiled >> with -march=zEC12: >> - dl-printf.c >> - ../sysdeps/unix/sysv/linux/dl-write.c >> - dl-tunables.c >> - ../sysdeps/unix/sysv/linux/dl-sysdep.c >> - rtld.c > > Sorry, I missed that requirement. > > Would you mind testing the attached patch? > > Thanks, > Florian Sure. Now it works fine and I get the expected: Fatal glibc error: CPU lacks VXRS_EXT2 support (z15 or later required) Thanks, Stefan ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 7/7] s390x: Use <gcc-macros.h> in early HWCAP check 2022-01-18 13:31 ` Stefan Liebler @ 2022-01-18 13:33 ` Florian Weimer 2022-01-18 13:38 ` Stefan Liebler 0 siblings, 1 reply; 24+ messages in thread From: Florian Weimer @ 2022-01-18 13:33 UTC (permalink / raw) To: Stefan Liebler; +Cc: libc-alpha * Stefan Liebler: > On 18/01/2022 13:54, Florian Weimer wrote: >> * Stefan Liebler: >> >>> I'm not quite sure if all your patches are already committed. I've just >>> give it a try with commit f8b765bec44e6c464a7eabf80e58c6851ca15ac3: >>> >>> - configure glibc with --with-rtld-early-cflags=-march=zEC12 and >>> CFLAGS=-march=z15 on a z15. >>> >>> - Rebooted with novx-kernel-parameter => vector-related HWCAPs are >>> disabled and executing vector-instructions leads to a crash >>> >>> - run a helloworld-program: crash due to vector-instruction in >>> _dl_setup_hash, which is called in _dl_start_final before >>> _dl_sysdep_start is called which runs dl_hwcap_check. >>> >>> I've checked the build-log and see that the following files are compiled >>> with -march=zEC12: >>> - dl-printf.c >>> - ../sysdeps/unix/sysv/linux/dl-write.c >>> - dl-tunables.c >>> - ../sysdeps/unix/sysv/linux/dl-sysdep.c >>> - rtld.c >> >> Sorry, I missed that requirement. >> >> Would you mind testing the attached patch? >> >> Thanks, >> Florian > > Sure. Now it works fine and I get the expected: > Fatal glibc error: CPU lacks VXRS_EXT2 support (z15 or later required) Thanks. Should I push it with your Reviewed-by: and Tested-by:? Florian ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 7/7] s390x: Use <gcc-macros.h> in early HWCAP check 2022-01-18 13:33 ` Florian Weimer @ 2022-01-18 13:38 ` Stefan Liebler 2022-01-18 21:03 ` Joseph Myers 0 siblings, 1 reply; 24+ messages in thread From: Stefan Liebler @ 2022-01-18 13:38 UTC (permalink / raw) To: Florian Weimer; +Cc: libc-alpha On 18/01/2022 14:33, Florian Weimer wrote: > * Stefan Liebler: > >> On 18/01/2022 13:54, Florian Weimer wrote: >>> * Stefan Liebler: >>> >>>> I'm not quite sure if all your patches are already committed. I've just >>>> give it a try with commit f8b765bec44e6c464a7eabf80e58c6851ca15ac3: >>>> >>>> - configure glibc with --with-rtld-early-cflags=-march=zEC12 and >>>> CFLAGS=-march=z15 on a z15. >>>> >>>> - Rebooted with novx-kernel-parameter => vector-related HWCAPs are >>>> disabled and executing vector-instructions leads to a crash >>>> >>>> - run a helloworld-program: crash due to vector-instruction in >>>> _dl_setup_hash, which is called in _dl_start_final before >>>> _dl_sysdep_start is called which runs dl_hwcap_check. >>>> >>>> I've checked the build-log and see that the following files are compiled >>>> with -march=zEC12: >>>> - dl-printf.c >>>> - ../sysdeps/unix/sysv/linux/dl-write.c >>>> - dl-tunables.c >>>> - ../sysdeps/unix/sysv/linux/dl-sysdep.c >>>> - rtld.c >>> >>> Sorry, I missed that requirement. >>> >>> Would you mind testing the attached patch? >>> >>> Thanks, >>> Florian >> >> Sure. Now it works fine and I get the expected: >> Fatal glibc error: CPU lacks VXRS_EXT2 support (z15 or later required) > > Thanks. Should I push it with your Reviewed-by: and Tested-by:? > > Florian > Yes, this if fine for me. I've had a look at the patch and it just extracted the _dl_setup_hash function into a new file which is then build with the rtld-early-cflags. Reviewed-by: Stefan Liebler <stli@linux.ibm.com> Tested-by: Stefan Liebler <stli@linux.ibm.com> ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 7/7] s390x: Use <gcc-macros.h> in early HWCAP check 2022-01-18 13:38 ` Stefan Liebler @ 2022-01-18 21:03 ` Joseph Myers 2022-01-18 21:21 ` Florian Weimer 0 siblings, 1 reply; 24+ messages in thread From: Joseph Myers @ 2022-01-18 21:03 UTC (permalink / raw) To: Stefan Liebler; +Cc: Florian Weimer, libc-alpha The "elf: Move _dl_setup_hash to its own file" change (commit c90363403b57b3b7919061851cb3e6d9c85e784a) appears to have broken the build for MIPS (all ABIs). In file included from ../sysdeps/gnu/ldsodefs.h:46, from ../sysdeps/unix/sysv/linux/ldsodefs.h:25, from ../sysdeps/unix/sysv/linux/mips/ldsodefs.h:22, from dl-setup_hash.c:21: dl-setup_hash.c: In function '_dl_setup_hash': ../sysdeps/mips/ldsodefs.h:39:33: error: implicit declaration of function 'DT_MIPS'; did you mean 'EM_MIPS'? [-Werror=implicit-function-declaration] 39 | (hash32) += (map)->l_info[DT_MIPS (SYMTABNO)]->d_un.d_val - (symbias); \ | ^~~~~~~ dl-setup_hash.c:48:7: note: in expansion of macro 'ELF_MACHINE_XHASH_SETUP' 48 | ELF_MACHINE_XHASH_SETUP (hash32, symbias, map); | ^~~~~~~~~~~~~~~~~~~~~~~ ../sysdeps/mips/ldsodefs.h:39:42: error: 'SYMTABNO' undeclared (first use in this function) 39 | (hash32) += (map)->l_info[DT_MIPS (SYMTABNO)]->d_un.d_val - (symbias); \ | ^~~~~~~~ dl-setup_hash.c:48:7: note: in expansion of macro 'ELF_MACHINE_XHASH_SETUP' 48 | ELF_MACHINE_XHASH_SETUP (hash32, symbias, map); | ^~~~~~~~~~~~~~~~~~~~~~~ ../sysdeps/mips/ldsodefs.h:39:42: note: each undeclared identifier is reported only once for each function it appears in 39 | (hash32) += (map)->l_info[DT_MIPS (SYMTABNO)]->d_un.d_val - (symbias); \ | ^~~~~~~~ dl-setup_hash.c:48:7: note: in expansion of macro 'ELF_MACHINE_XHASH_SETUP' 48 | ELF_MACHINE_XHASH_SETUP (hash32, symbias, map); | ^~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors -- Joseph S. Myers joseph@codesourcery.com ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 7/7] s390x: Use <gcc-macros.h> in early HWCAP check 2022-01-18 21:03 ` Joseph Myers @ 2022-01-18 21:21 ` Florian Weimer 0 siblings, 0 replies; 24+ messages in thread From: Florian Weimer @ 2022-01-18 21:21 UTC (permalink / raw) To: Joseph Myers; +Cc: Stefan Liebler, libc-alpha * Joseph Myers: > The "elf: Move _dl_setup_hash to its own file" change (commit > c90363403b57b3b7919061851cb3e6d9c85e784a) appears to have broken the build > for MIPS (all ABIs). Sorry, I didn't run a full build of a glibcs this time. 8-/ I did check that ELF_MACHINE_XHASH_SETUP was defined in mips <ldsodefs.h>, but missed its macro dependency. I'm build-testing a patch right now, will post it once it finishes building. Thanks, Florian ^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2022-01-18 21:21 UTC | newest] Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-01-14 12:40 [PATCH 0/7] Reliable CPU compatibility diagnostics in ld.so Florian Weimer 2022-01-14 12:40 ` [PATCH 1/7] x86: HAVE_X86_LAHF_SAHF, HAVE_X86_MOVBE and -march=x86-64-vN (bug 28782) Florian Weimer 2022-01-14 14:21 ` H.J. Lu 2022-01-14 12:40 ` [PATCH 2/7] Generate gcc-macros.h Florian Weimer 2022-01-14 14:24 ` H.J. Lu 2022-01-14 12:40 ` [PATCH 3/7] elf: Split dl-printf.c from dl-misc.c Florian Weimer 2022-01-14 14:25 ` H.J. Lu 2022-01-14 14:27 ` Florian Weimer 2022-01-14 14:32 ` H.J. Lu 2022-01-14 12:40 ` [PATCH 4/7] Add --early-cflags configure option Florian Weimer 2022-01-14 14:27 ` H.J. Lu 2022-01-14 14:29 ` Florian Weimer 2022-01-14 14:33 ` H.J. Lu 2022-01-14 14:34 ` Florian Weimer 2022-01-14 12:40 ` [PATCH 5/7] powerpc64le: Use <gcc-macros.h> in early HWCAP check Florian Weimer 2022-01-14 12:41 ` [PATCH 6/7] x86: Add x86-64-vN check to early startup Florian Weimer 2022-01-14 12:41 ` [PATCH 7/7] s390x: Use <gcc-macros.h> in early HWCAP check Florian Weimer 2022-01-18 12:42 ` Stefan Liebler 2022-01-18 12:54 ` Florian Weimer 2022-01-18 13:31 ` Stefan Liebler 2022-01-18 13:33 ` Florian Weimer 2022-01-18 13:38 ` Stefan Liebler 2022-01-18 21:03 ` Joseph Myers 2022-01-18 21:21 ` Florian Weimer
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).