From patchwork Wed Dec 15 23:12:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 48994 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 7F149385800A for ; Wed, 15 Dec 2021 23:14:33 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hall.aurel32.net (hall.aurel32.net [IPv6:2001:bc8:30d7:100::1]) by sourceware.org (Postfix) with ESMTPS id 9D308385842D for ; Wed, 15 Dec 2021 23:12:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9D308385842D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=aurel32.net Authentication-Results: sourceware.org; spf=none smtp.mailfrom=aurel32.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=aurel32.net ; s=202004.hall; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date: Subject:Cc:To:From:Content-Type:From:Reply-To:Subject:Content-ID: Content-Description:In-Reply-To:References:X-Debbugs-Cc; bh=7ZENnwIEsYPnG6FQA1G4GZ/mE0RM47xDeE6yC3exOBc=; b=DpWwHhDnLdEDoOioDcmVE116Io N6+sgJpxtjdWOeTNv1mneMa/LZ2/QM8ZjxYDkaThuC+Ajvvl6Y+dQbqdXyo+yWF9nUnpsKvWpeKrC NMMokrez2mbgqYFo9UJLqGA6KPH6NZjtew0HKzlf30C0LL26ykxmp2i5Zrz10d4M1W5jo7Ylea0Gh QDRq8y2YsFgHFx9/72+1tJzUFUlP5ZPjzJGk1dd+53+5vGff6q1ewmxSDBN3H6m8ECpy0lANwnRfL GbYj7AelDHXtAcNBENse/vj+o8VhdnWqI+gzLcA0ZJ3+0Gu3h7CpgGQiQri7on/NV9zGSvLd7nlwt 8EAsY+0A==; Received: from [2a01:e34:ec5d:a741:8a4c:7c4e:dc4c:1787] (helo=ohm.rr44.fr) by hall.aurel32.net with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mxdRq-0007xa-F1; Thu, 16 Dec 2021 00:12:34 +0100 Received: from aurel32 by ohm.rr44.fr with local (Exim 4.95) (envelope-from ) id 1mxdRq-001oul-1v; Thu, 16 Dec 2021 00:12:34 +0100 From: Aurelien Jarno To: libc-alpha@sourceware.org Subject: [PATCH] riscv: align stack before calling _dl_init [BZ #28703] Date: Thu, 16 Dec 2021 00:12:29 +0100 Message-Id: <20211215231229.434034-1-aurelien@aurel32.net> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_NONE, TXREP 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: , Cc: Aurelien Jarno , Andrew Waterman Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Align the stack pointer to 128 bits during the call to _dl_init() as specified by the RISC-V ABI [1]. This fixes the elf/tst-align2 test. Fixes bug 28703. [1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc --- sysdeps/riscv/dl-machine.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h index ce2b3c3875..f457a41c70 100644 --- a/sysdeps/riscv/dl-machine.h +++ b/sysdeps/riscv/dl-machine.h @@ -125,8 +125,14 @@ elf_machine_dynamic (void) sll a3, a1, " STRINGXP (PTRLOG) "\n\ add a3, a3, a2\n\ add a3, a3, " STRINGXP (SZREG) "\n\ + # Stash the stack pointer in s1.\n\ + mv s1, sp\n\ + # Align stack to 128 bits for the _dl_init call.\n\ + andi sp, sp,-16\n\ # Call the function to run the initializers.\n\ jal _dl_init\n\ + # Restore the stack pointer for _start.\n\ + mv sp, s1\n\ # Pass our finalizer function to _start.\n\ lla a0, _dl_fini\n\ # Jump to the user entry point.\n\