From patchwork Mon Jan 24 03:47:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 50376 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 D120F3858410 for ; Mon, 24 Jan 2022 03:48:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D120F3858410 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642996090; bh=njNUBFsn9IO4YEHZqzHkhHtAuwhtUt+YG20M5NVoSSw=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=glwWj+YS6DARmfDfQ5/SgvNxszfnibzqN4NU7JdirjMLOkVj22a+j3dO1iIqyu0jP FYQFtbjrRKzn3/uCip8Cpnv5n+eCemwr7V1aQVvu+Ab4/cQo12OQPsrvMblTjanPiM n+tFGnKPlsE/ZqryISEV2KbAKbQ/oZKYV5jZQrq4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 417763858434 for ; Mon, 24 Jan 2022 03:47:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 417763858434 Received: by mail-pf1-x430.google.com with SMTP id a8so9263084pfa.6 for ; Sun, 23 Jan 2022 19:47:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=njNUBFsn9IO4YEHZqzHkhHtAuwhtUt+YG20M5NVoSSw=; b=yXEDQjEmwmB4CqNOW5bFwwT5FsKbE7UWwIwaacJ2tB3HRUFQ53dLK/ApW4bDPvGTz4 SBdA4fMh8///uoh+cY0d9SIDOigKI/wiaRrHNLVMNpCmzH54RvUeKr+Yc1jwv8UUU7Jx jEERSz9goFv3xhqi+bgo2TdH6VNFVSC53woOR7syB44YnN92e6ddv5iM0K2osXHcV9K4 9mwXl0Ua9hS9chlAe2t1FVRuTXLBcoyJs7rcWTPS7xCKrJfdAEwSia6cX8hTGqcrWiwi FBGML4dWIXgcGPSau3TjGQS5DkqfeziQlwhs6g4IEldaTgzYP22/ZjKzjSQBfWSsQS1R A6lQ== X-Gm-Message-State: AOAM5326O7KMI/56keDWyEx9kk9PpmUO2I+S5McJmm5ObV9udWXbMVST kMoWJkmKkZz0gssfKLrBUVna29DUk8Y= X-Google-Smtp-Source: ABdhPJwh+RMRC4C7dyqNCBZeLZcVxkCLPY9x7wN1xWlctSq+X9l1Dvt88jzyDG0cIyvRzMWi/arKcA== X-Received: by 2002:a05:6a00:148c:b0:4c2:6f06:8c70 with SMTP id v12-20020a056a00148c00b004c26f068c70mr12714398pfu.48.1642996056386; Sun, 23 Jan 2022 19:47:36 -0800 (PST) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id kk17sm2660655pjb.21.2022.01.23.19.47.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jan 2022 19:47:35 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 82F4B1140025; Mon, 24 Jan 2022 14:17:32 +1030 (ACDT) Date: Mon, 24 Jan 2022 14:17:32 +1030 To: libc-alpha@sourceware.org Subject: [PATCH 2/5] [PowerPC64] Set up thread register for _dl_relocate_static_pie Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3038.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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 Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" On Sun, Jan 23, 2022 at 11:12:13PM +1030, Alan Modra wrote: > There's a serious problem in libgcc too. libgcc ifuncs access the > AT_HWCAP words stored in the tcb with an offset from the thread > pointer (r13), but r13 isn't set at the time _dl_relocate_static_pie > runs, and I'm loathe to try calling init_tls early. A better approach > that might work is to fake r13 so that _dl_hwcap is at the expected > offset where we'd normally find the tcb hwcap words. Like this. libgcc ifunc resolvers that access hwcap via a field in the tcb can't be called until the thread pointer is set up. This patch sets up a fake thread pointer early so that static-pies won't segfault on attempting to relocate themselves. diff --git a/sysdeps/powerpc/powerpc64/dl-machine.h b/sysdeps/powerpc/powerpc64/dl-machine.h index eb41c85280..413bbe7c06 100644 --- a/sysdeps/powerpc/powerpc64/dl-machine.h +++ b/sysdeps/powerpc/powerpc64/dl-machine.h @@ -589,6 +589,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