From patchwork Tue Feb 7 00:16:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 64395 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 D1C983889E19 for ; Tue, 7 Feb 2023 00:19:49 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 2CB103858425 for ; Tue, 7 Feb 2023 00:16:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2CB103858425 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-wm1-x334.google.com with SMTP id c4-20020a1c3504000000b003d9e2f72093so12043330wma.1 for ; Mon, 06 Feb 2023 16:16:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BAcTcjATBAdQf+KWosVGSXCa8AEadnxSJLwGoHNU96Y=; b=YiqQ3aN2qy2CL6l7OBeF32jtmVxUtnhTU/u5cTkQYx6EqzgDYeOdfiXH1vwAXHD4dZ SHNTUceyVXgPCS4+WI3vFXxmtENKxnUfs4mSY4QqKNpTQNrQAxnq5AJS9GnhBiROW4dX 9mHFMGZ/ssoZUzXqA1X7nE91EPx6C+MDOHnmZZsuq0tTqdy8cegaZTwwcFVA4ptWE5M2 WMhCqZ853O5KeWMb7ry7N2ZdKPwSLXZLNkITJEeXYsrwcv28cbB34nWRifY08JJEpL2L XyfnScjoGRzlh6ACpxLYBzHKz3YhmZQnmAyjNZyMoWKuHzdgqVdZQsqZGAXfCcFVru74 H68Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BAcTcjATBAdQf+KWosVGSXCa8AEadnxSJLwGoHNU96Y=; b=mD/VWS5cALns/FVpf6L13xyWsvtJ6cNdmjClFz+BgC1U+GYfXS6fMIp1HsCDMiiwUj R63s5RoxqOUGtM0AiZKpDxnFhlMYMfi6AD57qc7P+Alsn02XwN/pj8AdZ2dAj2QoYLpM in0+NI3g8Z9CHH/b42RFK9CwXP7b/wcdhsMQxrUrUg2WzY0+/3WBaLnAaVRjXIumAVVq 7c0NeJptS2jD85phPLjcfWp/ojOn27MDHnEnEWMwrAXZAVEa8lIyfH+AD5cVGoETM3N+ 7lEANe3TiJoQL4ZxsCe6Hl7eI6DrLycC6Ewqh8DopZuOj1y7Q7+2403D4z2xYDket6H9 xdzA== X-Gm-Message-State: AO0yUKWXwLHzFhowQpphM9/MC4Wvvx/cnVsTod1jhe6j9xDlEtq8z5W7 JT2VYM+CylLAEFx+2Wp7h3zrjr3GmekIJKev X-Google-Smtp-Source: AK7set9mSPvkxGUsAn0302oPWgU6iD0O50xhx9PwMofY4wkfix8nbTgnnlu/f7E4si9U9SSY9eC/Pw== X-Received: by 2002:a05:600c:331c:b0:3dc:9ecc:22a with SMTP id q28-20020a05600c331c00b003dc9ecc022amr1367730wmp.8.1675729009472; Mon, 06 Feb 2023 16:16:49 -0800 (PST) Received: from beast.fritz.box (62-178-148-172.cable.dynamic.surfer.at. [62.178.148.172]) by smtp.gmail.com with ESMTPSA id f1-20020a1cc901000000b003df14531724sm16862050wmb.21.2023.02.06.16.16.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 16:16:48 -0800 (PST) From: Christoph Muellner To: libc-alpha@sourceware.org, Palmer Dabbelt , Darius Rad , Andrew Waterman , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law , Philipp Tomsich , Heiko Stuebner Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [RFC PATCH 13/19] riscv: Add ifunc support for strlen Date: Tue, 7 Feb 2023 01:16:12 +0100 Message-Id: <20230207001618.458947-14-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230207001618.458947-1-christoph.muellner@vrull.eu> References: <20230207001618.458947-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_MANYTO, KAM_SHORT, 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: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" From: Christoph Müllner This patch adds ifunc support for calls to strlen to the RISC-V code. No optimized code is added as part of this patch. Signed-off-by: Christoph Müllner --- sysdeps/riscv/multiarch/Makefile | 4 ++- sysdeps/riscv/multiarch/ifunc-impl-list.c | 4 +++ sysdeps/riscv/multiarch/strlen.c | 40 +++++++++++++++++++++++ sysdeps/riscv/multiarch/strlen_generic.c | 32 ++++++++++++++++++ 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 sysdeps/riscv/multiarch/strlen.c create mode 100644 sysdeps/riscv/multiarch/strlen_generic.c diff --git a/sysdeps/riscv/multiarch/Makefile b/sysdeps/riscv/multiarch/Makefile index b08d7d1c8b..8e2b020233 100644 --- a/sysdeps/riscv/multiarch/Makefile +++ b/sysdeps/riscv/multiarch/Makefile @@ -6,5 +6,7 @@ sysdep_routines += \ \ memset_generic \ memset_rv64_unaligned \ - memset_rv64_unaligned_cboz64 + memset_rv64_unaligned_cboz64 \ + \ + strlen_generic endif diff --git a/sysdeps/riscv/multiarch/ifunc-impl-list.c b/sysdeps/riscv/multiarch/ifunc-impl-list.c index 84b3eb25a4..f848fc8401 100644 --- a/sysdeps/riscv/multiarch/ifunc-impl-list.c +++ b/sysdeps/riscv/multiarch/ifunc-impl-list.c @@ -54,5 +54,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, #endif IFUNC_IMPL_ADD (array, i, memset, 1, __memset_generic)) + IFUNC_IMPL (i, name, strlen, + IFUNC_IMPL_ADD (array, i, strlen, 1, __strlen_generic)) + + return i; } diff --git a/sysdeps/riscv/multiarch/strlen.c b/sysdeps/riscv/multiarch/strlen.c new file mode 100644 index 0000000000..85f7a91c9f --- /dev/null +++ b/sysdeps/riscv/multiarch/strlen.c @@ -0,0 +1,40 @@ +/* Multiple versions of strlen. RISC-V version. + 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 + . */ + +/* Define multiple versions only for the definition in libc. */ + +#if IS_IN (libc) +/* Redefine strlen so that the compiler won't complain about the type + mismatch with the IFUNC selector in strong_alias, below. */ +# undef strlen +# define strlen __redirect_strlen +# include +# include +# include +# include + +extern __typeof (__redirect_strlen) __libc_strlen; +extern __typeof (__redirect_strlen) __strlen_generic attribute_hidden; + +libc_ifunc (__libc_strlen, __strlen_generic); + +# undef strlen +strong_alias (__libc_strlen, strlen); +#else +# include +#endif diff --git a/sysdeps/riscv/multiarch/strlen_generic.c b/sysdeps/riscv/multiarch/strlen_generic.c new file mode 100644 index 0000000000..10aa05e699 --- /dev/null +++ b/sysdeps/riscv/multiarch/strlen_generic.c @@ -0,0 +1,32 @@ +/* strlen for RISC-V, default version for internal use. + 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 + . */ + +#include + +#define STRLEN __strlen_generic + +#ifdef SHARED +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(name) \ + __hidden_ver1(__strlen_generic, __GI_strlen, __strlen_generic); +#endif + +extern size_t __strlen_generic(const char *str); + +#include