From patchwork Fri Dec 25 03:25:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 41555 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 3BD813870856; Fri, 25 Dec 2020 03:25:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3BD813870856 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608866754; bh=Mzro2XkfI257bk88M0KuCyJsl6ZO16nnU3spAUUxwig=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=vYC6SgNIzTNs3m/2us3V7SBmIAOeuxMn5IkT9dSHdR86ZwtRnLgbbFAeKxYl0G5US oqg1khCM4zdjdKjvbAQ2XPUN19iqwAShuSTJwjE2IF2PyvncPUmmqoa8j5cehUWC2k 1gBaPHaBnkc/pTHZ37ay0hjtdR7dEGsHqE7/zFsA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 3CF91385800E for ; Fri, 25 Dec 2020 03:25:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3CF91385800E Received: by mail-ot1-x336.google.com with SMTP id r9so3106833otk.11 for ; Thu, 24 Dec 2020 19:25:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=Mzro2XkfI257bk88M0KuCyJsl6ZO16nnU3spAUUxwig=; b=pU3cD8MyWfihV/mbhVzj0ilazMcCnvMRBjQbYNlm0E3gTU/YcZgy3ybwP8RG8WBYdB 5i5uSiLsY2ueVQ/TVpc82RQE/jibZwmgjPlyB+drhtHmgbeHFy0t43HkY4BLCHy3Xpjc +uqWuEbCaKX8ITn6JKmH6RFexsQ4d4bzD+hNJuu7Q/dU9vQHgBfoUoEz9Gz+9etk5oM8 nHQY8QAk97b15lvcKkpiV6O3mJcJDqb26RKWcyY3nK5H6jQlpfVuI5y0Z0SFeHouayIo RL7VLH1i/I+L1Kq/VbwYljSL8DerWiMgopel19WV6IinljlHcD5dDlmKCEaR2cgQnuSM uT+A== X-Gm-Message-State: AOAM5310DeowjgtuYCWNLn7ZFI2SYpUGJ4QUUAM+EHlENg1zUafWBjsR MbOcdLw3yoAzxyEZCQqM7/KEGrNnqHzhAKrzLi2SDnK0rk4= X-Google-Smtp-Source: ABdhPJxbRS3EpnHQ1SPpfqYbykzy6oG8c5KK9Ar7nCCvePQlYS8NUp3FgFAGmg/X6musyII1DRCFHbYhY/S1fkbYUJ0= X-Received: by 2002:a05:6830:1d71:: with SMTP id l17mr24571267oti.269.1608866749464; Thu, 24 Dec 2020 19:25:49 -0800 (PST) MIME-Version: 1.0 References: <20201224230256.2646417-1-hjl.tools@gmail.com> In-Reply-To: <20201224230256.2646417-1-hjl.tools@gmail.com> Date: Thu, 24 Dec 2020 19:25:13 -0800 Message-ID: Subject: V2 [PATCH] x86: Add tests for IFUNC resolver with CPU_FEATURE_USABLE To: GNU C Library , Florian Weimer X-Spam-Status: No, score=-3036.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" On Thu, Dec 24, 2020 at 3:02 PM H.J. Lu wrote: > > Add tests for IFUNC resolver using CPU_FEATURE_USABLE with and without > lazy binding. Update tests to properly check IFUNC resolver. Florian, your patch failed: FAIL: elf/tst-ifunc-platform-3-bindnow FAIL: elf/tst-ifunc-platform-3-lazy due to [hjl@gnu-cfl-2 build-x86_64-linux]$ readelf -rW elf/tst-ifunc-platform-mod-3.so | grep __x86_cpu_array 0000000000003fe0 0000000200000006 R_X86_64_GLOB_DAT 0000000000000000 __x86_cpu_array@GLIBC_2.33 + 0 [hjl@gnu-cfl-2 build-x86_64-linux]$ readelf -rW elf/tst-ifunc-platform-3-lazy | grep __x86_cpu_array 0000000000406d80 0000003600000005 R_X86_64_COPY 0000000000406d80 __x86_cpu_array@GLIBC_2.33 + 0 [hjl@gnu-cfl-2 build-x86_64-linux]$ From 67db31ec5a3f570a6a2bbf40f61014c267c42798 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Thu, 24 Dec 2020 14:06:30 -0800 Subject: [PATCH] x86: Add tests for IFUNC resolver with CPU_FEATURE_USABLE Add tests for IFUNC resolver using CPU_FEATURE_USABLE with and without lazy binding. --- sysdeps/x86/Makefile | 30 +++++++- sysdeps/x86/tst-ifunc-platform-1-bindnow.c | 1 + sysdeps/x86/tst-ifunc-platform-1-lazy.c | 87 ++++++++++++++++++++++ sysdeps/x86/tst-ifunc-platform-1-static.c | 1 + sysdeps/x86/tst-ifunc-platform-2-bindnow.c | 1 + sysdeps/x86/tst-ifunc-platform-2-lazy.c | 51 +++++++++++++ sysdeps/x86/tst-ifunc-platform-3-bindnow.c | 1 + sysdeps/x86/tst-ifunc-platform-3-lazy.c | 1 + sysdeps/x86/tst-ifunc-platform-mod-2.c | 65 ++++++++++++++++ sysdeps/x86/tst-ifunc-platform-mod-3.c | 71 ++++++++++++++++++ 10 files changed, 307 insertions(+), 2 deletions(-) create mode 100644 sysdeps/x86/tst-ifunc-platform-1-bindnow.c create mode 100644 sysdeps/x86/tst-ifunc-platform-1-lazy.c create mode 100644 sysdeps/x86/tst-ifunc-platform-1-static.c create mode 100644 sysdeps/x86/tst-ifunc-platform-2-bindnow.c create mode 100644 sysdeps/x86/tst-ifunc-platform-2-lazy.c create mode 100644 sysdeps/x86/tst-ifunc-platform-3-bindnow.c create mode 100644 sysdeps/x86/tst-ifunc-platform-3-lazy.c create mode 100644 sysdeps/x86/tst-ifunc-platform-mod-2.c create mode 100644 sysdeps/x86/tst-ifunc-platform-mod-3.c diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile index 00109ded11..cd752b9bd6 100644 --- a/sysdeps/x86/Makefile +++ b/sysdeps/x86/Makefile @@ -7,8 +7,34 @@ sysdep-dl-routines += dl-get-cpu-features sysdep_headers += bits/platform/x86.h sys/platform/x86.h tests += tst-get-cpu-features tst-get-cpu-features-static \ - tst-cpu-features-cpuinfo tst-cpu-features-supports -tests-static += tst-get-cpu-features-static + tst-cpu-features-cpuinfo tst-cpu-features-supports \ + tst-ifunc-platform-1-bindnow \ + tst-ifunc-platform-1-lazy \ + tst-ifunc-platform-1-static \ + tst-ifunc-platform-2-bindnow \ + tst-ifunc-platform-2-lazy \ + tst-ifunc-platform-3-bindnow \ + tst-ifunc-platform-3-lazy +tests-static += tst-get-cpu-features-static \ + tst-ifunc-platform-1-static + +modules-names += tst-ifunc-platform-mod-2 \ + tst-ifunc-platform-mod-3 + +LDFLAGS-tst-ifunc-platform-1-lazy = -Wl,-z,lazy +LDFLAGS-tst-ifunc-platform-1-bindnow = -Wl,-z,now +tst-ifunc-platform-1-bindnow-ENV = LD_BIND_NOW=1 +LDFLAGS-tst-ifunc-platform-2-lazy = -Wl,-z,lazy +LDFLAGS-tst-ifunc-platform-2-bindnow = -Wl,-z,now +tst-ifunc-platform-2-bindnow-ENV = LD_BIND_NOW=1 +LDFLAGS-tst-ifunc-platform-3-lazy = -Wl,-z,lazy +LDFLAGS-tst-ifunc-platform-3-bindnow = -Wl,-z,now +tst-ifunc-platform-3-bindnow-ENV = LD_BIND_NOW=1 + +$(objpfx)tst-ifunc-platform-2-bindnow: $(objpfx)tst-ifunc-platform-mod-2.so +$(objpfx)tst-ifunc-platform-2-lazy: $(objpfx)tst-ifunc-platform-mod-2.so +$(objpfx)tst-ifunc-platform-3-bindnow: $(objpfx)tst-ifunc-platform-mod-3.so +$(objpfx)tst-ifunc-platform-3-lazy: $(objpfx)tst-ifunc-platform-mod-3.so endif ifeq ($(subdir),math) diff --git a/sysdeps/x86/tst-ifunc-platform-1-bindnow.c b/sysdeps/x86/tst-ifunc-platform-1-bindnow.c new file mode 100644 index 0000000000..f8391048ae --- /dev/null +++ b/sysdeps/x86/tst-ifunc-platform-1-bindnow.c @@ -0,0 +1 @@ +#include "tst-ifunc-platform-1-lazy.c" diff --git a/sysdeps/x86/tst-ifunc-platform-1-lazy.c b/sysdeps/x86/tst-ifunc-platform-1-lazy.c new file mode 100644 index 0000000000..2556c23f3c --- /dev/null +++ b/sysdeps/x86/tst-ifunc-platform-1-lazy.c @@ -0,0 +1,87 @@ +/* Program with local IFUNC resolver and . + Copyright (C) 2020 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 +#include + +enum isa +{ + has_none, + has_sse2, + has_avx2, + has_avx512f +}; + +static enum isa +none (void) +{ + return has_none; +} + +static enum isa +sse2 (void) +{ + return has_sse2; +} + +static enum isa +avx2 (void) +{ + return has_avx2; +} + +static enum isa +avx512f (void) +{ + return has_avx512f; +} + +static __typeof__ (avx2) * +resolver (void) +{ + if (CPU_FEATURE_USABLE (AVX512F)) + return avx512f; + else if (CPU_FEATURE_USABLE (AVX2)) + return avx2; + else if (CPU_FEATURE_USABLE (SSE2)) + return sse2; + return none; +} + +static enum isa cpuid (void) __attribute__ ((ifunc ("resolver"))); + +static int +do_test (void) +{ + enum isa has_isa = cpuid (); + TEST_VERIFY_EXIT (!!CPU_FEATURE_USABLE (SSE2) + == !!__builtin_cpu_supports ("sse2")); + TEST_VERIFY_EXIT (!!CPU_FEATURE_USABLE (AVX2) + == !!__builtin_cpu_supports ("avx2")); + TEST_VERIFY_EXIT (!!CPU_FEATURE_USABLE (AVX512F) + == !!__builtin_cpu_supports ("avx512f")); + if (__builtin_cpu_supports ("avx512f")) + TEST_VERIFY_EXIT (has_isa == has_avx512f); + else if (__builtin_cpu_supports ("avx2")) + TEST_VERIFY_EXIT (has_isa == has_avx2); + else if (__builtin_cpu_supports ("sse2")) + TEST_VERIFY_EXIT (has_isa == has_sse2); + return 0; +} + +#include diff --git a/sysdeps/x86/tst-ifunc-platform-1-static.c b/sysdeps/x86/tst-ifunc-platform-1-static.c new file mode 100644 index 0000000000..f8391048ae --- /dev/null +++ b/sysdeps/x86/tst-ifunc-platform-1-static.c @@ -0,0 +1 @@ +#include "tst-ifunc-platform-1-lazy.c" diff --git a/sysdeps/x86/tst-ifunc-platform-2-bindnow.c b/sysdeps/x86/tst-ifunc-platform-2-bindnow.c new file mode 100644 index 0000000000..7c2455c2a0 --- /dev/null +++ b/sysdeps/x86/tst-ifunc-platform-2-bindnow.c @@ -0,0 +1 @@ +#include "tst-ifunc-platform-2-lazy.c" diff --git a/sysdeps/x86/tst-ifunc-platform-2-lazy.c b/sysdeps/x86/tst-ifunc-platform-2-lazy.c new file mode 100644 index 0000000000..db3cc5e123 --- /dev/null +++ b/sysdeps/x86/tst-ifunc-platform-2-lazy.c @@ -0,0 +1,51 @@ +/* Program with local IFUNC resolver and . + Copyright (C) 2020 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 +#include + +enum isa +{ + has_none, + has_sse2, + has_avx2, + has_avx512f +}; + +extern enum isa cpuid (void); + +static int +do_test (void) +{ + enum isa has_isa = cpuid (); + TEST_VERIFY_EXIT (!!CPU_FEATURE_USABLE (SSE2) + == !!__builtin_cpu_supports ("sse2")); + TEST_VERIFY_EXIT (!!CPU_FEATURE_USABLE (AVX2) + == !!__builtin_cpu_supports ("avx2")); + TEST_VERIFY_EXIT (!!CPU_FEATURE_USABLE (AVX512F) + == !!__builtin_cpu_supports ("avx512f")); + if (__builtin_cpu_supports ("avx512f")) + TEST_VERIFY_EXIT (has_isa == has_avx512f); + else if (__builtin_cpu_supports ("avx2")) + TEST_VERIFY_EXIT (has_isa == has_avx2); + else if (__builtin_cpu_supports ("sse2")) + TEST_VERIFY_EXIT (has_isa == has_sse2); + return 0; +} + +#include diff --git a/sysdeps/x86/tst-ifunc-platform-3-bindnow.c b/sysdeps/x86/tst-ifunc-platform-3-bindnow.c new file mode 100644 index 0000000000..7c2455c2a0 --- /dev/null +++ b/sysdeps/x86/tst-ifunc-platform-3-bindnow.c @@ -0,0 +1 @@ +#include "tst-ifunc-platform-2-lazy.c" diff --git a/sysdeps/x86/tst-ifunc-platform-3-lazy.c b/sysdeps/x86/tst-ifunc-platform-3-lazy.c new file mode 100644 index 0000000000..7c2455c2a0 --- /dev/null +++ b/sysdeps/x86/tst-ifunc-platform-3-lazy.c @@ -0,0 +1 @@ +#include "tst-ifunc-platform-2-lazy.c" diff --git a/sysdeps/x86/tst-ifunc-platform-mod-2.c b/sysdeps/x86/tst-ifunc-platform-mod-2.c new file mode 100644 index 0000000000..c302277be4 --- /dev/null +++ b/sysdeps/x86/tst-ifunc-platform-mod-2.c @@ -0,0 +1,65 @@ +/* Shared object with local IFUNC resolver and . + Copyright (C) 2020 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 + +enum isa +{ + has_none, + has_sse2, + has_avx2, + has_avx512f +}; + +static enum isa +none (void) +{ + return has_none; +} + +static enum isa +sse2 (void) +{ + return has_sse2; +} + +static enum isa +avx2 (void) +{ + return has_avx2; +} + +static enum isa +avx512f (void) +{ + return has_avx512f; +} + +static __typeof__ (avx2) * +resolver (void) +{ + if (CPU_FEATURE_USABLE (AVX512F)) + return avx512f; + else if (CPU_FEATURE_USABLE (AVX2)) + return avx2; + else if (CPU_FEATURE_USABLE (SSE2)) + return sse2; + return none; +} + +enum isa cpuid (void) __attribute__ ((ifunc ("resolver"))); diff --git a/sysdeps/x86/tst-ifunc-platform-mod-3.c b/sysdeps/x86/tst-ifunc-platform-mod-3.c new file mode 100644 index 0000000000..1002c444ab --- /dev/null +++ b/sysdeps/x86/tst-ifunc-platform-mod-3.c @@ -0,0 +1,71 @@ +/* Shared object with local IFUNC resolver and . + Copyright (C) 2020 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 + +enum isa +{ + has_none, + has_sse2, + has_avx2, + has_avx512f +}; + +static enum isa +none (void) +{ + return has_none; +} + +static enum isa +sse2 (void) +{ + return has_sse2; +} + +static enum isa +avx2 (void) +{ + return has_avx2; +} + +static enum isa +avx512f (void) +{ + return has_avx512f; +} + +static __typeof__ (avx2) * +resolver (void) +{ + if (CPU_FEATURE_USABLE (AVX512F)) + return avx512f; + else if (CPU_FEATURE_USABLE (AVX2)) + return avx2; + else if (CPU_FEATURE_USABLE (SSE2)) + return sse2; + return none; +} + +static enum isa cpuid_local (void) __attribute__ ((ifunc ("resolver"))); + +enum isa +cpuid (void) +{ + return cpuid_local (); +} -- 2.29.2