From patchwork Thu Oct 19 15:27:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 23692 Received: (qmail 57955 invoked by alias); 19 Oct 2017 15:27:15 -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 57942 invoked by uid 89); 19 Oct 2017 15:27:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-oi0-f68.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=2tp9tARJpzzYqxq1lDW/AkbbwAyJxOyq5dinwAhv4SU=; b=nMabGDPaxCblTwxhulmlpOzBHmEwfRkj8OLb4u6bnYG850d+ywFLlW7KXi5nqOQJME W5ILlY873oUKoxfWPue0EGoL9X574V1xQg1mcj9hRhAFKnawOelaqs81rkpjDp09bGzb mZM5yT7aMMNMBXDOJfXnymXEyhvfDXO/lct+m313fO/zEw2xW49R8oHypH1YgKlyoi+R KQ2rXLw/3Ev082pA56PRlOj3ziN6HV6yw9rT2lP6wBOO+DRwt0aeczpUbbCkfPMWPgBX yz/UH4NcGVbY63OKBWVyb+ml7knltq/QjCAWddsGRdeM0gfZbmr5I2/7OYhpX/HqmY7W 3oSg== X-Gm-Message-State: AMCzsaWdtNQpBIVupwRmKMbbi7hjAm9zPHS72lfciWCqdCghJmniWjjM 1IAqPRm0EFAthpTdYODH2ptQHItmNQDQQJa3r5kaAg== X-Google-Smtp-Source: ABhQp+SwuU+fND3EVqCyky657/w7qAw0UC431eIQpaYKwcr6FoqNqxkKlOTzNs0oMmvTglxEmjW0hg1T+fJUfhTrev0= X-Received: by 10.157.46.35 with SMTP id q32mr1046851otb.99.1508426831087; Thu, 19 Oct 2017 08:27:11 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <8b475ef3-ae8d-b731-3bc3-923aee864e1a@redhat.com> References: <20171017154436.GA29035@gmail.com> <460065513.644164.1508256542062@mail.yahoo.com> <1616746650.107335.1508308101304@mail.yahoo.com> <210199060.225015.1508419635063@mail.yahoo.com> <8b475ef3-ae8d-b731-3bc3-923aee864e1a@redhat.com> From: "H.J. Lu" Date: Thu, 19 Oct 2017 08:27:10 -0700 Message-ID: Subject: Re: [PATCH] x86-64: Don't set GLRO(dl_platform) to NULL [BZ #22299] To: Florian Weimer Cc: Valery Reznic , GNU C Library On Thu, Oct 19, 2017 at 7:51 AM, Florian Weimer wrote: > On 10/19/2017 04:41 PM, H.J. Lu wrote: >> >> + if (platform) >> + GLRO(dl_platform) = platform; > > > This should use “if (platform != NULL)”. Done. >> +ifneq (no,$(have-tunables)) >> +tests += tst-platform-1 >> +modules-names += tst-platformmod-1 x86_64/tst-platformmod-2 >> +CFLAGS-tst-platform-1.c = -mno-avx >> +CFLAGS-tst-platformmod-1.c = -mno-avx >> +CFLAGS-tst-platformmod-2.c = -mno-avx >> +LDFLAGS-tst-platformmod-2.so = -Wl,-soname,tst-platformmod-2.so >> +$(objpfx)tst-platform-1: $(objpfx)tst-platformmod-1.so >> +$(objpfx)tst-platform-1.out: $(objpfx)x86_64/tst-platformmod-2.so >> +# Turn off AVX512F_Usable and AVX2_Usable so that GLRO(dl_platform) is >> +# always set to x86_64. >> +tst-platform-1-ENV = LD_PRELOAD=$(objpfx)\$$PLATFORM/tst-platformmod-2.so >> \ >> + GLIBC_TUNABLES=glibc.tune.hwcaps=-AVX512F_Usable,-AVX2_Usable >> +endif > > > Does this build $(objpfx)/tst-platformmod-2.so? I think this would No. x86_64/tst-platformmod-2, not tst-platformmod-2, is added to modules-names. [hjl@gnu-6 build-x86_64-linux]$ find -name tst-platformmod-2.so ./elf/x86_64/tst-platformmod-2.so [hjl@gnu-6 build-x86_64-linux]$ > invalidate part of the test. I am checking it in now. Thanks. From f928eaf36143431a57b7a50213d36c639909b8ff Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 17 Oct 2017 08:27:09 -0700 Subject: [PATCH] x86-64: Don't set GLRO(dl_platform) to NULL [BZ #22299] Since ld.so expands $PLATFORM with GLRO(dl_platform), don't set GLRO(dl_platform) to NULL. 2017-10-19 Valery Reznic H.J. Lu [BZ #22299] * sysdeps/x86/cpu-features.c (init_cpu_features): Don't set GLRO(dl_platform) to NULL. * sysdeps/x86_64/Makefile (tests): Add tst-platform-1. (modules-names): Add tst-platformmod-1 and x86_64/tst-platformmod-2. (CFLAGS-tst-platform-1.c): New. (CFLAGS-tst-platformmod-1.c): Likewise. (CFLAGS-tst-platformmod-2.c): Likewise. (LDFLAGS-tst-platformmod-2.so): Likewise. ($(objpfx)tst-platform-1): Likewise. ($(objpfx)tst-platform-1.out): Likewise. (tst-platform-1-ENV): Likewise. ($(objpfx)x86_64/tst-platformmod-2.os): Likewise. * sysdeps/x86_64/tst-platform-1.c: New file. * sysdeps/x86_64/tst-platformmod-1.c: Likewise. * sysdeps/x86_64/tst-platformmod-2.c: Likewise. --- sysdeps/x86/cpu-features.c | 12 ++++++++---- sysdeps/x86_64/Makefile | 20 ++++++++++++++++++++ sysdeps/x86_64/tst-platform-1.c | 29 +++++++++++++++++++++++++++++ sysdeps/x86_64/tst-platformmod-1.c | 23 +++++++++++++++++++++++ sysdeps/x86_64/tst-platformmod-2.c | 23 +++++++++++++++++++++++ 5 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 sysdeps/x86_64/tst-platform-1.c create mode 100644 sysdeps/x86_64/tst-platformmod-1.c create mode 100644 sysdeps/x86_64/tst-platformmod-2.c diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c index c267f17b76..332b0f0d4a 100644 --- a/sysdeps/x86/cpu-features.c +++ b/sysdeps/x86/cpu-features.c @@ -335,7 +335,6 @@ no_cpuid: #endif /* Reuse dl_platform, dl_hwcap and dl_hwcap_mask for x86. */ - GLRO(dl_platform) = NULL; #if !HAVE_TUNABLES && defined SHARED /* The glibc.tune.hwcap_mask tunable is initialized already, so no need to do this. */ @@ -346,13 +345,15 @@ no_cpuid: GLRO(dl_hwcap) = HWCAP_X86_64; if (cpu_features->kind == arch_kind_intel) { + const char *platform = NULL; + if (CPU_FEATURES_ARCH_P (cpu_features, AVX512F_Usable) && CPU_FEATURES_CPU_P (cpu_features, AVX512CD)) { if (CPU_FEATURES_CPU_P (cpu_features, AVX512ER)) { if (CPU_FEATURES_CPU_P (cpu_features, AVX512PF)) - GLRO(dl_platform) = "xeon_phi"; + platform = "xeon_phi"; } else { @@ -363,7 +364,7 @@ no_cpuid: } } - if (GLRO(dl_platform) == NULL + if (platform == NULL && CPU_FEATURES_ARCH_P (cpu_features, AVX2_Usable) && CPU_FEATURES_ARCH_P (cpu_features, FMA_Usable) && CPU_FEATURES_CPU_P (cpu_features, BMI1) @@ -371,7 +372,10 @@ no_cpuid: && CPU_FEATURES_CPU_P (cpu_features, LZCNT) && CPU_FEATURES_CPU_P (cpu_features, MOVBE) && CPU_FEATURES_CPU_P (cpu_features, POPCNT)) - GLRO(dl_platform) = "haswell"; + platform = "haswell"; + + if (platform != NULL) + GLRO(dl_platform) = platform; } #else GLRO(dl_hwcap) = 0; diff --git a/sysdeps/x86_64/Makefile b/sysdeps/x86_64/Makefile index 1514805f4a..12d4737240 100644 --- a/sysdeps/x86_64/Makefile +++ b/sysdeps/x86_64/Makefile @@ -58,6 +58,21 @@ LDFLAGS-tst-x86_64mod-1.so = -Wl,-soname,tst-x86_64mod-1.so $(objpfx)tst-x86_64-1: $(objpfx)x86_64/tst-x86_64mod-1.so +ifneq (no,$(have-tunables)) +tests += tst-platform-1 +modules-names += tst-platformmod-1 x86_64/tst-platformmod-2 +CFLAGS-tst-platform-1.c = -mno-avx +CFLAGS-tst-platformmod-1.c = -mno-avx +CFLAGS-tst-platformmod-2.c = -mno-avx +LDFLAGS-tst-platformmod-2.so = -Wl,-soname,tst-platformmod-2.so +$(objpfx)tst-platform-1: $(objpfx)tst-platformmod-1.so +$(objpfx)tst-platform-1.out: $(objpfx)x86_64/tst-platformmod-2.so +# Turn off AVX512F_Usable and AVX2_Usable so that GLRO(dl_platform) is +# always set to x86_64. +tst-platform-1-ENV = LD_PRELOAD=$(objpfx)\$$PLATFORM/tst-platformmod-2.so \ + GLIBC_TUNABLES=glibc.tune.hwcaps=-AVX512F_Usable,-AVX2_Usable +endif + tests += tst-audit3 tst-audit4 tst-audit5 tst-audit6 tst-audit7 \ tst-audit10 tst-sse tst-avx tst-avx512 test-extras += tst-audit4-aux tst-audit10-aux \ @@ -141,3 +156,8 @@ do-tests-clean common-mostlyclean: tst-x86_64-1-clean .PHONY: tst-x86_64-1-clean tst-x86_64-1-clean: -rm -rf $(objpfx)x86_64 + +$(objpfx)x86_64/tst-platformmod-2.os: $(objpfx)tst-platformmod-2.os + $(make-target-directory) + rm -f $@ + ln $< $@ diff --git a/sysdeps/x86_64/tst-platform-1.c b/sysdeps/x86_64/tst-platform-1.c new file mode 100644 index 0000000000..76a02e4b6d --- /dev/null +++ b/sysdeps/x86_64/tst-platform-1.c @@ -0,0 +1,29 @@ +/* Test PRELOAD with $PLATFORM. + Copyright (C) 2017 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 + +extern int preload (void); + +static int +do_test (void) +{ + return preload () == 0x1234 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +#include diff --git a/sysdeps/x86_64/tst-platformmod-1.c b/sysdeps/x86_64/tst-platformmod-1.c new file mode 100644 index 0000000000..9ef5e2b5be --- /dev/null +++ b/sysdeps/x86_64/tst-platformmod-1.c @@ -0,0 +1,23 @@ +/* Test PRELOAD with $PLATFORM. + Copyright (C) 2017 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 + . */ + +int +preload (void) +{ + return 0; +} diff --git a/sysdeps/x86_64/tst-platformmod-2.c b/sysdeps/x86_64/tst-platformmod-2.c new file mode 100644 index 0000000000..d0e5103892 --- /dev/null +++ b/sysdeps/x86_64/tst-platformmod-2.c @@ -0,0 +1,23 @@ +/* Test PRELOAD with $PLATFORM. + Copyright (C) 2017 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 + . */ + +int +preload (void) +{ + return 0x1234; +} -- 2.13.6