From patchwork Fri Jun 13 10:22:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ludwig Rydberg X-Patchwork-Id: 114434 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 CB80E387296C for ; Fri, 13 Jun 2025 10:24:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB80E387296C X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) by sourceware.org (Postfix) with ESMTPS id 69F7F3866231 for ; Fri, 13 Jun 2025 10:22:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 69F7F3866231 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gaisler.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gaisler.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 69F7F3866231 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=94.231.106.210 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749810172; cv=none; b=olR7ytw+ZOGNXfjPF0FIL4mOFExdgJKhb5/sLKUdbsVEVQPSOpc+9PvuloJw62pnJ4si+1mbeXiesIQG6CkPzEkVY/uXkueMXO6Kj5Ej36QtsyoMuVQi7ZsFxgPuuTW1I56USovD0bwqiObxGeO632FdMiyHG+VTRYlrpzW2mAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749810172; c=relaxed/simple; bh=1xgGHZWEsWusTWRBKKDAEWd+LMz++emr6mQzg+HZxpI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Xjua74QKbNWP8sioGc4vXW0/++bXTgjrS5aApNC7g2gdTWwTfuSmrN7nIPlQD02QuE2W5wLzexl1KDt+BekhmhMlPV1e5JWRvsA1qhvrKqbJ5U62xh+BhLXbjwY5d9dXhSzexSNqoNAQTwkqMRVbJ4J5d2rRxUiG5c+g8sYP6/A= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 69F7F3866231 Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4bJb7b0Wy8z1DHYV; Fri, 13 Jun 2025 12:22:51 +0200 (CEST) Received: from ludwig.got.gaisler.com (h-98-128-223-123.NA.cust.bahnhof.se [98.128.223.123]) by smtp.simply.com (Simply.com) with ESMTPA id 4bJb7Z6Gkgz1DHpV; Fri, 13 Jun 2025 12:22:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaisler.com; s=simplycom1; t=1749810170; bh=OCLdZseZCrTUYlGAG661uuGxrj/MwGdl2/MMf5fWAnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=csYr/Uqpjx38LiNBuiWaXA30QHjL3+tM6ZnYV75N4JpO/8AZSkwVC1U3v6DdYMi14 tLNjMV/8JH1oN/KMJMw5HFHhA1F51vGCCm2KzG2yQ4RM0JN6bdbCjX4P89FEJ+Sy3A rwrENOVBsIepqmKKDc4jsFVWmqkTrMRhqv2VnpoE= From: Ludwig Rydberg To: libc-alpha@sourceware.org Cc: andreas@gaisler.com, adhemerval.zanella@linaro.org, Ludwig Rydberg Subject: [PATCH] sparc: Fix argument passing to __libc_start_main on SPARC32 Date: Fri, 13 Jun 2025 12:22:41 +0200 Message-Id: <20250613102241.771-2-ludwig.rydberg@gaisler.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20250613102241.771-1-ludwig.rydberg@gaisler.com> References: <20250613102241.771-1-ludwig.rydberg@gaisler.com> MIME-Version: 1.0 X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_PASS, TXREP 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~patchwork=sourceware.org@sourceware.org Use a custom __libc_start_main function so the highest stack address can be provided to __libc_start_main_impl without altering the content of the stack (as there is no room for adding arguments to the stack). The __libc_stack_end was written to [%sp+23*4] but that address is already in use (holds the pointer to argv) which led to corruption. Fixes: d952c6efaa87 ("sparc: Fix argument passing to __libc_start_main (BZ 32981)") Signed-off-by: Ludwig Rydberg --- sysdeps/sparc/sparc32/start.S | 6 ++-- .../sysv/linux/sparc/sparc32/libc-start.c | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/libc-start.c base-commit: daab2a6d19f8360248289840408e7d2e5c203c2e diff --git a/sysdeps/sparc/sparc32/start.S b/sysdeps/sparc/sparc32/start.S index cef7c96cac72..9d97a2943efa 100644 --- a/sysdeps/sparc/sparc32/start.S +++ b/sysdeps/sparc/sparc32/start.S @@ -64,18 +64,16 @@ _start: xor %o0, %gdop_lox10(main), %o0 ld [%l7 + %o0], %o0, %gdop(main) #endif - mov 0, %o3 /* Used to be init. */ - mov 0, %o4 /* Used to be fini. */ /* When starting a binary via the dynamic linker, %g1 contains the address of the shared library termination function, which will be registered with atexit(). If we are statically linked, this will be NULL. */ - mov %g1, %o5 + mov %g1, %o3 /* Provide the highest stack address to update the __libc_stack_end (used to enable executable stacks if required). */ - st %sp, [%sp+23*4] + mov %sp, %o4 /* Let libc do the rest of the initialization, and call main. */ call __libc_start_main diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc-start.c b/sysdeps/unix/sysv/linux/sparc/sparc32/libc-start.c new file mode 100644 index 000000000000..c24c1539a41c --- /dev/null +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc-start.c @@ -0,0 +1,30 @@ +/* Copyright (C) 1998-2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define LIBC_START_MAIN generic_start_main +#include + +STATIC int +__libc_start_main_impl (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), + int argc, char **argv, void (*rtld_fini) (void), + void *stack_end) +{ + return generic_start_main (main, argc, argv, + NULL, NULL, rtld_fini, + stack_end); +} +DEFINE_LIBC_START_MAIN_VERSION