From patchwork Thu Sep 27 19:43:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 975870 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-96140-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="Kb/F0ygP"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Llc32Xdwz9s3l for ; Fri, 28 Sep 2018 05:43:47 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=LcEsAhjUAu7HIv7YvhOXoh0NAPn1kBx Z7AB6UE3uzxbkoXEUfkQFQnjHPFYt8Kc/DdZpvzcxr7P1MW53d6HrzDelxRwNLcO VMOIfy3S8rya8apeCsLG93XoR4xT854iTCLOS21EfdnsgvokLY1fGwZVM2/gUQDO uxBmspbiA08w= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=bkoFteaV2YOZlUzXWHmeHx161G0=; b=Kb/F0 ygPoAQmteh2A8lV5B3BHbj8WoybmHpZ4TrMpjuVcNeDH6oMgve5mgx3E4dGTasK8 ZRZ9VXYIEGCzLWukAQZ9Yf4tARv8EE1Xd0hy+fJCbTHfQYZQ+GJgqQW0WH2f3G3m PPpPFNgg/fK5O4vgB4nZXa0ygKlRv8Yvbew2VU= Received: (qmail 120188 invoked by alias); 27 Sep 2018 19:43:36 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 120046 invoked by uid 89); 27 Sep 2018 19:43:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=79 X-HELO: mga14.intel.com From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: V5 [PATCH 2/2] x86: Add a LD_PRELOAD IFUNC resolver test for CPU_FEATURE_USABLE Date: Thu, 27 Sep 2018 12:43:27 -0700 Message-Id: <20180927194327.7683-3-hjl.tools@gmail.com> In-Reply-To: <20180927194327.7683-1-hjl.tools@gmail.com> References: <20180927194327.7683-1-hjl.tools@gmail.com> Verify that CPU_FEATURE_USABLE can be used by IFUNC resolver in a LD_PRELOAD library. * sysdeps/x86/Makefile (modules-names): Add tst-x86-platform-mod-4 and tst-x86-platform-preload-4. (LDFLAGS-tst-x86-platform-mod-4.so): New. ($(objpfx)tst-x86-platform-mod-4.so): Likewise. ($(objpfx)tst-x86-platform-4): Likewise. ($(objpfx)tst-x86-platform-4.out): Likewise. (tst-x86-platform-4-ENV): Likewise. --- sysdeps/x86/Makefile | 10 +++- sysdeps/x86/tst-x86-platform-4.c | 54 +++++++++++++++++++++ sysdeps/x86/tst-x86-platform-mod-4.c | 37 ++++++++++++++ sysdeps/x86/tst-x86-platform-preload-4.c | 62 ++++++++++++++++++++++++ 4 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 sysdeps/x86/tst-x86-platform-4.c create mode 100644 sysdeps/x86/tst-x86-platform-mod-4.c create mode 100644 sysdeps/x86/tst-x86-platform-preload-4.c diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile index 272d8f0b89..1e759d3efc 100644 --- a/sysdeps/x86/Makefile +++ b/sysdeps/x86/Makefile @@ -7,8 +7,9 @@ sysdep-dl-routines += dl-get-cpu-features tests += tst-get-cpu-features tst-get-cpu-features-static \ tst-x86-platform-1 tst-x86-platform-1-static \ - tst-x86-platform-2 tst-x86-platform-3 -modules-names += tst-x86-platform-mod-2 tst-x86-platform-mod-3 + tst-x86-platform-2 tst-x86-platform-3 tst-x86-platform-4 +modules-names += tst-x86-platform-mod-2 tst-x86-platform-mod-3 \ + tst-x86-platform-mod-4 tst-x86-platform-preload-4 tests-static += tst-get-cpu-features-static tst-x86-platform-1-static $(objpfx)tst-x86-platform-mod-2.so: $(libsupport) @@ -16,6 +17,11 @@ $(objpfx)tst-x86-platform-2: $(objpfx)tst-x86-platform-mod-2.so LDFLAGS-tst-x86-platform-mod-3.so = -Wl,-z,now $(objpfx)tst-x86-platform-mod-3.so: $(libsupport) $(objpfx)tst-x86-platform-3: $(objpfx)tst-x86-platform-mod-3.so +LDFLAGS-tst-x86-platform-mod-4.so = -Wl,-z,now +$(objpfx)tst-x86-platform-mod-4.so: $(libsupport) +$(objpfx)tst-x86-platform-4: $(objpfx)tst-x86-platform-mod-4.so +$(objpfx)tst-x86-platform-4.out: $(objpfx)tst-x86-platform-preload-4.so +tst-x86-platform-4-ENV = LD_PRELOAD=$(objpfx)tst-x86-platform-preload-4.so endif ifeq ($(subdir),misc) diff --git a/sysdeps/x86/tst-x86-platform-4.c b/sysdeps/x86/tst-x86-platform-4.c new file mode 100644 index 0000000000..fe7bd59b82 --- /dev/null +++ b/sysdeps/x86/tst-x86-platform-4.c @@ -0,0 +1,54 @@ +/* Test case for x86 . + Copyright (C) 2018 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 +#include +#include + +extern bool check_sse2 (void); +extern bool check_avx (void); +extern bool check_avx2 (void); + +static int +do_test (void) +{ + bool failed = false; + + if (CPU_FEATURE_USABLE (SSE2) != check_sse2 ()) + { + printf ("LD_PRELOAD SSE2 check failed\n"); + failed = true; + } + + if (CPU_FEATURE_USABLE (AVX) != check_avx ()) + { + printf ("LD_PRELOAD AVX check failed\n"); + failed = true; + } + + if (CPU_FEATURE_USABLE (AVX2) != check_avx2 ()) + { + printf ("LD_PRELOAD AVX2 check failed\n"); + failed = true; + } + + return failed ? EXIT_FAILURE : EXIT_SUCCESS; +} + +#include diff --git a/sysdeps/x86/tst-x86-platform-mod-4.c b/sysdeps/x86/tst-x86-platform-mod-4.c new file mode 100644 index 0000000000..789389ce3e --- /dev/null +++ b/sysdeps/x86/tst-x86-platform-mod-4.c @@ -0,0 +1,37 @@ +/* Test case for x86 . + Copyright (C) 2018 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 + +bool +check_sse2 (void) +{ + return false; +} + +bool +check_avx (void) +{ + return false; +} + +bool +check_avx2 (void) +{ + return false; +} diff --git a/sysdeps/x86/tst-x86-platform-preload-4.c b/sysdeps/x86/tst-x86-platform-preload-4.c new file mode 100644 index 0000000000..d1216b90e9 --- /dev/null +++ b/sysdeps/x86/tst-x86-platform-preload-4.c @@ -0,0 +1,62 @@ +/* Test case for x86 . + Copyright (C) 2018 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 + +static bool +ifunc_check_sse2 (void) +{ + return CPU_FEATURE_USABLE (SSE2); +} + +static bool +(*get_check_sse2 (void)) (void) +{ + return ifunc_check_sse2; +} + +bool check_sse2 (void) __attribute__((ifunc("get_check_sse2"))); + +static bool +ifunc_check_avx (void) +{ + return CPU_FEATURE_USABLE (AVX); +} + +static bool +(*get_check_avx (void)) (void) +{ + return ifunc_check_avx; +} + +bool check_avx (void) __attribute__((ifunc("get_check_avx"))); + +static bool +ifunc_check_avx2 (void) +{ + return CPU_FEATURE_USABLE (AVX2); +} + +static bool +(*get_check_avx2 (void)) (void) +{ + return ifunc_check_avx2; +} + +bool check_avx2 (void) __attribute__((ifunc("get_check_avx2")));