From patchwork Thu May 25 20:25:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 767110 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3wYgnH0R5Nz9s8N for ; Fri, 26 May 2017 06:28:02 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="GvcvH4zW"; dkim-atps=neutral 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=QbeeLf5ggS2eMJmCdVFZfuAo0aDqLE8 G6sZhLzHt5tKQT4CyUilQ5PuPGkjXDZqlOlZ8LKP03n1aeuwAV4dhQiEWOgdhcCM RxwtSCKgLjEwLsRcB+Gu4OwbYyf5b65lMkMnypgpnoAyATH4vMtj4LOVr+ojPtLB r1rb+vSOICBY= 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=6UM0kxdsdJ0KoSMSgDm2X/fHFp0=; b=GvcvH 4zWrctympeHn/Y2KHLEZvHffDEqkcgwtoxjS8dRc/WSwwGhUDNdVn3od+uDFMb/I o4dAQMR1NJSRKcKgRuaJYv2kdkq2OoZ/2YthDOVRy/qPZ4NCxVwR211tnhV8Chmm oZEu5OaWW+tIn+Jvg2wnUXdmTKOjbls/uU/3nU= Received: (qmail 91227 invoked by alias); 25 May 2017 20: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 91104 invoked by uid 89); 25 May 2017 20:27:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_NEUTRAL autolearn=ham version=3.3.2 spammy=3517 X-HELO: homiemail-a92.g.dreamhost.com From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Cc: adhemerval.zanella@linaro.org Subject: [PATCH 3/4] Make LD_HWCAP_MASK usable for static binaries Date: Fri, 26 May 2017 01:55:59 +0530 Message-Id: <1495743960-23665-4-git-send-email-siddhesh@sourceware.org> In-Reply-To: <1495743960-23665-1-git-send-email-siddhesh@sourceware.org> References: <1495743960-23665-1-git-send-email-siddhesh@sourceware.org> The LD_HWCAP_MASK environment variable was ignored in static binaries, which is inconsistent with the behaviour of dynamically linked binaries. This seems to have been because of the inability of ld_hwcap_mask being read early enough to influence anything but now that it is in tunables, the mask is usable in static binaries as well. This feature is important for aarch64, which relies on HWCAP_CPUID being masked out to disable multiarch. A sanity test on x86_64 shows that there are no failures. Likewise for aarch64. * elf/dl-hwcaps.h [HAVE_TUNABLES]: Always read hwcap_mask. * sysdeps/sparc/sparc32/dl-machine.h [HAVE_TUNABLES]: Likewise. * sysdeps/x86/cpu-features.c (init_cpu_features): Always set up hwcap and hwcap_mask. --- elf/dl-hwcaps.h | 14 +++++++------- sysdeps/sparc/sparc32/dl-machine.h | 2 +- sysdeps/x86/cpu-features.c | 8 +++----- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/elf/dl-hwcaps.h b/elf/dl-hwcaps.h index 169ad1b..a8060d5 100644 --- a/elf/dl-hwcaps.h +++ b/elf/dl-hwcaps.h @@ -18,13 +18,13 @@ #include -#ifdef SHARED -# if HAVE_TUNABLES -# define GET_HWCAP_MASK() TUNABLE_GET (glibc, tune, hwcap_mask, uint64_t) +#if HAVE_TUNABLES +# define GET_HWCAP_MASK() TUNABLE_GET (glibc, tune, hwcap_mask, uint64_t) +#else +# ifdef SHARED +# define GET_HWCAP_MASK() GLRO(dl_hwcap_mask) # else -# define GET_HWCAP_MASK() GLRO(dl_hwcap_mask) +/* HWCAP_MASK is ignored in static binaries when built without tunables. */ +# define GET_HWCAP_MASK() (0) # endif -#else -/* HWCAP_MASK is ignored in static binaries. */ -# define GET_HWCAP_MASK() (0) #endif diff --git a/sysdeps/sparc/sparc32/dl-machine.h b/sysdeps/sparc/sparc32/dl-machine.h index f9ae133..95f6732 100644 --- a/sysdeps/sparc/sparc32/dl-machine.h +++ b/sysdeps/sparc/sparc32/dl-machine.h @@ -37,7 +37,7 @@ elf_machine_matches_host (const Elf32_Ehdr *ehdr) return 1; else if (ehdr->e_machine == EM_SPARC32PLUS) { -#ifdef SHARED +#if HAVE_TUNABLES || defined SHARED uint64_t hwcap_mask = GET_HWCAP_MASK(); return GLRO(dl_hwcap) & hwcap_mask & HWCAP_SPARC_V9; #else diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c index 4fe58bf..4288001 100644 --- a/sysdeps/x86/cpu-features.c +++ b/sysdeps/x86/cpu-features.c @@ -312,17 +312,16 @@ no_cpuid: cpu_features->model = model; cpu_features->kind = kind; -#if IS_IN (rtld) /* Reuse dl_platform, dl_hwcap and dl_hwcap_mask for x86. */ GLRO(dl_platform) = NULL; GLRO(dl_hwcap) = 0; -#if !HAVE_TUNABLES +#if !HAVE_TUNABLES && defined SHARED /* The glibc.tune.hwcap_mask tunable is initialized already, so no need to do this. */ GLRO(dl_hwcap_mask) = HWCAP_IMPORTANT; #endif -# ifdef __x86_64__ +#ifdef __x86_64__ if (cpu_features->kind == arch_kind_intel) { if (CPU_FEATURES_ARCH_P (cpu_features, AVX512F_Usable) @@ -352,7 +351,7 @@ no_cpuid: && CPU_FEATURES_CPU_P (cpu_features, POPCNT)) GLRO(dl_platform) = "haswell"; } -# else +#else if (CPU_FEATURES_CPU_P (cpu_features, SSE2)) GLRO(dl_hwcap) |= HWCAP_X86_SSE2; @@ -360,6 +359,5 @@ no_cpuid: GLRO(dl_platform) = "i686"; else if (CPU_FEATURES_ARCH_P (cpu_features, I586)) GLRO(dl_platform) = "i586"; -# endif #endif }