From patchwork Fri Sep 9 18:30:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 1676174 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=uclibc-ng.org (client-ip=89.238.66.15; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=G273kB13; dkim-atps=neutral Received: from helium.openadk.org (helium.openadk.org [89.238.66.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MPPhN4ZZ3z1yp6 for ; Sat, 10 Sep 2022 04:31:14 +1000 (AEST) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id DA45631E071C; Fri, 9 Sep 2022 20:31:03 +0200 (CEST) Authentication-Results: helium.openadk.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=G273kB13; dkim-atps=neutral Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by helium.openadk.org (Postfix) with ESMTPS id 5F54E31E00B1 for ; Fri, 9 Sep 2022 20:30:32 +0200 (CEST) Received: by mail-pj1-f47.google.com with SMTP id m3so2295331pjo.1 for ; Fri, 09 Sep 2022 11:30:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=T6676fnNaieLz/rQHHsXlBg4/IxLH4SKe2dNe3rHc1g=; b=G273kB13ddnN7Am2cwAHhPjiFj7V0iHZEvDp0hMeyzrfvnaV/f2EQqkxyqRqVNtCwN qYsNowN57UFUxuQY0nl/1Pe3rO6t7kHLLktj4S/SaF+MbOTx+TnfGqvsF4NjlElv7R+I /hI1Ti+dn7HLDzuXOfZBro1/qH5XgcD6onateVqKoV6DH3EWIt39zIU6QZloa5R87cla lvWRV9+b/bQy2RSbiQ2DojgSi55mxl+DvxqJChs8sWrXjTFNYFRyUC2wMnRhDMKObD5I ghprd/jc3BbNE4riNkDiUYPPNOEYhfSv+wl9uH/9y4cM0CJ3JNrbLP4ompUZstW7F6o5 m7QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=T6676fnNaieLz/rQHHsXlBg4/IxLH4SKe2dNe3rHc1g=; b=Af9jUdeM0QhALJnRZyhbdgGTaajMosJzRHQ8u8UFe9BzwsP+LsCNMWBR1dsotggOKC GW6XUWMTDn0eW7sCtKUC6rnYZmYwjyUpmDXE/1JNwCD7XMe0u/SrZY63P1F/S6xjbGZj oB07CAUoqbxwb+u8/W1deuC8T0Ai+GgaP8rY8wA1UwBatdgDTUQmDtSN6uNHIJr4zAt7 k+ucE7UVceHTsXWDXGm93Il4l8WcamUSczX1oHc936TydRSTohAH4EcWf3uQqGboO7jB 5NDhWK9nNcSYSa4S0Ns4KmrgbhXjMwnbYvH4R17eoNFjiom9cp1cVXptwxj8mZYPxcZc ItGQ== X-Gm-Message-State: ACgBeo0dBNRHrwFIuplKO8mZJrtoxh3MEQBPZrg9/PM1U7kJD1wWQBMC fRQP0W68rh1sd3GHxK09qKBbFM+a7mETQg== X-Google-Smtp-Source: AA6agR7QN4cxFtpzo26l1lztb4ZpjCb7KjTnPy/Utt0bM/TJUvoUh8iEtkvXt6iNWYkdSwMzypELGQ== X-Received: by 2002:a17:902:ce81:b0:172:9ac1:6ee with SMTP id f1-20020a170902ce8100b001729ac106eemr14640865plg.93.1662748230152; Fri, 09 Sep 2022 11:30:30 -0700 (PDT) Received: from octofox.metropolis (c-24-130-93-68.hsd1.ca.comcast.net. [24.130.93.68]) by smtp.gmail.com with ESMTPSA id q6-20020a170902dac600b00174a4bcefc7sm755709plx.217.2022.09.09.11.30.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 11:30:29 -0700 (PDT) From: Max Filippov To: devel@uclibc-ng.org Date: Fri, 9 Sep 2022 11:30:05 -0700 Message-Id: <20220909183009.4111393-2-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220909183009.4111393-1-jcmvbkbc@gmail.com> References: <20220909183009.4111393-1-jcmvbkbc@gmail.com> MIME-Version: 1.0 Message-ID-Hash: HL77OI7GT223LRAWTT3LAW37JJUIGDK7 X-Message-ID-Hash: HL77OI7GT223LRAWTT3LAW37JJUIGDK7 X-MailFrom: jcmvbkbc@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: linted X-Mailman-Version: 3.3.3 Precedence: list Subject: [uclibc-ng-devel] [PATCH 1/5] static pie: fix building static PDE List-Id: uClibc-ng Development Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: When uclibc is built with static PIE support the _dl_load_base variable shared between the libc-tls.c and reloc_static_pie.c creates the dependency that requires linking reloc_static_pie.o into static position-dependent executables resulting in the following build errors: gcc -static test.c -o test ...ld: ...usr/lib/libc.a(reloc_static_pie.os):(.text+0x0): undefined reference to `_DYNAMIC' Move _dl_load_base definition to libc-tls.c to resolve this dependency and fix static PDE build. Signed-off-by: Max Filippov --- libc/misc/internals/reloc_static_pie.c | 4 ++-- libpthread/nptl/sysdeps/generic/libc-tls.c | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libc/misc/internals/reloc_static_pie.c b/libc/misc/internals/reloc_static_pie.c index c0027de6fe06..ce42cb9b30df 100644 --- a/libc/misc/internals/reloc_static_pie.c +++ b/libc/misc/internals/reloc_static_pie.c @@ -25,7 +25,7 @@ #include #endif -ElfW(Addr) _dl_load_base = NULL; +extern ElfW(Addr) _dl_load_base; void reloc_static_pie (ElfW(Addr) load_addr); @@ -107,4 +107,4 @@ reloc_static_pie(ElfW(Addr) load_addr) #endif } _dl_load_base = load_addr; -} \ No newline at end of file +} diff --git a/libpthread/nptl/sysdeps/generic/libc-tls.c b/libpthread/nptl/sysdeps/generic/libc-tls.c index 54f3cb0c72b5..7cfe9ac1a85c 100644 --- a/libpthread/nptl/sysdeps/generic/libc-tls.c +++ b/libpthread/nptl/sysdeps/generic/libc-tls.c @@ -117,6 +117,10 @@ init_static_tls (size_t memsz, size_t align) GL(dl_tls_static_nelem) = GL(dl_tls_max_dtv_idx); } +#if !defined(__FDPIC__) && !defined(SHARED) && defined(STATIC_PIE) +ElfW(Addr) _dl_load_base; +#endif + void __libc_setup_tls (size_t tcbsize, size_t tcbalign); void __libc_setup_tls (size_t tcbsize, size_t tcbalign) @@ -143,8 +147,7 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign) #else initimage = (void *) phdr->p_vaddr; #if !defined(SHARED) && defined(STATIC_PIE) - extern ElfW(Addr) _dl_load_base; - initimage += _dl_load_base; + initimage += _dl_load_base; #endif #endif align = phdr->p_align; From patchwork Fri Sep 9 18:30:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 1676176 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=uclibc-ng.org (client-ip=89.238.66.15; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=bFqmndIk; dkim-atps=neutral Received: from helium.openadk.org (helium.openadk.org [89.238.66.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MPPkR6Rw3z1yj1 for ; Sat, 10 Sep 2022 04:33:01 +1000 (AEST) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id 0B16431E051F; Fri, 9 Sep 2022 20:32:54 +0200 (CEST) Authentication-Results: helium.openadk.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=bFqmndIk; dkim-atps=neutral Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by helium.openadk.org (Postfix) with ESMTPS id 7E79F31E00B1 for ; Fri, 9 Sep 2022 20:30:34 +0200 (CEST) Received: by mail-pj1-f54.google.com with SMTP id q3so2279957pjg.3 for ; Fri, 09 Sep 2022 11:30:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=Wn1DfmB4dKFVJq0WDCkFFKvZhzz5WuPYdauvryzCsc8=; b=bFqmndIklvTiIRPejVUi/tkZJ0/2gk/VR8mI/GN+b38oV5RtRBOS1zkR0pFpwopZnR 3dqMRoLMMAIVlvtvB+dKRUSd1ld3A7CGMoDvXatamRHe1EX8bAJG1/bD0FOoA1krT9Ja lVVZ3mQ8vWRKxZ0GjQzqRRUUeZpPZ8yatn7qqaBQSIsc8v5uZLOtC5V/sVLgkwt7ZHqN 6/GHbihSBP1kzHeudWr2hDaarRv2tT3DQdGbkOJK40weR069MkIPr1GA2FYRZ0zlXEz6 WignpB+7N7gSbzHSwTBvTw7FyDPEAX5/UAbmPz4NAU5eEMM4MmwrJzADJyU2YG/A30xC zSdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=Wn1DfmB4dKFVJq0WDCkFFKvZhzz5WuPYdauvryzCsc8=; b=ZgnB5q4hLHIFOtGahtBomGao2KxKg80NIIKFdLaovZEPNEmQcv/xFIhcV/RlpjcetW LXmWgCI6CFi8IxyUOyos7diXYhrp85j7mZVGRcfxDm2qhA3Cyt49az7+x7KTNJqUPOum QD152qCJ/iaelTnUzpkFRc0s6NS3bVh0X+hUsfHBDKh28tV3Eue2Jz3Ad70FhfapK2us KucPYQF7AHWdDQoxe+5sWbVdIq7gdtJb+1401tbyWoI5gX2aiSsq46h2lnAL0g2DjvgE XXWzyzR33A0x1pLDkrGIdns9ybvZnPUWQI12e2FeEJZ1X6FJACnz7DTILAvlVkhbTmBT ItwA== X-Gm-Message-State: ACgBeo34IknMMRloh72RyyKUp8ZAkdV4tL2TdzWu+HGoBePYRImNyxO4 MFbsOub0y8dvHYXqef1/EBQAq+1XPFkaeQ== X-Google-Smtp-Source: AA6agR7olmfI1PGbUdZnqgQuQPqSlJ2LvA8sEPWO1pthWh+N0If8uywxhjFFELsUdw5qo8xahC8ETg== X-Received: by 2002:a17:90a:7e08:b0:200:7cd8:32f6 with SMTP id i8-20020a17090a7e0800b002007cd832f6mr10850495pjl.96.1662748232506; Fri, 09 Sep 2022 11:30:32 -0700 (PDT) Received: from octofox.metropolis (c-24-130-93-68.hsd1.ca.comcast.net. [24.130.93.68]) by smtp.gmail.com with ESMTPSA id q6-20020a170902dac600b00174a4bcefc7sm755709plx.217.2022.09.09.11.30.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 11:30:32 -0700 (PDT) From: Max Filippov To: devel@uclibc-ng.org Date: Fri, 9 Sep 2022 11:30:06 -0700 Message-Id: <20220909183009.4111393-3-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220909183009.4111393-1-jcmvbkbc@gmail.com> References: <20220909183009.4111393-1-jcmvbkbc@gmail.com> MIME-Version: 1.0 Message-ID-Hash: 6OQ6BTTCZEXXKFAVQNNDJHQLVOBBT7FX X-Message-ID-Hash: 6OQ6BTTCZEXXKFAVQNNDJHQLVOBBT7FX X-MailFrom: jcmvbkbc@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: linted X-Mailman-Version: 3.3.3 Precedence: list Subject: [uclibc-ng-devel] [PATCH 2/5] static pie: replicate PERFORM_BOOTSTRAP_GOT conditions from dl-startup.c List-Id: uClibc-ng Development Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Code in reloc_static_pie.c is largely based on DL_START function from dl-startup.c, but it's missing the condition that disables the rest of relocation when PERFORM_BOOTSTRAP_GOT macro is defined. As a result when building reloc_static_pie.c for xtensa it applies relative relocations twice. Replicate PERFORM_BOOTSTRAP_GOT conditions from dl-startup.c in reloc_static_pie.c to allow using PERFORM_BOOTSTRAP_GOT macro as is. Signed-off-by: Max Filippov --- libc/misc/internals/reloc_static_pie.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libc/misc/internals/reloc_static_pie.c b/libc/misc/internals/reloc_static_pie.c index ce42cb9b30df..9f5366cc6ab7 100644 --- a/libc/misc/internals/reloc_static_pie.c +++ b/libc/misc/internals/reloc_static_pie.c @@ -54,6 +54,8 @@ reloc_static_pie(ElfW(Addr) load_addr) #endif +#if !defined(PERFORM_BOOTSTRAP_GOT) || defined(__avr32__) || defined(__mips__) + #if defined(ELF_MACHINE_PLTREL_OVERLAP) # define INDX_MAX 1 #else @@ -106,5 +108,6 @@ reloc_static_pie(ElfW(Addr) load_addr) } #endif } +#endif _dl_load_base = load_addr; } From patchwork Fri Sep 9 18:30:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 1676177 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=uclibc-ng.org (client-ip=2a00:1828:2000:679::23; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=VQWNAY3k; dkim-atps=neutral Received: from helium.openadk.org (helium.openadk.org [IPv6:2a00:1828:2000:679::23]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MPPkh56nSz1yj1 for ; Sat, 10 Sep 2022 04:33:16 +1000 (AEST) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id 9322531E071E; Fri, 9 Sep 2022 20:32:56 +0200 (CEST) Authentication-Results: helium.openadk.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=VQWNAY3k; dkim-atps=neutral Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by helium.openadk.org (Postfix) with ESMTPS id 940C031E00B1 for ; Fri, 9 Sep 2022 20:30:37 +0200 (CEST) Received: by mail-pj1-f47.google.com with SMTP id j6-20020a17090a694600b00200bba67dadso2410226pjm.5 for ; Fri, 09 Sep 2022 11:30:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=MZ+iGpMYPn/8L8Wi+d2WEKkIJ/fBrhj+wb7mduEmlOs=; b=VQWNAY3koYPiJBRruY08V3WbCQg3L2ayQc7yYpFBpshzG25p3StcIcCYJCT9FM2CvC 1a/Ew03piLlJQHD195HoilC89F/fCOhiyjYPFl+ONdy0iT2g7S+yXRWiig3yYIfblgDi u4lzQy8Wf6wQ64N0naKcXXulLfUouQlPlrWuvyBSHHR1TpxeyXMi05KdIOwiPzf3/TXk MG+Wt9mXXO/lUcXYN9p6/ge/375vqAJUB15FF46Qylr/j3tRqC7sHL3RXJR0jrCL7KDw 1NgnZhvbfqInJ/Os09Ze0GYtgwJIgbs9zlg1CSRNE6I6TFkQkFCm3+QM+qRakhrlEwml x8VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=MZ+iGpMYPn/8L8Wi+d2WEKkIJ/fBrhj+wb7mduEmlOs=; b=berpDJCMl0KYRvxKq6KFqZ6ygKKeqLsIMK9FZdrBu0xrH5jq1coPS8KzljwazCEYuJ 7PTbcEfe7KvRLI+ISkS+MUEdhpqydeM1RZsXrCqTF8fI9iEiZSG6rAoRqjmfgOouJ+EW mZcIbCAWUy+uTBQ2p5pVXZ23jPgj/VgOQ5fqMk4V3/7GH+bSgeRjvTl4gOe7SzMNx0Gv JxLDdAghdiQWl02Str2t/vzt9wlnZ0nTaVB0ZWh8o4a0nXOS+cDuNPClrVAYYBmQKv1h XXzEcgVZZTp3DgaN5pqEPSNZCLOWuO43wqqH59CnmW/Us4GcLYw6TRuU+IHQshOJ4IHW kmkQ== X-Gm-Message-State: ACgBeo2uxhLrSPEoQDssFKTCtSHwKMwxQ6m0d6zBvk1NLJ/9vJrGLt1Z mvDycRx7WmFomjHE6o506L5Kq6YFmzYCgw== X-Google-Smtp-Source: AA6agR5hNW/EwucEd5MNxTTNiBGNM4jciZAHfAjK1ajT3y5yBffzLouSthbbnV0qvTkWVdn71SB7dQ== X-Received: by 2002:a17:90b:1e0d:b0:202:91ec:e167 with SMTP id pg13-20020a17090b1e0d00b0020291ece167mr3165148pjb.174.1662748235052; Fri, 09 Sep 2022 11:30:35 -0700 (PDT) Received: from octofox.metropolis (c-24-130-93-68.hsd1.ca.comcast.net. [24.130.93.68]) by smtp.gmail.com with ESMTPSA id q6-20020a170902dac600b00174a4bcefc7sm755709plx.217.2022.09.09.11.30.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 11:30:34 -0700 (PDT) From: Max Filippov To: devel@uclibc-ng.org Date: Fri, 9 Sep 2022 11:30:07 -0700 Message-Id: <20220909183009.4111393-4-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220909183009.4111393-1-jcmvbkbc@gmail.com> References: <20220909183009.4111393-1-jcmvbkbc@gmail.com> MIME-Version: 1.0 Message-ID-Hash: WBW7S5S6HMD3VXQDDDJCH2QSKPU2WXLB X-Message-ID-Hash: WBW7S5S6HMD3VXQDDDJCH2QSKPU2WXLB X-MailFrom: jcmvbkbc@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: linted X-Mailman-Version: 3.3.3 Precedence: list Subject: [uclibc-ng-devel] [PATCH 3/5] xtensa: make GOT protection adjustment conditional List-Id: uClibc-ng Development Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Xtensa PERFORM_BOOTSTRAP_GOT macro uses mprotect to make bits of GOT writable, but noMMU linux kernel returns ENOSYS to mprotect syscalls, and syscall wrapper tries to update errno with the error code. This happens well before the relocations are done and results in writes to unrelated locations, memory corruption or protection violations. Split GOT protection update from PERFORM_BOOTSTRAP_GOT and only do it when building configuration with MMU support. Signed-off-by: Max Filippov --- ldso/ldso/xtensa/dl-startup.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ldso/ldso/xtensa/dl-startup.h b/ldso/ldso/xtensa/dl-startup.h index db223feadc90..19955ffc77a5 100644 --- a/ldso/ldso/xtensa/dl-startup.h +++ b/ldso/ldso/xtensa/dl-startup.h @@ -88,12 +88,11 @@ __asm__ ( /* Function calls are not safe until the GOT relocations have been done. */ #define NO_FUNCS_BEFORE_BOOTSTRAP -#define PERFORM_BOOTSTRAP_GOT(tpnt) \ +#if defined(__ARCH_USE_MMU__) +#define PERFORM_BOOTSTRAP_GOT_ADJUST_PROTECTION(tpnt) \ do { \ xtensa_got_location *got_loc; \ unsigned long l_addr = tpnt->loadaddr; \ - Elf32_Word relative_count; \ - unsigned long rel_addr; \ Elf32_Addr prev_got_start = 0, prev_got_end = 0; \ int x; \ \ @@ -125,7 +124,19 @@ do { \ prev_got_end - prev_got_start, \ PROT_READ | PROT_WRITE | PROT_EXEC); \ } \ +} while (0) +#else +#define PERFORM_BOOTSTRAP_GOT_ADJUST_PROTECTION(tpnt) \ +do { \ +} while (0) +#endif + +#define PERFORM_BOOTSTRAP_GOT(tpnt) \ +do { \ + Elf32_Word relative_count; \ + unsigned long rel_addr; \ \ + PERFORM_BOOTSTRAP_GOT_ADJUST_PROTECTION(tpnt); \ /* The following is a stripped down version of the code following \ the invocation of PERFORM_BOOTSTRAP_GOT in dl-startup.c. That \ code is skipped when PERFORM_BOOTSTRAP_GOT is defined, so it has \ From patchwork Fri Sep 9 18:30:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 1676178 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=uclibc-ng.org (client-ip=89.238.66.15; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=QK0c/uQh; dkim-atps=neutral Received: from helium.openadk.org (helium.openadk.org [89.238.66.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MPPkm0fQ4z1yp6 for ; Sat, 10 Sep 2022 04:33:17 +1000 (AEST) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id C6B5131E0723; Fri, 9 Sep 2022 20:32:58 +0200 (CEST) Authentication-Results: helium.openadk.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=QK0c/uQh; dkim-atps=neutral Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by helium.openadk.org (Postfix) with ESMTPS id C254531E00B1 for ; Fri, 9 Sep 2022 20:30:39 +0200 (CEST) Received: by mail-pj1-f53.google.com with SMTP id m10-20020a17090a730a00b001fa986fd8eeso6179003pjk.0 for ; Fri, 09 Sep 2022 11:30:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=7ditwgW1A6dvlChrdddIDxMXdoCzcx19lr5A9pzZ6JU=; b=QK0c/uQh0Qc6xBPMgrIYDCnLqDdvZODl5qPHBEJYI7skVvxsxgXhw4zMb4swkcwTfF 0rvSc5+Ci6QlDY0P8WRHezJmTXqyXqSXID9KGU6YRHO74KdpAgkWYj73nbR6bIYmkBht i/Q68F1L3h+HQPJgfdfu3hKK6/EXN0gEXJMwl3i77VBqdAM3Oxyn20/qHFNKbBa0GR6H kCFdNodJqsZifE7rrcTFF3fEWwiSAUm5B9Tuqi9Amn6Lhsci4uOu5hZ6y3rPgMkCzCYn pM/lwFT9f8wGQ679J3PnTazxfBoZA+pZSa6AN1oOOfjA0PzlAskScX0AXpdyUMVB1vCq io0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=7ditwgW1A6dvlChrdddIDxMXdoCzcx19lr5A9pzZ6JU=; b=aaIprwi6RhxUykBxqTx9pGPht3mPl/OZs1SB+h12Mn7ZE+XDby5uU2YS39lR12kNYD 3rFEt/5bx1YgYFUevJLGF0ae+c6SQGMfOaVuNLqbuBogy2nPAhFrzm41jg8W6XhnZSvb /UfEbbCK/hRXeWAH2CewN6QUMOfXDANtPUCiec7uwt7GYaZ4aBJnw+UJJaWXJgaB9xGn VJUIpRk0sOZvfLpaXId3IIqIfNh/fStp/7yxXzY38Q+qShHhogWuKp0Z/49w2gxkQfwe XPMENxfnWgNzI+7epkeQGovjibcBl61SNBm3cPqAYda9V325oPo53cKCjbz0nFrtlriZ Ufiw== X-Gm-Message-State: ACgBeo1LnutznBtbygI/NGWJw35MuVrbPe2BMvFpMwshwk9xAUbLu/uX aS1YHhQL70eHPl7FsAvVi3ohBJEurWR7uQ== X-Google-Smtp-Source: AA6agR5iJN3mVfc1UPzwjqV3VTkAoKZgQSv4J5ROcs0UtUEMomCUcK4riQrn6nroiysRSoDAV6hZlg== X-Received: by 2002:a17:90a:d14d:b0:1fa:f740:4aa5 with SMTP id t13-20020a17090ad14d00b001faf7404aa5mr10743857pjw.21.1662748237600; Fri, 09 Sep 2022 11:30:37 -0700 (PDT) Received: from octofox.metropolis (c-24-130-93-68.hsd1.ca.comcast.net. [24.130.93.68]) by smtp.gmail.com with ESMTPSA id q6-20020a170902dac600b00174a4bcefc7sm755709plx.217.2022.09.09.11.30.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 11:30:37 -0700 (PDT) From: Max Filippov To: devel@uclibc-ng.org Date: Fri, 9 Sep 2022 11:30:08 -0700 Message-Id: <20220909183009.4111393-5-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220909183009.4111393-1-jcmvbkbc@gmail.com> References: <20220909183009.4111393-1-jcmvbkbc@gmail.com> MIME-Version: 1.0 Message-ID-Hash: CIQ6OMSPDSUFGELW36PURODVXSAMEC3O X-Message-ID-Hash: CIQ6OMSPDSUFGELW36PURODVXSAMEC3O X-MailFrom: jcmvbkbc@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: linted X-Mailman-Version: 3.3.3 Precedence: list Subject: [uclibc-ng-devel] [PATCH 4/5] xtensa: drop ARCH_NEEDS_BOOTSTRAP_RELOCS List-Id: uClibc-ng Development Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Xtensa does not define PERFORM_BOOTSTRAP_RELOC so it doesn't need ARCH_NEEDS_BOOTSTRAP_RELOCS definition. Remove it. Signed-off-by: Max Filippov --- ldso/ldso/xtensa/dl-sysdep.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/ldso/ldso/xtensa/dl-sysdep.h b/ldso/ldso/xtensa/dl-sysdep.h index d308237d39ed..6b908989a8f1 100644 --- a/ldso/ldso/xtensa/dl-sysdep.h +++ b/ldso/ldso/xtensa/dl-sysdep.h @@ -94,9 +94,6 @@ typedef struct xtensa_got_location_struct { /* Used for error messages. */ #define ELF_TARGET "Xtensa" -/* Need bootstrap relocations */ -#define ARCH_NEEDS_BOOTSTRAP_RELOCS - struct elf_resolve; extern unsigned long _dl_linux_resolver (struct elf_resolve *, int); From patchwork Fri Sep 9 18:30:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 1676179 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=uclibc-ng.org (client-ip=2a00:1828:2000:679::23; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=oJAtBEB1; dkim-atps=neutral Received: from helium.openadk.org (helium.openadk.org [IPv6:2a00:1828:2000:679::23]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MPPkq2Xsdz1yp8 for ; Sat, 10 Sep 2022 04:33:23 +1000 (AEST) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id 0EA2931E0727; Fri, 9 Sep 2022 20:33:00 +0200 (CEST) Authentication-Results: helium.openadk.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=oJAtBEB1; dkim-atps=neutral Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by helium.openadk.org (Postfix) with ESMTPS id 69F0D31E00B1 for ; Fri, 9 Sep 2022 20:30:42 +0200 (CEST) Received: by mail-pl1-f173.google.com with SMTP id iw17so2604472plb.0 for ; Fri, 09 Sep 2022 11:30:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=D9p/pcZLtIljdNr3DO3IFvPkQqnCuNWsPCsDwCtKjPI=; b=oJAtBEB1mHDGqmL+0UO2UHYIQh1UsqL1Q+bSkGHusCEXS5AjyUY0YAtWJJ9dqvhk0T ey3xNPsvitny7iFHtkO0wFDMMGsJLxPKqR5+sxsU1ekWPRwRcU8HvtAGawGT0fvUpHrA 6HJeANOfwSkTubKzX+bR5WKJIcvPYxQqQHUfkpT7MOR3yGTbFnA0VGCskbm0XOJf3w+b fRgAmCNQ+Br7duJDm8/J+YFDtFct/4rOH924+74HTNG8ypwYCLtdx7RueCauY/x+hES7 aFC6WT7MBXCSwvTSa5Uz0uv+YbA51yLMsJlRvS4VjjqDkWgja+O2Ee+YlGx15Lr8EBsI nZEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=D9p/pcZLtIljdNr3DO3IFvPkQqnCuNWsPCsDwCtKjPI=; b=VMPQaQcv8WWVfxdNRFYoAtkdoMODp58B2NuEMZCooPNxTMWDUTksxxtWN4altwzrhb 7Yrkkb4kYasIG5XqbWz0ZqKwnMku9GzZVb+739zITjU51rJXXb17TLfK1I3mrTiHDxrk wpulWnzpHMHZcIRo2k6hGZTtrNEbt+ix4eN8zmvfTurAosJPuGAnD5v1wFqbw0EQSBz8 HUeCd4kAL/iqeP8zdNYzJ7UshW6EN9bYc0WEDcNaN/8a2FOR+ZSOA+L3Sd0R6Q9jYa3l dDzgSz2Bj/gks1JyOUdI33uxG+GSVkitrqIPyYV0Lg3T6xxYHfahNB+aJB/UWqJkAEx4 IXYw== X-Gm-Message-State: ACgBeo3wA5ZDm+qiGsA/cVivIYx02mw1GTdClTw/G3WANU/kqG4NTZIq eKJEamepWAHs9jiRBtK/iUP+NaOZZ0rLFQ== X-Google-Smtp-Source: AA6agR40xdECv6ExBi2cfoXI5xM/BtBe5dWNM1cA4BB1+TWskox1B5QJRKpKVHHRtdy/8sKr21p4Nw== X-Received: by 2002:a17:902:bd41:b0:172:74c9:2a08 with SMTP id b1-20020a170902bd4100b0017274c92a08mr15097810plx.9.1662748240301; Fri, 09 Sep 2022 11:30:40 -0700 (PDT) Received: from octofox.metropolis (c-24-130-93-68.hsd1.ca.comcast.net. [24.130.93.68]) by smtp.gmail.com with ESMTPSA id q6-20020a170902dac600b00174a4bcefc7sm755709plx.217.2022.09.09.11.30.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 11:30:39 -0700 (PDT) From: Max Filippov To: devel@uclibc-ng.org Date: Fri, 9 Sep 2022 11:30:09 -0700 Message-Id: <20220909183009.4111393-6-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220909183009.4111393-1-jcmvbkbc@gmail.com> References: <20220909183009.4111393-1-jcmvbkbc@gmail.com> MIME-Version: 1.0 Message-ID-Hash: D6VWW7RQ4ZT46CN5C2X6K43H3FTMXDXN X-Message-ID-Hash: D6VWW7RQ4ZT46CN5C2X6K43H3FTMXDXN X-MailFrom: jcmvbkbc@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: linted X-Mailman-Version: 3.3.3 Precedence: list Subject: [uclibc-ng-devel] [PATCH 5/5] xtensa: add static pie support List-Id: uClibc-ng Development Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Max Filippov --- extra/Configs/Config.in | 4 +++- ldso/ldso/xtensa/dl-startup.h | 2 ++ libc/misc/internals/reloc_static_pie.c | 2 +- libc/sysdeps/linux/xtensa/crt1.S | 27 ++++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in index 43c04fd0a271..dd1beaadcee3 100644 --- a/extra/Configs/Config.in +++ b/extra/Configs/Config.in @@ -324,7 +324,9 @@ config DOPIC config STATIC_PIE bool "Add support for Static Position Independent Executables (PIE)" default n - depends on DOPIC && !UCLIBC_FORMAT_FDPIC_ELF && (TARGET_arm || TARGET_i386 || TARGET_x86_64 || TARGET_aarch64 || TARGET_mips) + depends on DOPIC && !UCLIBC_FORMAT_FDPIC_ELF && \ + (TARGET_arm || TARGET_i386 || TARGET_x86_64 || TARGET_aarch64 || \ + TARGET_mips || TARGET_xtensa) config ARCH_HAS_NO_SHARED bool diff --git a/ldso/ldso/xtensa/dl-startup.h b/ldso/ldso/xtensa/dl-startup.h index 19955ffc77a5..1babaccea7e8 100644 --- a/ldso/ldso/xtensa/dl-startup.h +++ b/ldso/ldso/xtensa/dl-startup.h @@ -7,6 +7,7 @@ * Parts taken from glibc/sysdeps/xtensa/dl-machine.h. */ +#ifndef L_rcrt1 __asm__ ( " .text\n" " .align 4\n" @@ -81,6 +82,7 @@ __asm__ ( " addi a5, a5, 8\n" " bnez a6, 3b\n" " j .Lfixup_stack_ret"); +#endif /* Get a pointer to the argv value. */ #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long *) ARGS) + 1) diff --git a/libc/misc/internals/reloc_static_pie.c b/libc/misc/internals/reloc_static_pie.c index 9f5366cc6ab7..81b235a51cb3 100644 --- a/libc/misc/internals/reloc_static_pie.c +++ b/libc/misc/internals/reloc_static_pie.c @@ -21,7 +21,7 @@ #include #include -#ifdef __mips__ +#if defined(__mips__) || defined(__xtensa__) #include #endif diff --git a/libc/sysdeps/linux/xtensa/crt1.S b/libc/sysdeps/linux/xtensa/crt1.S index efbe264c03f0..3fa14ae583a9 100644 --- a/libc/sysdeps/linux/xtensa/crt1.S +++ b/libc/sysdeps/linux/xtensa/crt1.S @@ -76,9 +76,26 @@ .global _start .type _start, @function _start: +#ifdef L_rcrt1 + .begin no-transform + call0 1f +.Lret_addr: + .end no-transform + .align 4 +1: +#endif #if defined(__XTENSA_WINDOWED_ABI__) +#ifdef L_rcrt1 + movi a6, .Lret_addr + sub a6, a0, a6 + movi a0, 0 + movi a4, reloc_static_pie + add a4, a4, a6 + callx4 a4 +#else /* Clear a0 to obviously mark the outermost frame. */ movi a0, 0 +#endif /* Load up the user's main function. */ movi a6, main @@ -106,8 +123,18 @@ _start: movi a4, __uClibc_main callx4 a4 #elif defined(__XTENSA_CALL0_ABI__) +#ifdef L_rcrt1 + mov a12, a2 + movi a2, .Lret_addr + sub a2, a0, a2 + movi a0, reloc_static_pie + add a0, a0, a2 + callx0 a0 + mov a7, a12 +#else /* Setup the shared library termination function. */ mov a7, a2 +#endif /* Load up the user's main function. */ movi a2, main