From patchwork Thu Oct 6 15:35:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 58477 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 7C720389838B for ; Thu, 6 Oct 2022 15:36:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7C720389838B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665070563; bh=KgiGTVBmru3TrU4TTXp5z3XnUL3U5rZ2MLimJQo3VRc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=MeceyY8rZhfz9YFnmwkAd75OKdgF2uHs6aJkXFo38roGiBWZpIp87vbOlYuxyhnT9 4y8S6LrJByGHzYBHVy5dkKOGSxGburk7YaM3SESgOS6OcN+0jKmfLIJjS76WoVkSIV bg16TxF4lvXBFvKbOOUlxkPyRdVWZAcIm3KKS1P4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by sourceware.org (Postfix) with ESMTPS id C7E8F3858022 for ; Thu, 6 Oct 2022 15:35:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C7E8F3858022 Received: by mail-oi1-x22e.google.com with SMTP id d64so2416469oia.9 for ; Thu, 06 Oct 2022 08:35:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KgiGTVBmru3TrU4TTXp5z3XnUL3U5rZ2MLimJQo3VRc=; b=GlBcbkH4JAu6ml4bvjO3DK2Q8GEsSpfzeewP8ifWHwFSo//subWjTmigCi+C27Q4DF Ip78Ty6FGvPUrBMrXxOdHcY0BODt07iFYp8t87/Xi7gZ2rI8xBjVJO1ANndZGZW7GyWl JKVCi4HecghgnJYkzjNlBP9nvSfD5t40a3EG/KVwSSBui4eJkfF/h2+vce/GzDG4jOFF IJ2IHeKeBsnlwBfhAiptz5x++sdasQNqrMuu1xNhVqt2+ep5ffqtb1tttSZmC2k5xOwZ GUrp2PY0Q81EXrSsVufU8wzX/Sl8G5amFLvDMmco2yrcDdc7jClkXjn5UTd8dR4/i6y1 Tc0g== X-Gm-Message-State: ACrzQf0HB3rJIbKvweLNcVzF1czO6k8J9XAhS6tK4N3Jw5J/Whwt2ngT 6MOILZEsNZNALiOJ9m7FJSuq2kKZijdINbnh X-Google-Smtp-Source: AMsMyM5MojXOD+vwmfs05l28sejV8p1uUPnCQ94YkWtFDZE0kELmZKKu/yR3VEsoWCu4VJuX7VjgTg== X-Received: by 2002:a05:6808:1389:b0:351:6c25:8535 with SMTP id c9-20020a056808138900b003516c258535mr1264210oiw.120.1665070539711; Thu, 06 Oct 2022 08:35:39 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:b87d:458a:dad2:90f5:fdd3]) by smtp.gmail.com with ESMTPSA id bk3-20020a0568081a0300b003541158c659sm850340oib.22.2022.10.06.08.35.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 08:35:39 -0700 (PDT) To: libc-alpha@sourceware.org, Carlos O'Donell Subject: [PATCH v5] elf: Remove -fno-tree-loop-distribute-patterns usage on dl-support Date: Thu, 6 Oct 2022 12:35:35 -0300 Message-Id: <20221006153535.1666521-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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. 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 - # 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 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. + 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. + 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 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"); + +#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"); + +#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)); + +#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"); + +#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"); + +#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); + +#endif