From patchwork Fri Jan 14 12:40:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 50025 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E3EC3836005 for ; Fri, 14 Jan 2022 12:41:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E3EC3836005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642164080; bh=XpIXDzrb4doItTwS2ua7286YWcSahD/LO3Q9Ku/d78o=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=FM1p6E6tAvtWB0gJNeqlFCHVQuTKH8uX1s+jk9pC0KXTQK8SEpqAVy6itGG57iE3T JQUIvCo0Fqt6rAXbVBK/1r/X5DZePytTm+KL4AoS1k8P444XJSSV84AkZVXfIcMkfj G3DDTZQ4ZHG0uHyr6Lt8QFNGg73afKleqfI3j/+A= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id D3F883858C39 for ; Fri, 14 Jan 2022 12:40:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D3F883858C39 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-370-aXoIK0jONZKQe3FkTSuKxg-1; Fri, 14 Jan 2022 07:40:18 -0500 X-MC-Unique: aXoIK0jONZKQe3FkTSuKxg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 88D16100C660; Fri, 14 Jan 2022 12:40:17 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B72EE72436; Fri, 14 Jan 2022 12:40:16 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 1/7] x86: HAVE_X86_LAHF_SAHF, HAVE_X86_MOVBE and -march=x86-64-vN (bug 28782) In-Reply-To: References: X-From-Line: 01dee4fcc3539959c720b1cc09193f80a5c2ba62 Mon Sep 17 00:00:00 2001 Message-Id: <01dee4fcc3539959c720b1cc09193f80a5c2ba62.1642162312.git.fweimer@redhat.com> Date: Fri, 14 Jan 2022 13:40:14 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "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. Reviewed-by: H.J. Lu --- 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 From patchwork Fri Jan 14 12:40:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 50026 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D7857386EC3C for ; Fri, 14 Jan 2022 12:42:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D7857386EC3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642164122; bh=ZCVwKnV0qA8k7S3Gg34oS87MGXvrJ3iequ6YiM9YdMU=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=nNmMBTyiGv6Yf7iqLkQoUfycI5nsDYrKOhRG2russ9DyULVw30xadPSgGVXluLZhh BnzdzZ8IjbjXlHDsXQ//WqxUUfOiLwBT6/iFsGa8t7IDlAhaGKcFIFX3pzk0MOv7Mz 6QcH1dB4voK0So22avQFwszdE3kvz6mZxm6wQ+YI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 96A4E386EC3C for ; Fri, 14 Jan 2022 12:40:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 96A4E386EC3C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-125-GuwnMyaEO46pE1pImQQ_bA-1; Fri, 14 Jan 2022 07:40:24 -0500 X-MC-Unique: GuwnMyaEO46pE1pImQQ_bA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E78C485B663 for ; Fri, 14 Jan 2022 12:40:23 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B2DD7B9ED for ; Fri, 14 Jan 2022 12:40:23 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 2/7] Generate gcc-macros.h In-Reply-To: References: X-From-Line: 589769aee82434f370de47d9746aec521aab1f46 Mon Sep 17 00:00:00 2001 Message-Id: <589769aee82434f370de47d9746aec521aab1f46.1642162312.git.fweimer@redhat.com> Date: Fri, 14 Jan 2022 13:40:21 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "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. Reviewed-by: H.J. Lu --- 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) From patchwork Fri Jan 14 12:40:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 50027 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5F67E385C400 for ; Fri, 14 Jan 2022 12:42:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F67E385C400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642164165; bh=x7KEjoZksaEln6pIuzxXde/zWxH1LFGWecVi1azOcOs=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Bo54BuW2OfQuL4pA+PaZ+Sebu7LCJIKZcl78/Q+De6YyXb2GAUtKHyZS1tW653mVS Ww9RZJeg/VPqB0yrVyY/dk+5bQiGGTs3vEKhr/ouIqhN+S55E/njER+QtDVYBJ+243 vGPRJNAVEXAcdU2ZgxG1O+KbGCnHXrflnthBThqY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id F3B543835C18 for ; Fri, 14 Jan 2022 12:40:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F3B543835C18 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-137-7JQu7kI2O0md8l0O6ogFZw-1; Fri, 14 Jan 2022 07:40:33 -0500 X-MC-Unique: 7JQu7kI2O0md8l0O6ogFZw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B55E41023F4E for ; Fri, 14 Jan 2022 12:40:31 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A7C9E26DE5 for ; Fri, 14 Jan 2022 12:40:30 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 3/7] elf: Split dl-printf.c from dl-misc.c In-Reply-To: References: X-From-Line: 905c03a4ee231961ca1dd4fc74e49ebf97299b0d Mon Sep 17 00:00:00 2001 Message-Id: <905c03a4ee231961ca1dd4fc74e49ebf97299b0d.1642162312.git.fweimer@redhat.com> Date: Fri, 14 Jan 2022 13:40:28 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "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 . */ -#include +#include <_itoa.h> #include #include -#include #include -#include -#include -#include -#include +#include #include +#include #include -#include #include -#include -#include -#include <_itoa.h> -#include -#include +#include /* 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 + . */ + +#include <_itoa.h> +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* 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) From patchwork Fri Jan 14 12:40:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 50028 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AB576385DC2D for ; Fri, 14 Jan 2022 12:43:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB576385DC2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642164212; bh=PT+fzXjKsoAEtNXEypjs3VDDxXUfV92fLJgALDUc3Y0=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=it62eTnWLkz/c718K87oEs1LLvRuI/TqzhMa5v1GzaQUbyk5CZa0d89oL5urq/1BT 5m6Jf1qZ0MFWqxvDwDPlbJkJ4Qb5En9IuPXpTiOZB66WvVyLSqPs/Y6ig/eFiYK4J2 iR/cNXHmq5lzN82Qs8l4h6HL3Sh9bH0NpX3vpy78= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 8EF9A3835C02 for ; Fri, 14 Jan 2022 12:40:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8EF9A3835C02 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-508-tMttDutCMcmeDNlNC5ITTw-1; Fri, 14 Jan 2022 07:40:39 -0500 X-MC-Unique: tMttDutCMcmeDNlNC5ITTw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2F1FD1023F4D for ; Fri, 14 Jan 2022 12:40:38 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 84FBB105C729 for ; Fri, 14 Jan 2022 12:40:37 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 4/7] Add --early-cflags configure option In-Reply-To: References: X-From-Line: ba54ada5b853d96208f1ca434e25ca5caf93eb56 Mon Sep 17 00:00:00 2001 Message-Id: Date: Fri, 14 Jan 2022 13:40:35 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "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} From patchwork Fri Jan 14 12:40:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 50029 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 02C63383600D for ; Fri, 14 Jan 2022 12:44:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 02C63383600D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642164255; bh=G8t//5polw7uErk86PPpTJpxraSFj9fdnjq4Plq7Zbo=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=cHfqF4bek/igAbrUr9B3KP7+PPOebxH1k7AStugWHyhn5dYVXBdJpBY3/31k7vESP ZzdEo/owGkfdSjJYUo8R8BQVbzOQDAdGJuLEud/gpYe5u114ygDEf+wu5X9Izkteui VqYJwdsYPK6sUp+mYj/T0W2/fT/b2JcQxJd98Pqw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id C007B386EC3C for ; Fri, 14 Jan 2022 12:40:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C007B386EC3C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-328-otaZRiHnMSKccegu5FcRYQ-1; Fri, 14 Jan 2022 07:40:51 -0500 X-MC-Unique: otaZRiHnMSKccegu5FcRYQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8B45784BA40; Fri, 14 Jan 2022 12:40:50 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B142084644; Fri, 14 Jan 2022 12:40:49 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 5/7] powerpc64le: Use in early HWCAP check In-Reply-To: References: X-From-Line: 42e3a9aae86bfe545c24b1fe9908d64d3fdf8cb0 Mon Sep 17 00:00:00 2001 Message-Id: <42e3a9aae86bfe545c24b1fe9908d64d3fdf8cb0.1642162312.git.fweimer@redhat.com> Date: Fri, 14 Jan 2022 13:40:47 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Cc: Tulio Magno Quites Machado Filho Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "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 #include 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"); From patchwork Fri Jan 14 12:41:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 50030 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6A4B93858D35 for ; Fri, 14 Jan 2022 12:44:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A4B93858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642164297; bh=tqM4mIuIGowqkloLu8ZiH8EdDoZBVAaEiYt0lDMCq14=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=KuUjB5dxNRq8QonsIj8ccx2aei/IkDbrWmL51zriQz9h5mA4FPLzWkEufhlaxZCTr wlt/zfwY7o4mjiJxFOoYkSpbOo9DXUZtiC1Nh+QCZDX4nEYknp21BhjZzo01vd0wPY wmFA+5z7ms3fJSAAo1H9uYClOivnxaO4DEH0qJEQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id DC12A383602A for ; Fri, 14 Jan 2022 12:41:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DC12A383602A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-261-sk9wCAhCOrClfYxftLvLZA-1; Fri, 14 Jan 2022 07:41:05 -0500 X-MC-Unique: sk9wCAhCOrClfYxftLvLZA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1820984BA40; Fri, 14 Jan 2022 12:41:04 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2DF3B26576; Fri, 14 Jan 2022 12:41:02 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 6/7] x86: Add x86-64-vN check to early startup In-Reply-To: References: X-From-Line: efa4a91cd090981e827e7ff90dad97475aadfd26 Mon Sep 17 00:00:00 2001 Message-Id: Date: Fri, 14 Jan 2022 13:41:01 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This ISA level covers the glibc build itself. 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 +# include /* 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, From patchwork Fri Jan 14 12:41:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 50031 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A9B49385AC21 for ; Fri, 14 Jan 2022 12:45:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A9B49385AC21 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642164339; bh=vKRuF+x+4pAtvKct3I7UOtMnI1ap4qAN3XJNZ5kNtp0=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=EegOXVtca672tV2jolQwjxIihorzWoT+9LmPpfEm+DjIspTrDGq2Jm/3Bq90bv683 3qQAFo+g1NTwb4QyS7qyvCLoWBoxXjpkjFdNa/slB9IC5HFc4nn+dYQL5jiFPfk7IK lac4UhtCWWJNlt9ojeaktPucS+sRDcF3ZOxMFBAs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 631E63835C03 for ; Fri, 14 Jan 2022 12:41:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 631E63835C03 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-377-hVLW1m8qOvKPLaeOmEma5g-1; Fri, 14 Jan 2022 07:41:14 -0500 X-MC-Unique: hVLW1m8qOvKPLaeOmEma5g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CA12D100C661; Fri, 14 Jan 2022 12:41:13 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ED3D91064145; Fri, 14 Jan 2022 12:41:12 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 7/7] s390x: Use in early HWCAP check In-Reply-To: References: X-From-Line: 201e517c6a751bebe505af99e35a9f8643066f31 Mon Sep 17 00:00:00 2001 Message-Id: <201e517c6a751bebe505af99e35a9f8643066f31.1642162312.git.fweimer@redhat.com> Date: Fri, 14 Jan 2022 13:41:10 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Cc: Stefan Liebler Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This is required so that the checks still work if $(early-cflags) selects a different ISA level. Reviewed-by: Stefan Liebler Tested-by: Stefan Liebler --- 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 #include 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");