From patchwork Mon Feb 28 06:40:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 51419 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 955053858414 for ; Mon, 28 Feb 2022 06:42:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 955053858414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1646030562; bh=3/cVKz/wRhxlIkf9kiCzKeLbBxlwFYhLlCKLCVy+JSc=; 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=OPBpMNU++NJatBNGYOJHuPi7HHsgwYgh6goFlxSqLNu+TIWyeKqEMTqpXseAIcAG8 kpnBXq33MOmPuR+1oIV7nqAg0BYPnEaUaaM2ZzOEF1X0Ks4yuYZSR+0TGcIVMMETMQ MQfxBFwrht6VAtdND+sRIal5A0g8helB1tmMKXqI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 9B7D23858C60 for ; Mon, 28 Feb 2022 06:41:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9B7D23858C60 Received: by mail-pl1-x631.google.com with SMTP id z2so9865860plg.8 for ; Sun, 27 Feb 2022 22:41:39 -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=3/cVKz/wRhxlIkf9kiCzKeLbBxlwFYhLlCKLCVy+JSc=; b=tMVF6ZKosj+lYB+HnYXZyJSrep729ESVp8WAaJsp+ozjxBfVCp4WInSSfLGzoICfRg 7EnLf3CW4l8zuGzZImSbIfLirAgM7embmZrw8MPB/7ffa4mZfiR6nBzyGCdes59SlEke 5arRWC8+T3ZcXjQB3fSoBByjyMYIEzOwOeIYADUCpOpH0dK5t9/ItD4HMpeJmMFWdWmK wuLiMcAAIIvP3gmw+PIf/WNSMVobNlz2BO3orVP15kbiViC6DUe3dSSKSve615wNrcYE 3HkP8Wiy0vEIcdf5TNgUqefbgttoV6YlIf7HfGNEJv8kjd7zSIqgrhvErTA2bSEvffg6 Kk1g== X-Gm-Message-State: AOAM530nLkfXE99YNAwIVuFP2LXewWCouvUoUGHVBf73A1sCYhlH0R3I hbZVXyuU9Knhc4JSzouVe8fxqooAPFY= X-Google-Smtp-Source: ABdhPJzW4b3s/mBcIJ203ijJWN42wt5u6Ch8ZIKOAI/kVeVHfw8to5a5ZwIPe/xbWlRTjOC3lwXm6A== X-Received: by 2002:a17:902:d643:b0:151:6f2c:cfb4 with SMTP id y3-20020a170902d64300b001516f2ccfb4mr1441511plh.120.1646030498301; Sun, 27 Feb 2022 22:41:38 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 22:41:37 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v2 1/4] powerpc64: Use medium model toc accesses throughout Date: Mon, 28 Feb 2022 17:10:49 +1030 Message-Id: <20220228064052.3413334-2-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.3 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, 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" 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 in isolation 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. A followup patch will fix that. Reviewed-by: Tulio Magno Quites Machado Filho 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 5da5de7a0a..6fab5cbe81 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 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"); From patchwork Mon Feb 28 06:40:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 51421 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 A06343858434 for ; Mon, 28 Feb 2022 06:44:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A06343858434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1646030646; bh=5cVFRMeJt1caFkOpQHebhUyKRE38nCtKWvxc/gPYdjU=; 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=TdDvM/aL/27CIRyIwxawe1HH98ndhm5hJQH9TrXpqa9Wn0fUIt22WRblDW6aZS1mQ SRXGQE0XdnXdZKVR5UtMP4Xdze5m4vYEJM94+isAwuuu8Nf/NqwkR/08Eos9t426ui 1GT/5uhngRPIqVj+dLVNrH9sZ7nHNKpRCfs+VpuA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id BD79C3858430 for ; Mon, 28 Feb 2022 06:41:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BD79C3858430 Received: by mail-pf1-x42f.google.com with SMTP id i21so10184834pfd.13 for ; Sun, 27 Feb 2022 22:41:44 -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=5cVFRMeJt1caFkOpQHebhUyKRE38nCtKWvxc/gPYdjU=; b=S5RtHjm1QASsMOxEkXKWfau15PSCmHm1UzfYRUMXNsHTFeOVYYnEQbGwe0R6ht+Jum HXUxU1YYS8OYVnkWnUGOyg1zqdZZt3lwal11Egpx/md3fDsElBh9TRsW2bfqPK1xp/wZ JqAzdX/OpMZ3giDsg5DXXuHab9wwhdWonkcD697nne1uMatFIRZO3JR1lQocUeMO29cZ mo4b6ZCd3RzepQtt/KadIRFPbKE4fwCUjC6rNeinKuNvziKyQ3D7+SH4gwnYy3TV4oAH aZn6RMC4UWyIX0Vi50j+x86V3B0sJcgsztnMDVgnDR6/Wl3SJYzRDfigC8KvJMiZRWGO dhJg== X-Gm-Message-State: AOAM532E6xun0K7AgKlJ8YZYL72fD1nwdVdjx85LHeZVMHh+w9478Gqo Sv6sIJq59yWQ2cYYV2AwFbldDxOGVbU= X-Google-Smtp-Source: ABdhPJx67g+AXYOogHIxWDd+fvkRU3OqDDNHkKi1kaDXwnf+fT4fWU2vzS8k0TJP12x+ZAMSpJZ7DA== X-Received: by 2002:a05:6a00:1310:b0:4ca:cc46:20c7 with SMTP id j16-20020a056a00131000b004cacc4620c7mr19893250pfu.44.1646030503599; Sun, 27 Feb 2022 22:41:43 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 22:41:42 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v2 3/4] powerpc: Relocate stinfo->main Date: Mon, 28 Feb 2022 17:10:51 +1030 Message-Id: <20220228064052.3413334-4-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.6 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, 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" 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. stinfo->init and stinfo->fini are zero in both powerpc64/start.S and powerpc32/start.S, so make it a little more obvious they are unused by passing NULLs to LIBC_START_MAIN. The makefile change is needed to pick up elf/dl-static-tls.h from dl-machine.h. Reviewed-by: Tulio Magno Quites Machado Filho 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 Feb 28 06:40: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: 51422 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 8B93E3858414 for ; Mon, 28 Feb 2022 06:44:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B93E3858414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1646030688; bh=YqRzKS4KZ7n6sqhzqkgFnrZNKtXkVyKicQdB4YRL19I=; 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=SrmrASOFUwUIN6xh5lLDaKZBOY2rkJrH8WyIPISPxsk1+MUH94eqjeO6HP3c87HVm +pn8yCAtKbI8XgThLlroOP6VKTEdzFXPIWtYKC9nbAA0StmEgoPN5lF8agljeq9JrD 8q3uk897cYE4yyf4U2imp9P16nllA4xPhpECODr4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by sourceware.org (Postfix) with ESMTPS id 8E3933858424 for ; Mon, 28 Feb 2022 06:41:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8E3933858424 Received: by mail-pj1-x102d.google.com with SMTP id h17-20020a17090acf1100b001bc68ecce4aso13914054pju.4 for ; Sun, 27 Feb 2022 22:41:47 -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=YqRzKS4KZ7n6sqhzqkgFnrZNKtXkVyKicQdB4YRL19I=; b=m0Nu0j6jk/0a7ZPPTyAKyLZl4pE6ZXuoMsTbSFb0zJtJv0AjAnMuaylWO83hrJ88wL Zmv+QSuoc2hPta/mCMx8Ew9G7RmFGXpmmv7o0r37nnwj5QljsP/bEGRvGM8fGYrfwCql aIpyeq1+kwd7HDv37YHBorY/FsYCoZJyKZ04JTwvGvCnlbfsoKn8zBLk7+g10Iw8KhNo 0z5V137a9oWrZNszgC3Ele5xRsxg0T3R2tGJBgktAiCVa021c6Vdr7HXKasYuO43dgJL xg6V028Pa9RMlL+EO/NCqI9DtDq8m2UtkcsQI+2PkmX9/erLVi4ZoTfojUtelnMt9IlU kgNw== X-Gm-Message-State: AOAM531EZfTcsfkvfSKemmvhNl9l6DMksn0k3NASk2DpkutYBas17Cmb DPH0ni6zFgaHEHfOHOyMaseXHmFWjSM= X-Google-Smtp-Source: ABdhPJw5cDeUBwO+k3WonTgauOC6uwFycGWnHT0sPkTa/9yF4V57QHvcGbQWx9dOKAIKoBEvp2Yuig== X-Received: by 2002:a17:902:b607:b0:14d:c39c:a37 with SMTP id b7-20020a170902b60700b0014dc39c0a37mr19136307pls.84.1646030506331; Sun, 27 Feb 2022 22:41:46 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 22:41:45 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v2 4/4] powerpc64: Enable static-pie Date: Mon, 28 Feb 2022 17:10:52 +1030 Message-Id: <20220228064052.3413334-5-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.7 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, 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" * sysdeps/powerpc/powerpc64/configure.ac (SUPPORT_STATIC_PIE): Define. (PI_STATIC_AND_HIDDEN): Define. * sysdeps/powerpc/powerpc64/configure: Regenerate. diff --git a/sysdeps/powerpc/powerpc64/configure b/sysdeps/powerpc/powerpc64/configure index fddea0355a..f19dd5578e 100644 --- a/sysdeps/powerpc/powerpc64/configure +++ b/sysdeps/powerpc/powerpc64/configure @@ -1,6 +1,12 @@ # 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 + + +$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..7764a65822 100644 --- a/sysdeps/powerpc/powerpc64/configure.ac +++ b/sysdeps/powerpc/powerpc64/configure.ac @@ -1,6 +1,15 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory. # Local configure fragment for sysdeps/powerpc/powerpc64. +dnl It is possible to access static and hidden symbols in a position +dnl independent way requiring no relocation on powerpc64. The linker +dnl edits medium and large model code that uses GOT/TOC entries (which +dnl would require relocation) to r2 relative accesses. +AC_DEFINE(PI_STATIC_AND_HIDDEN) + +dnl 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