From patchwork Mon Feb 28 06:40:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 51420 X-Patchwork-Delegate: tuliom@linux.vnet.ibm.com 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 A6136385841E for ; Mon, 28 Feb 2022 06:43:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6136385841E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1646030604; bh=AwgdXVRsWGvShLbkaMkVqLNoeMWhJ8Ctq7P93MiDacA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=e4xsmRMFJf1oJhJWyD1zyB4Sx0LgBet3WHsAdWhX6BtvQSRcjA/r9q+c0WnWOaE0P eg8DQcGZd5vu46gjsnk2ffAv80XiVUWUzfhxrQlmYa4zP0BnI72yzV5QqEXWmqaBX0 M1HtD0XpyeO+3z1QybUrvijQJDfjQJceJtgxvDjQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by sourceware.org (Postfix) with ESMTPS id 365FE3858C83 for ; Mon, 28 Feb 2022 06:41:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 365FE3858C83 Received: by mail-pg1-x52f.google.com with SMTP id bc27so1702127pgb.4 for ; Sun, 27 Feb 2022 22:41:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AwgdXVRsWGvShLbkaMkVqLNoeMWhJ8Ctq7P93MiDacA=; b=psTq+Spq4LbO3V8mLfuczsqfCgjeakaabBEM+gtbgh586sS/FlSh4yGpEgnPM4EBkj ay1AXrhUoud1RdIBTip6sQ6dEqn1BQHcNB/OG8rQpgKVczQCrorBE2KuphFgB3tbT/nP FaQwLrU0H4Ei0lMyZjPwmSfch1CW2/mlnxmLXk2d1+1acHX4Aknu3VzQJ4hZpubwvOZ+ STEDSAQMiueoRnCOgLjFicayNLzazJZs12kebILmwzHKnp5h2RnfpWQ1O9wrjbExvpRR QJUIXmYtmzc3Bfe12LNw4QGvOLSGHT7TEC+yhlgCrZ9/hi5hoows5M0Q2T5+id7x17o3 rbfw== X-Gm-Message-State: AOAM532P3Pvgq3JBfwopRUi05NneUypvAVHD9xOFe8s9KFUDwTumK3qn /M5YR/YZnIuCFJ/Uoi1QosAzIO8nUoc= X-Google-Smtp-Source: ABdhPJzs3bK8K1VHjx2pVp5LKJqlcXWwoucxycQ9ufhSe/Tov36xrSDN1RdWXG44KBFyvC1434R+/g== X-Received: by 2002:a62:63c2:0:b0:4e1:604:f07 with SMTP id x185-20020a6263c2000000b004e106040f07mr19763351pfb.56.1646030500847; Sun, 27 Feb 2022 22:41:40 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:f31d:e338:6c7b:8cfa]) by smtp.gmail.com with ESMTPSA id q15-20020a63504f000000b0037425262293sm9130249pgl.43.2022.02.27.22.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 22:41:40 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v2 2/4] powerpc64: Set up thread register for _dl_relocate_static_pie Date: Mon, 28 Feb 2022 17:10:50 +1030 Message-Id: <20220228064052.3413334-3-amodra@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220228064052.3413334-1-amodra@gmail.com> References: <20220228064052.3413334-1-amodra@gmail.com> MIME-Version: 1.0 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Alan Modra via Libc-alpha From: Alan Modra Reply-To: Alan Modra Cc: Tulio Magno Quites Machado Filho , Alan Modra Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" libgcc ifunc resolvers that access hwcap via a field in the tcb can't be called until the thread pointer is set up. Other ifunc resolvers might need access to at_platform. This patch sets up a fake thread pointer early to a copy of tcbhead_t. hwcapinfo.c already had local variables for hwcap and at_platform, replace them with an entire tcbhead_t. It's not that large and this way we easily ensure hwcap and at_platform are at the same relative offsets as they are in the real thread block. The patch also conditionally disables part of tst-tlsifunc-static, "bar address read from IFUNC resolver is incorrect". We can't get a proper address for a thread variable before glibc initialises tls. Reviewed-by: Tulio Magno Quites Machado Filho diff --git a/sysdeps/powerpc/hwcapinfo.c b/sysdeps/powerpc/hwcapinfo.c index e030e322bd..afde05f863 100644 --- a/sysdeps/powerpc/hwcapinfo.c +++ b/sysdeps/powerpc/hwcapinfo.c @@ -20,8 +20,7 @@ #include #include -uint64_t __tcb_hwcap __attribute__ ((visibility ("hidden"))); -uint32_t __tcb_platform __attribute__ ((visibility ("hidden"))); +tcbhead_t __tcb __attribute__ ((visibility ("hidden"))); /* This function parses the HWCAP/HWCAP2 fields, adding the previous supported ISA bits, as well as converting the AT_PLATFORM string to a number. This @@ -34,7 +33,7 @@ __tcb_parse_hwcap_and_convert_at_platform (void) uint64_t h1, h2; /* Read AT_PLATFORM string from auxv and convert it to a number. */ - __tcb_platform = _dl_string_platform (GLRO (dl_platform)); + __tcb.at_platform = _dl_string_platform (GLRO (dl_platform)); /* Read HWCAP and HWCAP2 from auxv. */ h1 = GLRO (dl_hwcap); @@ -66,8 +65,7 @@ __tcb_parse_hwcap_and_convert_at_platform (void) /* Consolidate both HWCAP and HWCAP2 into a single doubleword so that we can read both in a single load later. */ - __tcb_hwcap = h2; - __tcb_hwcap = (h1 << 32) | __tcb_hwcap; + __tcb.hwcap = (h1 << 32) | (h2 & 0xffffffff); } #if IS_IN (rtld) diff --git a/sysdeps/powerpc/hwcapinfo.h b/sysdeps/powerpc/hwcapinfo.h index ac462835ce..1f5e0bcb51 100644 --- a/sysdeps/powerpc/hwcapinfo.h +++ b/sysdeps/powerpc/hwcapinfo.h @@ -21,8 +21,7 @@ #ifndef HWCAPINFO_H # define HWCAPINFO_H -extern uint64_t __tcb_hwcap attribute_hidden; -extern uint32_t __tcb_platform attribute_hidden; +extern tcbhead_t __tcb attribute_hidden; extern void __tcb_parse_hwcap_and_convert_at_platform (void); diff --git a/sysdeps/powerpc/nptl/tls.h b/sysdeps/powerpc/nptl/tls.h index b80d39ad41..22b0075235 100644 --- a/sysdeps/powerpc/nptl/tls.h +++ b/sysdeps/powerpc/nptl/tls.h @@ -45,8 +45,6 @@ #ifndef __ASSEMBLER__ -# include - /* Get system call information. */ # include @@ -100,6 +98,8 @@ typedef struct dtv_t *dtv; } tcbhead_t; +# include + /* This is the size of the initial TCB. */ # define TLS_INIT_TCB_SIZE 0 @@ -137,8 +137,8 @@ typedef struct # define TLS_INIT_TP(tcbp) \ ({ \ __thread_register = (void *) (tcbp) + TLS_TCB_OFFSET; \ - THREAD_SET_HWCAP (__tcb_hwcap); \ - THREAD_SET_AT_PLATFORM (__tcb_platform); \ + THREAD_SET_HWCAP (__tcb.hwcap); \ + THREAD_SET_AT_PLATFORM (__tcb.at_platform); \ NULL; \ }) diff --git a/sysdeps/powerpc/powerpc64/dl-machine.h b/sysdeps/powerpc/powerpc64/dl-machine.h index 6fab5cbe81..bb0ccd0811 100644 --- a/sysdeps/powerpc/powerpc64/dl-machine.h +++ b/sysdeps/powerpc/powerpc64/dl-machine.h @@ -559,6 +559,27 @@ elf_machine_plt_value (struct link_map *map, const Elf64_Rela *reloc, #define ARCH_LA_PLTEXIT ppc64v2_gnu_pltexit #endif +#if ENABLE_STATIC_PIE && !defined SHARED && !IS_IN (rtld) +#include +#include + +/* Set up r13 for _dl_relocate_static_pie so that libgcc ifuncs that + normally access the tcb copy of hwcap will see __tcb.hwcap. */ + +static inline void __attribute__ ((always_inline)) +ppc_init_fake_thread_pointer (void) +{ + DIAG_PUSH_NEEDS_COMMENT; + /* We are playing pointer tricks. Silence gcc warning. */ + DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Warray-bounds"); + __thread_register = (char *) &__tcb.hwcap - TCB_HWCAP; + DIAG_POP_NEEDS_COMMENT; +} + +#define ELF_MACHINE_BEFORE_RTLD_RELOC(map, dynamic_info) \ + ppc_init_fake_thread_pointer (); +#endif /* ENABLE_STATIC_PIE && !defined SHARED && !IS_IN (rtld) */ + #endif /* dl_machine_h */ #ifdef RESOLVE_MAP diff --git a/sysdeps/powerpc/tst-tlsifunc-static.c b/sysdeps/powerpc/tst-tlsifunc-static.c index c0ff8972a9..438b27c0ec 100644 --- a/sysdeps/powerpc/tst-tlsifunc-static.c +++ b/sysdeps/powerpc/tst-tlsifunc-static.c @@ -16,4 +16,5 @@ License along with the GNU C Library; if not, see . */ +#define TST_TLSIFUNC_STATIC 1 #include "tst-tlsifunc.c" diff --git a/sysdeps/powerpc/tst-tlsifunc.c b/sysdeps/powerpc/tst-tlsifunc.c index 92313e68f4..6b256c6229 100644 --- a/sysdeps/powerpc/tst-tlsifunc.c +++ b/sysdeps/powerpc/tst-tlsifunc.c @@ -101,11 +101,14 @@ do_test (void) if (&bar == bar_ptr) printf ("PASS: bar address read from IFUNC resolver is correct.\n"); +#if !defined TST_TLSIFUNC_STATIC || !defined PIC \ + || !defined PI_STATIC_AND_HIDDEN else { printf ("FAIL: bar address read from IFUNC resolver is incorrect.\n"); ret = 1; } +#endif if (tcb_test ()) printf ("PASS: tcb_test IFUNC resolver called once.\n");