From patchwork Wed Jan 3 17:14:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1882023 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=IWc4iXT4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T4xHD3p1Pz1yQ5 for ; Thu, 4 Jan 2024 04:17:28 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 38ECD3857B80 for ; Wed, 3 Jan 2024 17:17:25 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id 10D5638582B2 for ; Wed, 3 Jan 2024 17:15:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 10D5638582B2 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 10D5638582B2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::134 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704302116; cv=none; b=g/RZsTBQELwUg3mQfumrnqRMiZNrfDChLCe0KEKpWlTzqM2QLO1aOADj05aXN+enRtENnDGFAD8z+4uG6lsR7Q0HWGrVqC0RMThfjiGBoLKCF8kpP8jxzD+T0okRCsNgIu6pi2oQ9kShFZck2VMFlZvGI6Z1cT5/abt3oFWYfZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704302116; c=relaxed/simple; bh=OJ/nGZaM05MzDVz16yXgKeqTkGIwYNvLT3Gf4BEhZs8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JLAgMvnOfGzFLWAypNwd8afdl0ZIU3+F61BArZ8aq53E0GXlyFv/foFwnHD0HkxArIC2w+YucXGu8UJxq8MY2nbGjktabNtj1EOB0lgvqEy797XJ92aw63T81uLbLkc3cG5yq+Dsc/yFvp36JtHBfG2D68FVjT9qA090U7IXxys= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-50e67f70f34so9335168e87.0 for ; Wed, 03 Jan 2024 09:15:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704302111; x=1704906911; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=qymngUbQlNpwUge87Me/hGlGbhY7Qqui1F5SiPCb7Eg=; b=IWc4iXT4qzv+oxJb2CxktRkqQhJaKiIaGk3A5I/0oxEvN17Vqfg4qjAX6vgcVO8pep 7ywd7L7E1R6nZE2RkPrWNpgkhOXcWTrWYZVVf9rcmNg9Qve3auuV0HdB4Qqfe7I3ZwxU G+X/B9UEhSdiCR27vpFY67GEu+iw72656w5OzGlBULuyJQuvqCR4H3uybP0Kiuor0Kiz FCgxuefXm0Z7vH4ar6c7Ns6mLDSvWIMZl4zNIRWGYu88w1/l/Cfn0EivdYXUYNmjLLj7 nmDZ7njh45auilb3vbOOKJI4t7IDu/P2PdDRh+SQrudjou+q1k6K4BtEPsZhsV46WQk3 4vCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704302111; x=1704906911; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qymngUbQlNpwUge87Me/hGlGbhY7Qqui1F5SiPCb7Eg=; b=OJUmqtXVMIeRRBOikVyKdyDQeG5PKvhj9MGny5PP1s8JKLANbses/3vy2a+VRvtWXx 0GBF/GtUe9y7TWAd8T/4hxALe8t1bDzDWxlzDtto562uTZ9lqJwtOnrwkt4NS2X/dciz G40MVFEYag3/KvXo7zc+g4oaL8gFHRPd670+7JFyNtHCTI2mJCANRCNZyiyOXULpO2L2 pgIQYZbGvrvnSMF4nBQi7mVGq8OxtWz/ODw6m/Yy/9BFBN8s723PgwwewpFDYfuF/45o CXLbJ5dijWR5bv9RnMKrKROOpzq7YiKvX22SW7tToutJFBJvrTJ6fPzFrFgsIgfmszrL g4oQ== X-Gm-Message-State: AOJu0Yzv5gWTj6kctS1tgVkD1iQj7RfqSSKcigpPbk0DPVusuf/HoM92 tmtzHb47EoAv6/ITUrwSmsGCmMcpPsI= X-Google-Smtp-Source: AGHT+IEUJa01IYh5vJFsZqfaQIPom3zNZ7q0kxNgGsOH8b92m1lcQG5+XBiDWEUaAJOlcTPIYRDr+g== X-Received: by 2002:a05:6512:2106:b0:50e:9767:1488 with SMTP id q6-20020a056512210600b0050e97671488mr2307106lfr.46.1704302111119; Wed, 03 Jan 2024 09:15:11 -0800 (PST) Received: from surface-pro-6.. ([2a00:1370:818c:b32f:ebdc:fd0:376b:8006]) by smtp.gmail.com with ESMTPSA id y23-20020a196417000000b0050e6d84d177sm3546068lfb.279.2024.01.03.09.15.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 09:15:10 -0800 (PST) From: Sergey Bugaev To: libc-alpha@sourceware.org, bug-hurd@gnu.org Subject: [RFC PATCH 07/23] hurd: Pass the data pointer to _hurd_stack_setup explicitly Date: Wed, 3 Jan 2024 20:14:40 +0300 Message-ID: <20240103171502.1358371-8-bugaevc@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240103171502.1358371-1-bugaevc@gmail.com> References: <20240103171502.1358371-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Instead of relying on the stack frame layout to figure out where the stack pointer was prior to the _hurd_stack_setup () call, just pass the pointer as an argument explicitly. This is less brittle and much more portable. Signed-off-by: Sergey Bugaev --- sysdeps/mach/hurd/i386/static-start.S | 3 +++ sysdeps/mach/hurd/x86/init-first.c | 16 +++++++--------- sysdeps/mach/hurd/x86_64/static-start.S | 1 + 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/sysdeps/mach/hurd/i386/static-start.S b/sysdeps/mach/hurd/i386/static-start.S index d83505b2..3ffcb47d 100644 --- a/sysdeps/mach/hurd/i386/static-start.S +++ b/sysdeps/mach/hurd/i386/static-start.S @@ -19,7 +19,10 @@ .text .globl _start _start: + pushl %esp call _hurd_stack_setup + /* No need to "addl %4, %esp", since _hurd_stack_setup + * returns with an already adjusted stack pointer. */ xorl %edx, %edx jmp _start1 diff --git a/sysdeps/mach/hurd/x86/init-first.c b/sysdeps/mach/hurd/x86/init-first.c index bb051418..6f71d71b 100644 --- a/sysdeps/mach/hurd/x86/init-first.c +++ b/sysdeps/mach/hurd/x86/init-first.c @@ -197,7 +197,7 @@ strong_alias (posixland_init, __libc_init_first); which should not exist at all. */ void inhibit_stack_protector -_hurd_stack_setup (void) +_hurd_stack_setup (void **argptr) { /* This is the very first C code that runs in a statically linked executable -- calling this function is the first thing that _start in @@ -206,14 +206,12 @@ _hurd_stack_setup (void) _start1 expects the arguments, environment, and a Hurd data block to be located at the top of the stack. The data may already be located there, - or we may need to receive it from the exec server. */ - void *caller = __builtin_extract_return_addr (__builtin_return_address (0)); - /* If the arguments and environment are already located on the stack, this is - where they are, just above our call frame. Note that this may not be a - valid pointer in case we're supposed to receive the arguments from the exec - server, so we can not dereference it yet. */ - void **p = (void **) __builtin_frame_address (0) + 2; + or we may need to receive it from the exec server. If the data is located + on the stack (just above our call frame), argptr points to it. Note that + this may not be a valid pointer in case we're supposed to receive the + arguments from the exec server, so we can not dereference it yet. */ + void *caller = __builtin_extract_return_addr (__builtin_return_address (0)); /* Init the essential things. */ first_init (); @@ -245,7 +243,7 @@ _hurd_stack_setup (void) the stack pointer to the data (which is somewhere on the current stack anyway). This way, _start1 find the data on the top of the stack, just as it expects to. */ - _hurd_startup (p, &doinit); + _hurd_startup (argptr, &doinit); __builtin_unreachable (); } #endif diff --git a/sysdeps/mach/hurd/x86_64/static-start.S b/sysdeps/mach/hurd/x86_64/static-start.S index 9b9db937..0ec00905 100644 --- a/sysdeps/mach/hurd/x86_64/static-start.S +++ b/sysdeps/mach/hurd/x86_64/static-start.S @@ -25,6 +25,7 @@ _start: leaq __strlen_sse2(%rip), %rax movq %rax, strlen@GOTPCREL(%rip) + movq %rsp, %rdi call _hurd_stack_setup xorq %rdx, %rdx jmp _start1