From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 E40A73858D37 for ; Mon, 10 Oct 2022 12:28:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E40A73858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665404885; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K9wuJx2af78eKfOexP3ECpDWBUNRteBr82/X7pRTBkw=; b=F/hbVetNX48LXWsHA+dssapGDMZrkQnEy76f3Vze0hAkoSDCYsRpxm8OAjLmN2w/djAXqv fX3KlhesoaW+xE97/xjwBy+Rmfb0rlEFHt4DPNf8xwMjqBhXl6fajTT7Wk5fPHDwl37SRP AbbfSxTCmYu84DoOersfv6MPDKwInSs= Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-658-9vguQPzaPyGjUWAuT7sMDA-1; Mon, 10 Oct 2022 08:28:04 -0400 X-MC-Unique: 9vguQPzaPyGjUWAuT7sMDA-1 Received: by mail-il1-f197.google.com with SMTP id h10-20020a056e021d8a00b002f99580de6cso8511961ila.5 for ; Mon, 10 Oct 2022 05:28:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=K9wuJx2af78eKfOexP3ECpDWBUNRteBr82/X7pRTBkw=; b=D5e6H9AUohkuHliXZFbofo/C5r6S2fNhy5jE9q7f9K/F8TG251u/FydlJ26QzJ+uLL Ts87jSO5uuaWiJ5e0r/qxiUZi6iTTXtBOMBSTgruWeqhIiopuEEt12HfnNtRygalp01K u4SCoqDRxsrRNPQzOF1MsCKEbd5pkpb9HKsbVHb5JHU3YvhmLzxHqOjhcbUC4Ka0vR78 sSvcG8WXrnB/Ux+7FQh1JTpHyMrav1RqUntnw7TLnEsWbRdeZudXcwUZtHuzFQ26IYRR yMIsSz3a+UH1Y8rxTpwvgc1zzMn6EWTXAf7zuUemX7sgN44klczLx1jPjgyoOa4suWZ/ YJuw== X-Gm-Message-State: ACrzQf2ecBq9s9d7kdxsUA5iR37qB3mEMu9NzxkbobEWx9SBWl/yDJSb ar1rN6HN/CsICbBDTqNQH+td4/K4pgQvOmJd8O8zhG47b/ihtvFGwHfrM5ta2gQMayd7lnmhd5t EljAClEqeFjd/wh2K9CLS X-Received: by 2002:a05:6602:1594:b0:6bc:3432:7a1b with SMTP id e20-20020a056602159400b006bc34327a1bmr1883944iow.210.1665404882899; Mon, 10 Oct 2022 05:28:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Dw2B8Z4lsfQjk7SlOREjwuIpG+UmaT1VyhUEKZ+Nsi3u6dxRy34B/IBPMCi8ukbGw5Kr35Q== X-Received: by 2002:a05:6602:1594:b0:6bc:3432:7a1b with SMTP id e20-20020a056602159400b006bc34327a1bmr1883922iow.210.1665404882462; Mon, 10 Oct 2022 05:28:02 -0700 (PDT) Received: from [192.168.0.241] (192-0-145-146.cpe.teksavvy.com. [192.0.145.146]) by smtp.gmail.com with ESMTPSA id q14-20020a02c8ce000000b0036378825c31sm3957549jao.70.2022.10.10.05.28.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 Oct 2022 05:28:01 -0700 (PDT) Message-ID: <7bfa0e9f-393f-c5c7-92a3-c3b5937ff51a@redhat.com> Date: Mon, 10 Oct 2022 08:28:00 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v5] elf: Remove -fno-tree-loop-distribute-patterns usage on dl-support To: Adhemerval Zanella , libc-alpha@sourceware.org References: <20221006153535.1666521-1-adhemerval.zanella@linaro.org> From: Carlos O'Donell Organization: Red Hat In-Reply-To: <20221006153535.1666521-1-adhemerval.zanella@linaro.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,KAM_STOCKGEN,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 10/6/22 11:35, Adhemerval Zanella wrote: > Besides the option being gcc specific, this approach is still fragile > and not future proof since we do not know if this will be the only > optimization option gcc will add that transforms loops to memset > (or any libcall). > > This patch adds a new header, dl-symbol-redir-ifunc.h, that can b > used to redirect the compiler generated libcalls to port the generic > memset implementation if required. > > Checked on x86_64-linux-gnu and aarch64-linux-gnu. Thanks. In v5 you collapse this all to one header and that simplifies things. LGTM. Reviewed-by: Carlos O'Donell > --- > elf/Makefile | 5 --- > elf/dl-support.c | 1 + > .../aarch64/multiarch/dl-symbol-redir-ifunc.h | 24 ++++++++++++ > sysdeps/generic/dl-symbol-redir-ifunc.h | 38 +++++++++++++++++++ > .../i686/multiarch/dl-symbol-redir-ifunc.h | 24 ++++++++++++ > .../le/multiarch/dl-symbol-redir-ifunc.h | 24 ++++++++++++ > .../s390/multiarch/dl-symbol-redir-ifunc.h | 29 ++++++++++++++ > .../sparcv9/multiarch/dl-symbol-redir-ifunc.h | 24 ++++++++++++ > .../sparc64/multiarch/dl-symbol-redir-ifunc.h | 24 ++++++++++++ > .../x86_64/multiarch/dl-symbol-redir-ifunc.h | 34 +++++++++++++++++ > 10 files changed, 222 insertions(+), 5 deletions(-) > create mode 100644 sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h > create mode 100644 sysdeps/generic/dl-symbol-redir-ifunc.h > create mode 100644 sysdeps/i386/i686/multiarch/dl-symbol-redir-ifunc.h > create mode 100644 sysdeps/powerpc/powerpc64/le/multiarch/dl-symbol-redir-ifunc.h > create mode 100644 sysdeps/s390/multiarch/dl-symbol-redir-ifunc.h > create mode 100644 sysdeps/sparc/sparc32/sparcv9/multiarch/dl-symbol-redir-ifunc.h > create mode 100644 sysdeps/sparc/sparc64/multiarch/dl-symbol-redir-ifunc.h > create mode 100644 sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h > > diff --git a/elf/Makefile b/elf/Makefile > index 276343a47f..7b50ccc07a 100644 > --- a/elf/Makefile > +++ b/elf/Makefile > @@ -162,11 +162,6 @@ ifeq (yes,$(have-loop-to-function)) > CFLAGS-rtld.c += -fno-tree-loop-distribute-patterns > endif > > -ifeq (yes,$(have-loop-to-function)) > -# Likewise, during static library startup, memset is not yet available. > -CFLAGS-dl-support.c = -fno-tree-loop-distribute-patterns > -endif > - OK. > # Compile rtld itself without stack protection. > # Also compile all routines in the static library that are elided from > # the shared libc because they are in libc.a in the same way. > diff --git a/elf/dl-support.c b/elf/dl-support.c > index 4af0b5b2ce..614b5b3e0c 100644 > --- a/elf/dl-support.c > +++ b/elf/dl-support.c > @@ -44,6 +44,7 @@ > #include > #include > #include > +#include OK. Include the single header. > > extern char *__progname; > char **_dl_argv = &__progname; /* This is checked for some error messages. */ > diff --git a/sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h > new file mode 100644 > index 0000000000..6ee6537181 > --- /dev/null > +++ b/sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h > @@ -0,0 +1,24 @@ > +/* Symbol rediretion for loader/static initialization code. OK. > + Copyright (C) 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 > + . */ > + > +#ifndef _DL_IFUNC_GENERIC_H > +#define _DL_IFUNC_GENERIC_H > + > +asm ("memset = __memset_generic"); > + > +#endif > diff --git a/sysdeps/generic/dl-symbol-redir-ifunc.h b/sysdeps/generic/dl-symbol-redir-ifunc.h > new file mode 100644 > index 0000000000..b4a087e531 > --- /dev/null > +++ b/sysdeps/generic/dl-symbol-redir-ifunc.h > @@ -0,0 +1,38 @@ > +/* Symbol rediretion for loader/static initialization code. OK. > + Copyright (C) 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 > + . */ > + > +#ifndef _DL_IFUNC_GENERIC_H > +#define _DL_IFUNC_GENERIC_H > + > +/* The compiler might optimize loops or other constructs to library calls even > + in freestanding mode. Although it is safe in most scenarios, on program > + loading and static startup, iFUNC resolution might require other dynamic > + relocation that are not yet done. > + > + Instead of adding per-file compiler flags to avoid the libcall generation, > + this header defines generic symbols that will be routed instead of the > + default symbols name. > + > + Each port can then make the required redirection to the expected generic > + implementation if the symbol is provided as iFUNC, with a global definition > + such as: > + > + asm ("memset = __memset_generic"); > + */ > + > +#endif OK. > diff --git a/sysdeps/i386/i686/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/i386/i686/multiarch/dl-symbol-redir-ifunc.h > new file mode 100644 > index 0000000000..a0c66f8892 > --- /dev/null > +++ b/sysdeps/i386/i686/multiarch/dl-symbol-redir-ifunc.h > @@ -0,0 +1,24 @@ > +/* Symbol rediretion for loader/static initialization code. > + Copyright (C) 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 > + . */ > + > +#ifndef _DL_IFUNC_GENERIC_H > +#define _DL_IFUNC_GENERIC_H > + > +asm ("memset = __memset_ia32"); OK. > + > +#endif > diff --git a/sysdeps/powerpc/powerpc64/le/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/powerpc/powerpc64/le/multiarch/dl-symbol-redir-ifunc.h > new file mode 100644 > index 0000000000..1883bc3a9d > --- /dev/null > +++ b/sysdeps/powerpc/powerpc64/le/multiarch/dl-symbol-redir-ifunc.h > @@ -0,0 +1,24 @@ > +/* Symbol rediretion for loader/static initialization code. > + Copyright (C) 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 > + . */ > + > +#ifndef _DL_IFUNC_GENERIC_H > +#define _DL_IFUNC_GENERIC_H > + > +asm ("memset = __memset_power8"); OK. POWER8 is the minimum for ppc64le. > + > +#endif > diff --git a/sysdeps/s390/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/s390/multiarch/dl-symbol-redir-ifunc.h > new file mode 100644 > index 0000000000..14cdd46808 > --- /dev/null > +++ b/sysdeps/s390/multiarch/dl-symbol-redir-ifunc.h > @@ -0,0 +1,29 @@ > +/* Symbol rediretion for loader/static initialization code. > + Copyright (C) 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 > + . */ > + > +#ifndef _DL_IFUNC_GENERIC_H > +#define _DL_IFUNC_GENERIC_H > + > +#include > + > +#define IFUNC_SYMBOL_STR1(s) #s > +#define IFUNC_SYMBOL_STR(s) IFUNC_SYMBOL_STR1(s) > + > +asm ("memset = " IFUNC_SYMBOL_STR(MEMSET_DEFAULT)); OK. > + > +#endif > diff --git a/sysdeps/sparc/sparc32/sparcv9/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/sparc/sparc32/sparcv9/multiarch/dl-symbol-redir-ifunc.h > new file mode 100644 > index 0000000000..42c477b872 > --- /dev/null > +++ b/sysdeps/sparc/sparc32/sparcv9/multiarch/dl-symbol-redir-ifunc.h > @@ -0,0 +1,24 @@ > +/* Symbol rediretion for loader/static initialization code. > + Copyright (C) 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 > + . */ > + > +#ifndef _DL_IFUNC_GENERIC_H > +#define _DL_IFUNC_GENERIC_H > + > +asm ("memset = __memset_ultra1"); OK. > + > +#endif > diff --git a/sysdeps/sparc/sparc64/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/sparc/sparc64/multiarch/dl-symbol-redir-ifunc.h > new file mode 100644 > index 0000000000..42c477b872 > --- /dev/null > +++ b/sysdeps/sparc/sparc64/multiarch/dl-symbol-redir-ifunc.h > @@ -0,0 +1,24 @@ > +/* Symbol rediretion for loader/static initialization code. > + Copyright (C) 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 > + . */ > + > +#ifndef _DL_IFUNC_GENERIC_H > +#define _DL_IFUNC_GENERIC_H > + > +asm ("memset = __memset_ultra1"); > + OK. > +#endif > diff --git a/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h > new file mode 100644 > index 0000000000..64f9996854 > --- /dev/null > +++ b/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h > @@ -0,0 +1,34 @@ > +/* Symbol rediretion for loader/static initialization code. > + Copyright (C) 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 > + . */ > + > +#ifndef _DL_IFUNC_GENERIC_H > +#define _DL_IFUNC_GENERIC_H > + > +#include > + > +#if MINIMUM_X86_ISA_LEVEL >= 4 > +# define HAVE_MEMSET_IFUNC_GENERIC "__memset_evex_unaligned" > +#elif MINIMUM_X86_ISA_LEVEL == 3 > +# define HAVE_MEMSET_IFUNC_GENERIC "__memset_avx2_unaligned" > +#else > +# define HAVE_MEMSET_IFUNC_GENERIC "__memset_sse2_unaligned" > +#endif > + > +asm ("memset = " HAVE_MEMSET_IFUNC_GENERIC); OK. > + > +#endif -- Cheers, Carlos.