From patchwork Tue Oct 17 15:44:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 827099 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-85947-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="b3HkUGtn"; 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 3yGfdX18PVz9t32 for ; Wed, 18 Oct 2017 02:44:47 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:reply-to :mime-version:content-type; q=dns; s=default; b=F1c96Tcy2RbK8nMv meUd9W9ojDJpnMUUWJMisBBfrLk8vOs6kBdZKCiFlzrqum/hOeGmktk7zp+LNTHn VmHVtjjsSROEBhbr9EAweCJGe06+g2gTcgQxqrsU/xqiqdxt0ZV7L4VqPqJfe7/P EjkM1/JiUcifhXehn08ze0IJZfM= 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:date:from:to:cc:subject:message-id:reply-to :mime-version:content-type; s=default; bh=gphebCgKX2H5vHjmDjO9hS HQROY=; b=b3HkUGtnlb24qOSyjVylca9HQiEcACooVtmMSj3iKOyceTFU8U6RMq puMMTZmXkQCkP65W5qJv3UeUsH5RF1ZXtb46iFVKWC4pk/LGpcVLbEUGtDZQsnko 33IigTO5IqM3k1lp7yrVe1QL69ZhurxHScMSZb+1RYkv3ZrvR8LuQ= Received: (qmail 129302 invoked by alias); 17 Oct 2017 15:44:42 -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 129283 invoked by uid 89); 17 Oct 2017 15:44:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, NO_DNS_FOR_FROM, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=HCc:D*yahoo.com X-HELO: mga05.intel.com X-ExtLoop1: 1 Date: Tue, 17 Oct 2017 08:44:36 -0700 From: "H.J. Lu" To: GNU C Library Cc: Valery Reznic Subject: [PATCH] x86-64: Don't set GLRO(dl_platform) to NULL [BZ #22299] Message-ID: <20171017154436.GA29035@gmail.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) Since ld.so expands $PLATFORM with GLRO(dl_platform), don't set GLRO(dl_platform) to NULL. OK for master and 2.26 branch? H.J. --- 2017-10-17 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 | 18 ++++++++++++++++++ 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, 101 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..1b3cfcc7cd 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) + GLRO(dl_platform) = platform; } #else GLRO(dl_hwcap) = 0; diff --git a/sysdeps/x86_64/Makefile b/sysdeps/x86_64/Makefile index 1514805f4a..9ccb8905b1 100644 --- a/sysdeps/x86_64/Makefile +++ b/sysdeps/x86_64/Makefile @@ -58,6 +58,19 @@ 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 +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 + 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 +154,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; +}