From patchwork Sun Jan 23 12:42:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 50370 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 1EF2D3858408 for ; Sun, 23 Jan 2022 12:42:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1EF2D3858408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642941760; bh=mPJe5qsyZkBKJNK7f5tEfXQoqbfgLPLjmyj9gBEtzE8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Irc+9ZW25HD3o8QG7FF1xosiNMo8kCL+Uv6K630KoQ6Ebq0OB/g8lbjL0nI9IG6so xvBxn73emIpPQSJDtSZbBywcAKNc9ldqjGpP9yQ/w8k9JgvVjOjLS3VSUO+zAGrRxS tAlZdUyAt/Pwh9yUQjY9WBSbtmoQ5iADCBEvCbfA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by sourceware.org (Postfix) with ESMTPS id 954973858C60 for ; Sun, 23 Jan 2022 12:42:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 954973858C60 Received: by mail-pj1-x102b.google.com with SMTP id z10-20020a17090acb0a00b001b520826011so9352323pjt.5 for ; Sun, 23 Jan 2022 04:42:18 -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:mime-version :content-disposition; bh=mPJe5qsyZkBKJNK7f5tEfXQoqbfgLPLjmyj9gBEtzE8=; b=mm2FRXBVOEYeUOn0Mg4cW+QFQ64oHahipUuYTD4nOm20Pud6tDpBnJu0xLgOiTi2p7 6qPOGV2rezCAyzkzl/DHr4bf+2P5erxyjojL87fwgeFbM3D1mi+zAJn9NQMOsRSsAtOn JF7kuV11AdWELrXPIiKZeC3+UKHW8yqH+sNYboZnj5Slcw61MccysG5CzhNUpXwNaSpp gSC1PsqprlPYdBLEEUiCluqiURDC+8+nW/9xpi36DJBqqMXpZTDd+0bWnSHNsqnG73q9 xWkW4eCw1Pi3uoVkzg5XVY0u+bOASGl+/TeDNqm/kDFOeSIkXx8aHhs+QXWdejItXbG3 QIAg== X-Gm-Message-State: AOAM531/r2jOLnR2b00QKAvrI0BX3c4f1owWKVXNI0hJlR5lwN7P7zkK wwzEGsmIITlk9fIEzN9XbWFMeNmOQDc= X-Google-Smtp-Source: ABdhPJyNIHmMrntqz9/XVOZXW3KmxZMzi7uhiPsGOydo2q2hpizGW38vFT1xXLhKBCL9erXarKvWew== X-Received: by 2002:a17:902:aa43:b0:14a:ca21:979a with SMTP id c3-20020a170902aa4300b0014aca21979amr11304298plr.18.1642941737695; Sun, 23 Jan 2022 04:42:17 -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 lr7sm8442274pjb.42.2022.01.23.04.42.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jan 2022 04:42:16 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 342021140F2C; Sun, 23 Jan 2022 23:12:13 +1030 (ACDT) Date: Sun, 23 Jan 2022 23:12:13 +1030 To: libc-alpha@sourceware.org Subject: [PowerPC64] Use medium model toc accesses throughout Message-ID: MIME-Version: 1.0 Content-Disposition: inline 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" The PowerPC64 linker edits medium model toc-indirect code to toc-pointer relative: addis r9,r2,tc_entry_for_var@toc@ha ld r9,tc_entry_for_var@toc@l(r9) becomes addis r9,r2,(var-.TOC.)@ha addi r9,r9,(var-.TOC.)@l when "var" is known to be local to the binary. This isn't done for small-model toc-indirect code, because "var" is almost guaranteed to be too far away from .TOC. for a 16-bit signed offset. And, because the analysis of which .toc entry can be removed becomes much more complicated in objects that mix code models, they aren't removed if any small-model toc sequence appears in an object file. Unfortunately glibc's build of ld.so smashes the needed objects together in a ld -r linking stage. This means the GOT/TOC is left with a whole lot of relative relocations which is untidy, but in itself is not a serious problem. However, static-pie on powerpc64 bombs due to a segfault caused by one of the small-model accesses before _dl_relocate_static_pie. (The very first one in rcrt1.o passing start_addresses in r8 to __libc_start_main.) So this patch makes all the toc/got accesses in assembly medium code model, and a couple of functions hidden. By itself this is *not* enough to give us working static-pie, but it is useful anyway to enable better linker optimisation. 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. Tested for regressions with a powerpc64le-linux build and test run. OK to apply? diff --git a/sysdeps/powerpc/powerpc64/__longjmp-common.S b/sysdeps/powerpc/powerpc64/__longjmp-common.S index 4d71b9e102..5f629e1e0f 100644 --- a/sysdeps/powerpc/powerpc64/__longjmp-common.S +++ b/sysdeps/powerpc/powerpc64/__longjmp-common.S @@ -47,12 +47,14 @@ ENTRY (__longjmp) CALL_MCOUNT 2 #ifndef __NO_VMX__ - ld r5,.LC__dl_hwcap@toc(r2) + addis r5,r2,.LC__dl_hwcap@toc@ha + ld r5,.LC__dl_hwcap@toc@l(r5) # ifdef SHARED /* Load _rtld-global._dl_hwcap. */ - ld r5,RTLD_GLOBAL_RO_DL_HWCAP_OFFSET(r5) + ld r5,RTLD_GLOBAL_RO_DL_HWCAP_OFFSET(r5) # else - ld r5,0(r5) /* Load extern _dl_hwcap. */ + /* Load extern _dl_hwcap. */ + ld r5,0(r5) # endif andis. r5,r5,(PPC_FEATURE_HAS_ALTIVEC >> 16) beq L(no_vmx) diff --git a/sysdeps/powerpc/powerpc64/dl-machine.h b/sysdeps/powerpc/powerpc64/dl-machine.h index a505998351..eb41c85280 100644 --- a/sysdeps/powerpc/powerpc64/dl-machine.h +++ b/sysdeps/powerpc/powerpc64/dl-machine.h @@ -175,9 +175,12 @@ BODY_PREFIX "_dl_start_user:\n" \ /* the address of _start in r30. */ \ " mr 30,3\n" \ /* &_dl_argc in 29, &_dl_argv in 27, and _dl_loaded in 28. */ \ -" ld 28,.LC__rtld_local@toc(2)\n" \ -" ld 29,.LC__dl_argc@toc(2)\n" \ -" ld 27,.LC__dl_argv@toc(2)\n" \ +" addis 28,2,.LC__rtld_local@toc@ha\n" \ +" ld 28,.LC__rtld_local@toc@l(28)\n" \ +" addis 29,2,.LC__dl_argc@toc@ha\n" \ +" ld 29,.LC__dl_argc@toc@l(29)\n" \ +" addis 27,2,.LC__dl_argv@toc@ha\n" \ +" ld 27,.LC__dl_argv@toc@l(27)\n" \ /* _dl_init (_dl_loaded, _dl_argc, _dl_argv, _dl_argv+_dl_argc+1). */ \ " ld 3,0(28)\n" \ " lwa 4,0(29)\n" \ @@ -204,7 +207,8 @@ BODY_PREFIX "_dl_start_user:\n" \ " addi 6,6,8\n" \ /* Pass a termination function pointer (in this case _dl_fini) in \ r7. */ \ -" ld 7,.LC__dl_fini@toc(2)\n" \ +" addis 7,2,.LC__dl_fini@toc@ha\n" \ +" ld 7,.LC__dl_fini@toc@l(7)\n" \ /* Pass the stack pointer in r1 (so far so good), pointing to a NULL \ value. This lets our startup code distinguish between a program \ linked statically, which linux will call with argc on top of the \ diff --git a/sysdeps/powerpc/powerpc64/dl-trampoline.S b/sysdeps/powerpc/powerpc64/dl-trampoline.S index 23debc2faf..45b821607b 100644 --- a/sysdeps/powerpc/powerpc64/dl-trampoline.S +++ b/sysdeps/powerpc/powerpc64/dl-trampoline.S @@ -32,6 +32,7 @@ because gcc as of 2010/05 doesn't allocate a proper stack frame for a function that makes no calls except for __tls_get_addr and we might be here resolving the __tls_get_addr call. */ + .hidden _dl_runtime_resolve #define INT_PARMS FRAME_MIN_SIZE ENTRY (_dl_runtime_resolve, 4) stdu r1,-FRAME_SIZE(r1) @@ -195,6 +196,7 @@ END(_dl_runtime_resolve) parm1 (r3) and the index (r0) needs to be converted to an offset (index * 24) in parm2 (r4). */ #ifndef PROF + .hidden _dl_profile_resolve ENTRY (_dl_profile_resolve, 4) /* Spill r30, r31 to preserve the link_map* and reloc_addr, in case we need to call _dl_audit_pltexit. */ @@ -225,12 +227,14 @@ ENTRY (_dl_profile_resolve, 4) std r9,INT_PARMS+48(r1) std r10,INT_PARMS+56(r1) std r8,CALLING_SP(r1) - ld r12,.LC__dl_hwcap@toc(r2) + addis r12,r2,.LC__dl_hwcap@toc@ha + ld r12,.LC__dl_hwcap@toc@l(r12) #ifdef SHARED /* Load _rtld_local_ro._dl_hwcap. */ ld r12,RTLD_GLOBAL_RO_DL_HWCAP_OFFSET(r12) #else - ld r12,0(r12) /* Load extern _dl_hwcap. */ + /* Load extern _dl_hwcap. */ + ld r12,0(r12) #endif andis. r0,r12,(PPC_FEATURE_HAS_ALTIVEC >> 16) beq L(saveFP) diff --git a/sysdeps/powerpc/powerpc64/setjmp-common.S b/sysdeps/powerpc/powerpc64/setjmp-common.S index 41812e3427..19e76d59ee 100644 --- a/sysdeps/powerpc/powerpc64/setjmp-common.S +++ b/sysdeps/powerpc/powerpc64/setjmp-common.S @@ -132,12 +132,14 @@ JUMPTARGET(GLUE(__sigsetjmp_symbol,_ent)): std r31,((JB_GPRS+17)*8)(3) stfd fp31,((JB_FPRS+17)*8)(3) #ifndef __NO_VMX__ - ld r6,.LC__dl_hwcap@toc(r2) + addis r6,r2,.LC__dl_hwcap@toc@ha + ld r6,.LC__dl_hwcap@toc@l(r6) # ifdef SHARED /* Load _rtld-global._dl_hwcap. */ - ld r6,RTLD_GLOBAL_RO_DL_HWCAP_OFFSET(r6) + ld r6,RTLD_GLOBAL_RO_DL_HWCAP_OFFSET(r6) # else - ld r6,0(r6) /* Load extern _dl_hwcap. */ + /* Load extern _dl_hwcap. */ + ld r6,0(r6) # endif andis. r6,r6,(PPC_FEATURE_HAS_ALTIVEC >> 16) beq L(no_vmx) diff --git a/sysdeps/powerpc/powerpc64/start.S b/sysdeps/powerpc/powerpc64/start.S index 4319dc8d3e..244d9da07b 100644 --- a/sysdeps/powerpc/powerpc64/start.S +++ b/sysdeps/powerpc/powerpc64/start.S @@ -74,7 +74,8 @@ ENTRY (_start) /* put the address of start_addresses in r8... ** ** PPC64 ABI uses R13 for thread local, so we leave it alone */ - ld r8,.L01@toc(r2) + addis r8,r2,.L01@toc@ha + ld r8,.L01@toc@l(r8) /* and continue in libc-start, in glibc. */ b JUMPTARGET(__libc_start_main) diff --git a/sysdeps/powerpc/powerpc64/sysdep.h b/sysdeps/powerpc/powerpc64/sysdep.h index 3fec06e0df..011068b290 100644 --- a/sysdeps/powerpc/powerpc64/sysdep.h +++ b/sysdeps/powerpc/powerpc64/sysdep.h @@ -469,14 +469,16 @@ LT_LABELSUFFIX(name,_name_end): ; \ .tc _rtld_global_ro[TC],_rtld_global_ro # endif # define __GLRO(rOUT, var, offset) \ - ld rOUT,.LC__ ## var@toc(r2); \ + addis rOUT,r2,.LC__ ## var@toc@ha; \ + ld rOUT,.LC__ ## var@toc@l(rOUT); \ lwz rOUT,offset(rOUT) #else # define __GLRO_DEF(var) \ .LC__ ## var: \ .tc _ ## var[TC],_ ## var # define __GLRO(rOUT, var, offset) \ - ld rOUT,.LC__ ## var@toc(r2); \ + addis rOUT,r2,.LC__ ## var@toc@ha; \ + ld rOUT,.LC__ ## var@toc@l(rOUT); \ lwz rOUT,0(rOUT) #endif 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 From patchwork Mon Jan 24 03:50:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 50377 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 E43F53858435 for ; Mon, 24 Jan 2022 03:51:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E43F53858435 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642996277; bh=1C0XooXmxPoak4aHZBWCjDjPyix6b4sD7vpTR8qDYcw=; 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=gXLdTO2JmvdFNPNC5WpmNHYiXGdAwuoLYAXTJ0UtX/02QqUcxLoXJ5f3LYqHIz7ca OMJu0H75pVfDXMlepNRpmFxfZSHWygdOI1ppKhz6bbc9w6focVj7eCAbvrVeO++vsP UPqctfZPO8n1kIQ/2VlbI0qqyPYSrWMbqpoj6Ql4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by sourceware.org (Postfix) with ESMTPS id 3E74F3858D3C for ; Mon, 24 Jan 2022 03:50:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3E74F3858D3C Received: by mail-pj1-x102e.google.com with SMTP id s61-20020a17090a69c300b001b4d0427ea2so19193084pjj.4 for ; Sun, 23 Jan 2022 19:50:57 -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=1C0XooXmxPoak4aHZBWCjDjPyix6b4sD7vpTR8qDYcw=; b=jUGKimpztgsZHOcOmfUxsK8o6j/HG4DjSkWErTwUAK0aeeDJE4zG9QvwkjbEORvUFB OcSU4ix2lwf8YYYA/Wt377GMp3YkGfwWLY8yIadS/GUPRn8Ddmt2FZwOhgfU4jkNfTLh hMiKWHGHMUyWXwVEpZiNXWNVmtNK/vZnFDNgrO07LNrOKzcN+hqsm+9QztCcdIzIAPGh 3ixUX9MJz3xSSC/AT8MRQgvBmaBDKNeLP5mXE7nGc2qV2TusqFLmpptlJKIe9VnwUYhn 5xGukOe/rth4eKd4q/Fu3XvUyEThG6rZLY4Q+qFXnTclaXshf5uHRxGqALji7mKvB3LK s6Bg== X-Gm-Message-State: AOAM532/+CgyqTVoO+DzOdFXBhZnYhYTwo857jTkROUwbaQYFwnXSf6Y dz+y1wU+O/S5zUf4/rkZKVKXvHOw6GE= X-Google-Smtp-Source: ABdhPJzjVM28oH6ng8RRN2ipItXTDyA+Yal3BIyZG/GfYEITimyTozBGfkLHN/KQmQmoAFp6djrNsw== X-Received: by 2002:a17:902:76cb:b0:14b:24f:cc6e with SMTP id j11-20020a17090276cb00b0014b024fcc6emr12343348plt.17.1642996256362; Sun, 23 Jan 2022 19:50:56 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:6dcd:c685:dad8:6b5b]) by smtp.gmail.com with ESMTPSA id mz23sm11701304pjb.2.2022.01.23.19.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jan 2022 19:50:55 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id E06571140025; Mon, 24 Jan 2022 14:20:52 +1030 (ACDT) Date: Mon, 24 Jan 2022 14:20:52 +1030 To: libc-alpha@sourceware.org Subject: [PATCH 3/5] [PowerPC] Relocate stinfo->main Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3037.2 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" The previous 2 patches got us to the point of segfaulting when trying to transfer to main. start_addresses in sysdeps/powerpc/powerpc64/start.S is historical baggage that should disappear. Until someone does that, relocating stinfo->main by hand is one solution to the fact that the field may be unrelocated at the time it is accessed. This is similar to what is done for dynamic tags via the D_PTR macro. The makefile change is needed to pick up elf/dl-static-tls.h from dl-machine.h. diff --git a/sysdeps/unix/sysv/linux/powerpc/Makefile b/sysdeps/unix/sysv/linux/powerpc/Makefile index fc7c29c695..93783cae00 100644 --- a/sysdeps/unix/sysv/linux/powerpc/Makefile +++ b/sysdeps/unix/sysv/linux/powerpc/Makefile @@ -27,3 +27,9 @@ tests += $(tests-static) tests += test-gettimebasefreq tests += test-powerpc-linux-sysconf endif + +ifeq ($(subdir),csu) +# to relocate stinfo->main +CPPFLAGS-libc-start.o += -I../elf +CPPFLAGS-libc-start.op += -I../elf +endif diff --git a/sysdeps/unix/sysv/linux/powerpc/libc-start.c b/sysdeps/unix/sysv/linux/powerpc/libc-start.c index bb97d16145..8f0d3a0eac 100644 --- a/sysdeps/unix/sysv/linux/powerpc/libc-start.c +++ b/sysdeps/unix/sysv/linux/powerpc/libc-start.c @@ -23,6 +23,10 @@ #ifndef SHARED #include #endif +#if ENABLE_STATIC_PIE && !defined SHARED +/* For elf_machine_load_address. */ +#include +#endif /* The main work is done in the generic function. */ #define LIBC_START_MAIN generic_start_main @@ -95,8 +99,15 @@ __libc_start_main_impl (int argc, char **argv, __tcb_parse_hwcap_and_convert_at_platform (); #endif - return generic_start_main (stinfo->main, argc, argv, auxvec, - stinfo->init, stinfo->fini, rtld_fini, + void *main = stinfo->main; +#if ENABLE_STATIC_PIE && !defined SHARED + struct link_map *map = _dl_get_dl_main_map (); + if (!map->l_relocated) + main = (char *) main + elf_machine_load_address (); +#endif + + return generic_start_main (main, argc, argv, auxvec, + NULL, NULL, rtld_fini, stack_on_entry); } DEFINE_LIBC_START_MAIN_VERSION From patchwork Mon Jan 24 03:52:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 50378 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 8C5D53858437 for ; Mon, 24 Jan 2022 03:52:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C5D53858437 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642996375; bh=O8VATgfugfTS802Y3Vn0BwC7yV9kFaZNe7JudZq7aZI=; 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=WasLLLvUA9tox9u3apUsILG5W6X/hObteX0Xrsn5wUPm2OcCVQWMHuRUaFX51xCFb lQk2xBoZLkHxdUGeV1ntHZfBVbxghmH34O9xONOxC8yNA1RJ85Uh75HY7OR0qO/zWq gxU436hv+w1NDmb0rMb3DUO3LvogXxUKuFrDKghg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 037233858C3A for ; Mon, 24 Jan 2022 03:52:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 037233858C3A Received: by mail-pf1-x436.google.com with SMTP id h5so6212059pfv.13 for ; Sun, 23 Jan 2022 19:52:34 -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=O8VATgfugfTS802Y3Vn0BwC7yV9kFaZNe7JudZq7aZI=; b=tQS0xzkyaOTKhkPewf4fJuK9ST7wF2Sjfz1jye/juiI+XLoVADwX4n+lEwJ/zzjRGn brvlL/ZXdn3Y65lTEEfg7ovv/uJzsMza+TP1pq9J6A81gzhiosCAY5V4BZmVksP5HJ0T SUord7UfwVCN+gE29wCyVlGM5ZEUmiElbULcMNGhb9TDvALdAMlJXuw/0dqjUMUS3U6+ Ori3eMA8iwtqBUbrK9KOZOuI7gpUiJedWokl5ChHA+G2TCjNKewQh+IqU8uSfpke2rJY 4XdR04o8SDDYaaShIpdhUusYVTK7zu31jxI7WVXeTkI3g1HfBgP5FZl9VcbOa147PIxL p1AA== X-Gm-Message-State: AOAM531wh4a5ZAmdw5BlH1WrF4XyrgJxzjg0OJ2ZKuZ70IMmdspjNTb1 3bkyuQJHIl8P/g2QIi/ztZm0C7k+nPk= X-Google-Smtp-Source: ABdhPJxH9UIdv4fixKSLWP9h61hA49upixNO9EDy0nD7SjiZynxpBu02FGtf46J5NWP/vOFuHqip5w== X-Received: by 2002:a63:8748:: with SMTP id i69mr10874226pge.422.1642996354173; Sun, 23 Jan 2022 19:52:34 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:6dcd:c685:dad8:6b5b]) by smtp.gmail.com with ESMTPSA id 5sm20306867pjf.34.2022.01.23.19.52.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jan 2022 19:52:33 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id EFE351142F74; Mon, 24 Jan 2022 14:22:30 +1030 (ACDT) Date: Mon, 24 Jan 2022 14:22:30 +1030 To: libc-alpha@sourceware.org Subject: [PATCH 4/5] Constify a variable in dl_vdso_vsym Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3037.2 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" Just a tidy. Compilers may decide to put the rfv variable in .data rather than on the stack. It's slightly better to put it in .data.rel.ro.local instead. Also, making it const may enable further optimisations. diff --git a/sysdeps/unix/sysv/linux/dl-vdso.h b/sysdeps/unix/sysv/linux/dl-vdso.h index bfefce8f35..8611488acc 100644 --- a/sysdeps/unix/sysv/linux/dl-vdso.h +++ b/sysdeps/unix/sysv/linux/dl-vdso.h @@ -45,7 +45,7 @@ dl_vdso_vsym (const char *name) ElfW (Sym) wsym = { 0 }; wsym.st_info = (unsigned char) ELFW (ST_INFO (STB_WEAK, STT_NOTYPE)); - struct r_found_version rfv = { VDSO_NAME, VDSO_HASH, 1, NULL }; + const struct r_found_version rfv = { VDSO_NAME, VDSO_HASH, 1, NULL }; /* Search the scope of the vdso map. */ const ElfW (Sym) *ref = &wsym; From patchwork Mon Jan 24 04:06:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 50379 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 E96313858435 for ; Mon, 24 Jan 2022 04:06:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E96313858435 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642997194; bh=UH7Lb6RnDKP7Qb4soSLReITNW6vgIMXT9g4ZTwubynM=; 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=xv9mP37jujQ/b4qQNdF10s68Fs57bq0vN28QIhRjeUVi1ic3vY4CF96ZtkCe2rZP5 qle49Cn1Fa9Uhgy6atz1vUW59HLQVwtWTXO/vl+zjNpVR/lZDWW+ZScnWQj1ulifAl bNBLqDUjTqG27NaQeXEUhFWMCgxY4UJzGwOtlYOg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by sourceware.org (Postfix) with ESMTPS id F23993858C3A for ; Mon, 24 Jan 2022 04:06:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F23993858C3A Received: by mail-pg1-x530.google.com with SMTP id j10so2026457pgc.6 for ; Sun, 23 Jan 2022 20:06:10 -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=UH7Lb6RnDKP7Qb4soSLReITNW6vgIMXT9g4ZTwubynM=; b=5cFKdsK8qx5vnigc1Wh6NQL3QtaY6DMDsvYqJTXcIHrxvkocKihNPsNtjrU9w4pEgo doZhItfm6hqKyzfEEnt4AQIlxsXT7hxhtvlmu6a2JxaR6pipgqoE9OkzJ42hwXAD10Lz WzyfeQOxWQrTwnKttjORnygpyrrkBKOMfJp8JW+PjI8PEmYDXBkzHWpDR0pm7xHRNIZ5 4WOtd+KvBOJtZpsfBpOj/n7qFQK88gxfk+yxiGBImUm/fS+V192ZQa4Kj7QPrmMDLKfs xP0K6VlYcmigpTrbAX3710QKeSDtevPQOP+3Y6aqOoJM2ynshmaJ23PzMEZs/z5ty5Aq 8apw== X-Gm-Message-State: AOAM530I21nMAcvZXHBTWwQYsO0zu0rGZQrU2lvhaEO6JtyaBTP++ZSm CL4Sg2gHyzF0kd55ckGrv1BEr050DW8= X-Google-Smtp-Source: ABdhPJxtED13Deqim4x/UDGI4ynL4qruTla0Pm+6dK+8aYkdfRXrPIk/c4z3kmtL1UbMrvOh4yVe7g== X-Received: by 2002:a63:8448:: with SMTP id k69mr10598946pgd.565.1642997170164; Sun, 23 Jan 2022 20:06:10 -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 x25sm13731274pfu.91.2022.01.23.20.06.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jan 2022 20:06:09 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id C54C21140025; Mon, 24 Jan 2022 14:36:06 +1030 (ACDT) Date: Mon, 24 Jan 2022 14:36:06 +1030 To: libc-alpha@sourceware.org Subject: [PATCH 5/5] Enable static-pie on powerpc64 Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3037.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, 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" Also regenerate another powerpc configure file that wasn't done when making the corresponding configure.ac change. With this series and latest gcc + binutils I get mostly working static-pie on powerpc64le-linux. There are a number of regressions: FAIL: elf/tst-glibc-hwcaps-cache FAIL: elf/tst-glibc-hwcaps-prepend-cache FAIL: elf/tst-ldconfig-bad-aux-cache FAIL: elf/tst-ldconfig-ld_so_conf-update FAIL: elf/tst-tlsifunc-static * sysdeps/powerpc/powerpc64/configure.ac (SUPPORT_STATIC_PIE): Define. (PI_STATIC_AND_HIDDEN): Define. * sysdeps/powerpc/powerpc64/configure: Regenerate. * sysdeps/unix/sysv/linux/powerpc/configure: Regenerate. diff --git a/sysdeps/powerpc/powerpc64/configure b/sysdeps/powerpc/powerpc64/configure index fddea0355a..4a219ab8ac 100644 --- a/sysdeps/powerpc/powerpc64/configure +++ b/sysdeps/powerpc/powerpc64/configure @@ -1,6 +1,13 @@ # This file is generated from configure.ac by Autoconf. DO NOT EDIT! # Local configure fragment for sysdeps/powerpc/powerpc64. +$as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h + + +# Static PIE is supported. +$as_echo "#define SUPPORT_STATIC_PIE 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for support for overlapping .opd entries" >&5 $as_echo_n "checking for support for overlapping .opd entries... " >&6; } if ${libc_cv_overlapping_opd+:} false; then : diff --git a/sysdeps/powerpc/powerpc64/configure.ac b/sysdeps/powerpc/powerpc64/configure.ac index 1f3d54414c..5eedd2f81c 100644 --- a/sysdeps/powerpc/powerpc64/configure.ac +++ b/sysdeps/powerpc/powerpc64/configure.ac @@ -1,6 +1,13 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory. # Local configure fragment for sysdeps/powerpc/powerpc64. +dnl It is always possible to access static and hidden symbols in an +dnl position independent way. +AC_DEFINE(PI_STATIC_AND_HIDDEN) + +# Static PIE is supported. +AC_DEFINE(SUPPORT_STATIC_PIE) + AC_CACHE_CHECK(for support for overlapping .opd entries, libc_cv_overlapping_opd, [dnl libc_cv_overlapping_opd=no diff --git a/sysdeps/unix/sysv/linux/powerpc/configure b/sysdeps/unix/sysv/linux/powerpc/configure index a4c809fd98..7183573bc0 100644 --- a/sysdeps/unix/sysv/linux/powerpc/configure +++ b/sysdeps/unix/sysv/linux/powerpc/configure @@ -93,7 +93,13 @@ EOF $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; } then - libc_linker_feature=yes + if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp -Wl,--no-tls-get-addr-optimize -nostdlib \ + -nostartfiles -fPIC -shared -o conftest.so conftest.c 2>&1 \ + | grep "warning: --no-tls-get-addr-optimize ignored" > /dev/null 2>&1; then + true + else + libc_linker_feature=yes + fi fi rm -f conftest* fi