From patchwork Thu Sep 15 19:30:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 1678401 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=UbOkGIvT; 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 4MT6l65m8cz1ypd for ; Fri, 16 Sep 2022 05:31:29 +1000 (AEST) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id B59013520780; Thu, 15 Sep 2022 21:31:21 +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=UbOkGIvT; dkim-atps=neutral Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by helium.openadk.org (Postfix) with ESMTPS id 34DED35206C5 for ; Thu, 15 Sep 2022 21:31:15 +0200 (CEST) Received: by mail-pf1-f178.google.com with SMTP id e68so19057700pfe.1 for ; Thu, 15 Sep 2022 12:31:15 -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=UbOkGIvTHGVP0saPNsDEjflkWhE7IhqS/YC+m1N2/+lFSnTDvPeQWy/sNAi+N4dKpZ hK6vEyKkw9SAFYLKWL/BmbWp9KGbbJ25RU0RbKegXdlU5BAbkKkTFVAjXvv2nyPPKSwz zLRxJxRWn+WsS526LbtTPdzNHoU0NsbJGq/amDSanxFPQgOwqTbTB5/GDGdF5DMC+RCc yH2DcT07y0BOePfzAaBXEfRZh198OmvQ4uitZ8cSvhITZ0+rx3xfIR+ubrjhs9///CeG fzNag52q1HSdMst4l8KARvjFMFKhgwBZufr/n2CQjrwQek9mGFVxYpaC0bxzZRCZ5pJk qv8g== 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=0jAQ/SMuQo17mzWDpxfFqN8FXaTO0xrES52lR5yx9OEW0PQPcaVIWQ8S6E0MQaO04q uimlgIAtJQQoyhuw+jbPV64N/ztkyhV7OAM13LzZJrHYSkUQ8B4RfXygHW6SNQOJItpk DP8Unl7yDr7C6qgWAz/ubZvkLPg3qOcEDwogEcHmsgDK+CYz70iRNzPLhAtrEVs8fvE2 S9UBwG29VFdGHoZ4TOWOKPJqk6hq6aMt3eE8F0qEO6AVv4qjqJLFpHdGRxdl8yw24tub 9GsZ6nW5LetsNGuIvxN01HBjmwSXlQTAjrCHRdFhyad0gX8yegTpiXpKQt+D9bXhfzx2 vViQ== X-Gm-Message-State: ACrzQf2LC+IMZa4gbbNNFSuzHM6uxHoqw4rz0lYJJiUwG64I8oj4b1e5 gF1dNdx+Id0yzdccjBSLwhos2kAhXZTd4Q== X-Google-Smtp-Source: AMsMyM5m/RXpGmb4rQpOesFClIDDvRieS9ha/IVvu+HCMwN3RsP+Oge7e9RtVMh+/59uYRCZfkNDlA== X-Received: by 2002:a63:1b10:0:b0:439:2e22:8fcc with SMTP id b16-20020a631b10000000b004392e228fccmr1167479pgb.565.1663270273000; Thu, 15 Sep 2022 12:31:13 -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 n9-20020a170902e54900b00174be817124sm13418743plf.221.2022.09.15.12.31.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 12:31:12 -0700 (PDT) From: Max Filippov To: devel@uclibc-ng.org Date: Thu, 15 Sep 2022 12:30:50 -0700 Message-Id: <20220915193054.2916840-2-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220915193054.2916840-1-jcmvbkbc@gmail.com> References: <20220915193054.2916840-1-jcmvbkbc@gmail.com> MIME-Version: 1.0 Message-ID-Hash: UHVEUCCMULIZ7KDNEZFKC3ZCR77NBK3Z X-Message-ID-Hash: UHVEUCCMULIZ7KDNEZFKC3ZCR77NBK3Z 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 v2 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 Thu Sep 15 19:30:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 1678403 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=TXVCSyCK; 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 4MT6lG1SR0z1ynm for ; Fri, 16 Sep 2022 05:31:38 +1000 (AEST) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id F3DEC35206C5; Thu, 15 Sep 2022 21:31:32 +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=TXVCSyCK; dkim-atps=neutral Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by helium.openadk.org (Postfix) with ESMTPS id 36AA63520778 for ; Thu, 15 Sep 2022 21:31:19 +0200 (CEST) Received: by mail-pg1-f176.google.com with SMTP id q9so9109532pgq.8 for ; Thu, 15 Sep 2022 12:31:19 -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=FqzC2H3gUVeC4Tvz1i/odQjzv68bPKhYDtq5fGmgBqU=; b=TXVCSyCKPT1Cm59K8AOOj2a5bYuB0BCjFKV7EI0j/hHFb6amuDgvxOWsLGUmYnD1F2 dAm5VQTtx1qVmhowxWQWkvd6RfB7GottJZFCD8O9bcbec3+WoLKwAzUFotbKk0h6UT/I wlPT82QD7mC6t/74riTbbbDEIJQXZCoQjdxuhBvY7XYW8nSUhWKE8dDqdKERCy96Wy9J 4GWLgEvDTIEb2HfVzvrmmcDR4/8BRftEdrtP7DhO1OGvCn8bupT+YfwcxvPaQkp475kX 8YFmmpaxEsx9FrWdDQp6ldsobjsC4g44Kxc7iPIrtAoCVkyh5zhrNkOIu0kG2Jf3ve+h 5OOw== 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=FqzC2H3gUVeC4Tvz1i/odQjzv68bPKhYDtq5fGmgBqU=; b=VhO+cPtIt8giF1GAIZWKEpJnBSBJd2Q8SngczkmG0yWdpEvzX5npx3Awd6Nb5p/k0n ppJkz7zLt1C5Ebpa9JF2NxKrpVcPFWD/DQV0QiT26Nto9/4rnFuMDxsnOtK1AUX1b2G/ pk5mNBUTvk3G9ihsVHvAPUSB2FVToBivzpJzdp3g2VVq7BkKcsQG2qE/4BT53oVdDQag LYWKygDDeYB4C1nCKrvj/hygPtzNp43OzIS49JNrqajJ8HJp4ol9YDIPQqmb1EPQ0Hjd ZMl1OC0wuLVAPss6CMUGqRpwS4rfhL8BAVXlFEgSQ+bn8x0t7/5GnIeGatqfehMfP5kt dzdA== X-Gm-Message-State: ACrzQf2VPft5c4wDGG6+8lDOgc9tvhKYhiWgtE3OJSPJFQggefYbKLgQ XKAJWiqr0bulIVdNqJhklbObSePpRmUasw== X-Google-Smtp-Source: AMsMyM6GUxfHa1kcKlv3skzx/A8A2b0xDwTz9o7Rj30JnksXvb16gzV+m2ZV70TsvqBjd+rImQT/Mg== X-Received: by 2002:a05:6a00:124f:b0:542:6c43:5be8 with SMTP id u15-20020a056a00124f00b005426c435be8mr1377308pfi.5.1663270275767; Thu, 15 Sep 2022 12:31:15 -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 n9-20020a170902e54900b00174be817124sm13418743plf.221.2022.09.15.12.31.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 12:31:15 -0700 (PDT) From: Max Filippov To: devel@uclibc-ng.org Date: Thu, 15 Sep 2022 12:30:51 -0700 Message-Id: <20220915193054.2916840-3-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220915193054.2916840-1-jcmvbkbc@gmail.com> References: <20220915193054.2916840-1-jcmvbkbc@gmail.com> MIME-Version: 1.0 Message-ID-Hash: B5NZ7OZLXYQUIAYO6NHRTM7RZDYUIMMV X-Message-ID-Hash: B5NZ7OZLXYQUIAYO6NHRTM7RZDYUIMMV 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 v2 2/5] ldso: clean up PERFORM_BOOTSTRAP_GOT ifdeferry List-Id: uClibc-ng Development Archived-At: List-Archive: <> List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 3 architectures currently define PERFORM_BOOTSTRAP_GOT: avr32, mips and xtensa. A block of code that applies relative relocations in the DL_START is disabled when PERFORM_BOOTSTRAP_GOT is defined, unless it's avr32 or mips, effectively disabling it only for xtensa. This may be simplified by removing the call to elf_machine_relative from the xtensa PERFORM_BOOTSTRAP_GOT and always using common code. Signed-off-by: Max Filippov --- Changes v1->v2: - new patch ldso/ldso/dl-startup.c | 3 --- ldso/ldso/xtensa/dl-startup.h | 11 ----------- 2 files changed, 14 deletions(-) diff --git a/ldso/ldso/dl-startup.c b/ldso/ldso/dl-startup.c index 24b046c62b0b..a1b3d49fdd39 100644 --- a/ldso/ldso/dl-startup.c +++ b/ldso/ldso/dl-startup.c @@ -255,8 +255,6 @@ DL_START(unsigned long args) PERFORM_BOOTSTRAP_GOT(tpnt); #endif -#if !defined(PERFORM_BOOTSTRAP_GOT) || defined(__avr32__) || defined(__mips__) - /* OK, now do the relocations. We do not do a lazy binding here, so that once we are done, we have considerably more flexibility. */ SEND_EARLY_STDERR_DEBUG("About to do library loader relocations\n"); @@ -337,7 +335,6 @@ DL_START(unsigned long args) #endif } } -#endif SEND_STDERR_DEBUG("Done relocating ldso; we can now use globals and make function calls!\n"); diff --git a/ldso/ldso/xtensa/dl-startup.h b/ldso/ldso/xtensa/dl-startup.h index db223feadc90..92877aa016fb 100644 --- a/ldso/ldso/xtensa/dl-startup.h +++ b/ldso/ldso/xtensa/dl-startup.h @@ -92,8 +92,6 @@ __asm__ ( 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,13 +123,4 @@ do { \ prev_got_end - prev_got_start, \ PROT_READ | PROT_WRITE | PROT_EXEC); \ } \ -\ - /* 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 \ - to be done here instead. */ \ - relative_count = tpnt->dynamic_info[DT_RELCONT_IDX]; \ - rel_addr = tpnt->dynamic_info[DT_RELOC_TABLE_ADDR]; \ - if (rel_addr) \ - elf_machine_relative(load_addr, rel_addr, relative_count); \ } while (0) From patchwork Thu Sep 15 19:30:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 1678404 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=Rw82FK70; 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 4MT6lM6njKz1ynm for ; Fri, 16 Sep 2022 05:31:43 +1000 (AEST) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id 79605352077D; Thu, 15 Sep 2022 21:31:35 +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=Rw82FK70; dkim-atps=neutral Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by helium.openadk.org (Postfix) with ESMTPS id D373B35206C5 for ; Thu, 15 Sep 2022 21:31:20 +0200 (CEST) Received: by mail-pg1-f182.google.com with SMTP id v4so18206864pgi.10 for ; Thu, 15 Sep 2022 12:31:20 -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=GBJ+J3XQ11jBhfci+Jt8yYf4dQAxAUMuAJSt4Iz4AJs=; b=Rw82FK70/oK+u/mt6KPZDqhFBbh47h570CDZwOdv5Fdcdxw2KccxsnSjQ1IJ6Ro1km 1396huhFaIfJ+ZymGckqaU8yzGiVrhV3IwW0tk9/2J5qhPhDHK+2ufKUe04A042tHMMp ar87omBRzo4EypjNhr3k2AaxED0N8h6d1aLYeoMD7Gyxpmgg4aHnXZrNIm57EFaa/vGw WoLcwJ3IzW0hbpxg4uRF5iht87+yElTIQfOpap2h6VcG/BpOO6nITv2UiohmWcee1FGi drR+3ghwOnAwHbqcc2vw2ylX3vyAyAZZpL++xFxG4EPYgq9W5bkNi7hqd0IMphDQ/Vag AlSA== 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=GBJ+J3XQ11jBhfci+Jt8yYf4dQAxAUMuAJSt4Iz4AJs=; b=tBUj0stBVaNzyoTvFqKjnc0zHhPqabbRJrfLPW0ZgA0e+eOBKjAg3h+7yY7qniLtVl CpPGdwGyPkLjDwit7BlbsYynwx3kK2h46QFI3U0FcjWN5+PkZiffDFoeWNFGqYj49E0v O1F+sINi3T3JdGkdUZBE/9ipIv9W5gVWMevcjaEAMYYnABU1B8GlbBhBlLPNm2+C1Leb j+dmPzu7ApPREaXiu3OwgFH+r0INBV2y8cymKJ8EFiLwSlyeZDSJT39zkQfQyFd/fsVX RLSmkBdY5fRh864v9+U6B4c87TXLrTOpaXWkrt4BPTNstcNrkbdJFDcYqoGBcc3EyVq7 eVyA== X-Gm-Message-State: ACrzQf3IYk+jJPG6Vrt83RjnSnbA3ERcNey19TO92wmnCRLoFJQf3cyV uRNAotyqiaRLg+ggOE62vch9qmeKcxgFMA== X-Google-Smtp-Source: AMsMyM49TA8o+DOVoydfZExq7SxkPpzv5vVLCp/Dqb0sbIZYh52HSaalTSJO4F6zdSkcFQi61AFktg== X-Received: by 2002:a63:4ca:0:b0:434:b550:2115 with SMTP id 193-20020a6304ca000000b00434b5502115mr1198429pge.203.1663270278114; Thu, 15 Sep 2022 12:31:18 -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 n9-20020a170902e54900b00174be817124sm13418743plf.221.2022.09.15.12.31.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 12:31:17 -0700 (PDT) From: Max Filippov To: devel@uclibc-ng.org Date: Thu, 15 Sep 2022 12:30:52 -0700 Message-Id: <20220915193054.2916840-4-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220915193054.2916840-1-jcmvbkbc@gmail.com> References: <20220915193054.2916840-1-jcmvbkbc@gmail.com> MIME-Version: 1.0 Message-ID-Hash: LWJOUS3W6M6NBUSHWCPI6F2LR3DZNARX X-Message-ID-Hash: LWJOUS3W6M6NBUSHWCPI6F2LR3DZNARX 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 v2 3/5] xtensa: ldso: 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. Only define PERFORM_BOOTSTRAP_GOT when building xtensa configuration with MMU support. Signed-off-by: Max Filippov --- Changes v1->v2: - now that PERFORM_BOOTSTRAP_GOT only does mprotect calls make its whole definition conditional instead of extracting that part. ldso/ldso/xtensa/dl-startup.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ldso/ldso/xtensa/dl-startup.h b/ldso/ldso/xtensa/dl-startup.h index 92877aa016fb..439bdbd7a5e2 100644 --- a/ldso/ldso/xtensa/dl-startup.h +++ b/ldso/ldso/xtensa/dl-startup.h @@ -88,6 +88,7 @@ __asm__ ( /* Function calls are not safe until the GOT relocations have been done. */ #define NO_FUNCS_BEFORE_BOOTSTRAP +#if defined(__ARCH_USE_MMU__) #define PERFORM_BOOTSTRAP_GOT(tpnt) \ do { \ xtensa_got_location *got_loc; \ @@ -124,3 +125,4 @@ do { \ PROT_READ | PROT_WRITE | PROT_EXEC); \ } \ } while (0) +#endif From patchwork Thu Sep 15 19:30:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 1678405 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=Q5vKWx0B; 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 4MT6lT33mHz1ynm for ; Fri, 16 Sep 2022 05:31:49 +1000 (AEST) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id C6251352077E; Thu, 15 Sep 2022 21:31:36 +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=Q5vKWx0B; dkim-atps=neutral Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by helium.openadk.org (Postfix) with ESMTPS id A7CA5352077D for ; Thu, 15 Sep 2022 21:31:23 +0200 (CEST) Received: by mail-pl1-f178.google.com with SMTP id s18so13359153plr.4 for ; Thu, 15 Sep 2022 12:31:23 -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=Q5vKWx0BhJo3LJ+NLUY0WeIBeksahSGQQdefx4JklDJJ/FIF52rtJ1/JVuM57OzK3U Nf95r3/3LTRDM4bHDiCtwUoOZmN+Ut1FyVwizfovae89mqM6ZrxhU2n5L4K5C3bxEbe+ yodkGGRLnNkfIfVVp2nZsPzReaiey0iKQpOV98GJyuPlth1bdkVjwotRbibEFNYIBoab F7XI7WRkMvPShULQpXXkrSho1l7NcxaYv7EWRjpG/TsqTO4BvzZZCn61pYFP2JFeRcGK bsjMLUB7WCpeqtbZoZvLCyEomMrAqhvtN6RB2x4WdeHDgOe61qTdTIBdbpcs2lPAjCz2 uagw== 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=sJCanobNzTEvJXqL8chS4fOwLjmDjjK6yiorvY0AW0nh3w32iN+dk9lIaNMLvR3mKp 47x64g/xhxa5uTPir7MdNWSa3kcP4bNP1F4iH1+7nRhdlqTPcbKF6418HujIhzh3TRzT 3YiPSlXlY09VF3AuZ8fweajdGAJq+kE3wDeUEoeTqwGuFLxZ3t59WkwKbUJin8sElxST ojPPfoRXoqEPeGWuPBOMZAJkJ5Dk8FMpQ7MeZpPl1cXaE+91oQ2yvVul/qR2jDuqyogt LpTB5uVgKTZMfbwYUKsEOhMPQhnXuGZ3ucMmMdP9yc7bb10khixc9n+b75yhl7to0ECA 5WgA== X-Gm-Message-State: ACrzQf3dUeVkpsgcso2L9mDd5Wp2gGJR5GPWrbcrmMXlivTjHG4Jkk5R JZdmerDA5FEs3MWy7mhCn9gBqKXDQg8XYw== X-Google-Smtp-Source: AMsMyM5rsLmvgqtKiTA7rKVyPxtnuZJgCsI/HsI4pPuYe6ZMAQbzKDuPzyxZZ/t+ADzAZ+gifKy1Jg== X-Received: by 2002:a17:902:dad2:b0:178:401c:f66d with SMTP id q18-20020a170902dad200b00178401cf66dmr941947plx.157.1663270280511; Thu, 15 Sep 2022 12:31:20 -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 n9-20020a170902e54900b00174be817124sm13418743plf.221.2022.09.15.12.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 12:31:20 -0700 (PDT) From: Max Filippov To: devel@uclibc-ng.org Date: Thu, 15 Sep 2022 12:30:53 -0700 Message-Id: <20220915193054.2916840-5-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220915193054.2916840-1-jcmvbkbc@gmail.com> References: <20220915193054.2916840-1-jcmvbkbc@gmail.com> MIME-Version: 1.0 Message-ID-Hash: IOXUFKRP3BY3UEBGOZEMFGI4VCSOW6GB X-Message-ID-Hash: IOXUFKRP3BY3UEBGOZEMFGI4VCSOW6GB 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 v2 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 Thu Sep 15 19:30:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 1678406 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=o6Ri+Nns; 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 4MT6lW72v5z1ynm for ; Fri, 16 Sep 2022 05:31:51 +1000 (AEST) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id 93F45352067E; Thu, 15 Sep 2022 21:31:43 +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=o6Ri+Nns; 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 718113520194 for ; Thu, 15 Sep 2022 21:31:26 +0200 (CEST) Received: by mail-pj1-f47.google.com with SMTP id n23-20020a17090a091700b00202a51cc78bso17131839pjn.2 for ; Thu, 15 Sep 2022 12:31:26 -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=Ltm1hyRhvMjKva1lvsJ1mGFjie21FSB/fnFeLJiX9O0=; b=o6Ri+Nns5tIFEoMPPvdBMX2GLcWGvLST+BZGg6EchMP9W2YmIrD7MLmz27nhZtTFS8 rIrQYuZf/DNew9RqblybpMMsFDN6GLFDvQsxbKTgaB4xtDf+UbcRRXh/eNR3qm8kzAMr QQkxczyty2+JfimROSKRGE8IxACjvfUJ6QzQpBnb8ablmLn1QwKNAQ/wZ/xUMvqX/bk3 qu/Rm2PSy1/c68/Kbtzo7chb/wrcWfH90Srl/o5d2FzfjIgDWHcKBMBjGi7MsX2B37NO hCmddlhJ8P/v5tjcaNvvji2IOOSg115Qzsb3dQwTqFCMrPuugBPyTqUBC6duEn4zwpc8 LUKQ== 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=Ltm1hyRhvMjKva1lvsJ1mGFjie21FSB/fnFeLJiX9O0=; b=Os2pDVmsJHIaXBx3OX9/RrKUZC+Rhh5oWmz8JXKjF/H577O2NRJ+mSmUC1t6WC1Amm +3DQ+Ykky8RA77NwQmr92OG1WV1uPW1LwNxgl2ZEfToaSbdNvvpC6OEbJcgQOXUriMO+ fNqchyqsjbKwBwe0T+8RszB+l5h0wYVFfs2Ry9Pu9VLMbabiYPt6vqzOwL8YZwSLCZfN bDvLSYqFrZCPv/Z6IA/TK2uQS5J+aW16P5+sDFab7HS+Qe/Vt7gYgeynEllk1ydukwg0 ElQ+Dyu8bPOEiIxr6qvpneqkWBHHdBCL7UgqZ7QaeTBWRDNOM6buUY35Fy0Z2bfFV+nz JuPQ== X-Gm-Message-State: ACrzQf3HhZ5O0QjnAvNYxLnt1/TcvxrQgtNNqNo/76ncG+VGq+qsA2Z5 /Jj03OIdWzkyF5RAbs4gYtAue1u44QIbbw== X-Google-Smtp-Source: AMsMyM6lu6lvNZBORNf/Bu+ntpKX8GrsZn1jSugD70FP0itn162sa3mc0mhGCnvhNq1Bcu8UBpbeww== X-Received: by 2002:a17:902:c40b:b0:178:e34:efa9 with SMTP id k11-20020a170902c40b00b001780e34efa9mr1093039plk.10.1663270282936; Thu, 15 Sep 2022 12:31:22 -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 n9-20020a170902e54900b00174be817124sm13418743plf.221.2022.09.15.12.31.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Sep 2022 12:31:22 -0700 (PDT) From: Max Filippov To: devel@uclibc-ng.org Date: Thu, 15 Sep 2022 12:30:54 -0700 Message-Id: <20220915193054.2916840-6-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220915193054.2916840-1-jcmvbkbc@gmail.com> References: <20220915193054.2916840-1-jcmvbkbc@gmail.com> MIME-Version: 1.0 Message-ID-Hash: LKZ7FGC25IKQSUAJCKTVGXQCTTAHUMOD X-Message-ID-Hash: LKZ7FGC25IKQSUAJCKTVGXQCTTAHUMOD 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 v2 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 439bdbd7a5e2..c9350c0f201e 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 ce42cb9b30df..ab1923024c2b 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