Message ID | 20230109075442.25963-4-w@1wt.eu |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2028203wrt; Sun, 8 Jan 2023 23:57:22 -0800 (PST) X-Google-Smtp-Source: AMrXdXvf9NT0tfdKURUs0ugAhDt+T+FgdQMQj23W5fti8NvTWDPS3Ax+CP61H6qv49/pzHwT4cBC X-Received: by 2002:a17:906:d217:b0:7c1:6fc:6048 with SMTP id w23-20020a170906d21700b007c106fc6048mr51666268ejz.24.1673251042392; Sun, 08 Jan 2023 23:57:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673251042; cv=none; d=google.com; s=arc-20160816; b=TfAx2GT9bxeDLyM4uqDrFYeEodPXodtd9RpQdXl/UvU2cToe0Szm4pB8f7tZ7tslBk KUz+YgiCmaPNi4OraJvI+q/lAbPcJmTIzSwUqO3WSoL2vJk7WuPEtK59BreTy051NsOn RkEIzygiWtIrrugFe/Fsy0Egl8M21vUmWhdFYqCiud966Sy+5/vNowb5djmbKkmwXRX2 1mCAZ6/E2or8qjh394kx4fsvYsUXjgKpWMsouyTJzFMKZ6P8evMJQNYpqMh4MREkM4He WeU64x+nAxy24IbhLW8U3nNDHCZWwkjyXLKMBxlXxlWAmNJgPsKRyx2nctkSOzcOQ9Ns U6gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=qMvOXmjYVrX9jQomSokd6YO83sksTD8p/f61cr4ob04=; b=Z0oWkde7Qc5JoULxr4K3PGoGTEYEH0Ek89PRJU1sbyxf3uZp7AZ+9TkKOxb5eHHbsa ldkBXGEzMgpqmwFiAZ6psgBVcNIde/PZs/z6/JBHLE5u6j/jXU374CPBEM/pEQ3vuuKA CiFN6HE16W/DqSxB5zhpEA2hGSL2M2GC1TzbtUb6suwhLJT9SpUjSc5WkRnKJqquGzeQ /zwqJKaxBKsIn25qHFBHKcw0WwUEwBLbo8B7bhp8vpQK4NhV28J2suwO1b7XjVn5fUNH 57y/FHnnfWLci/BAKixJX8IhKoOA4IK6v1sx8DkwRDRz+oST6HMOLEMQCJpYc+4qsBDG Hs3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xe6-20020a170907318600b00780488c11bbsi8968786ejb.388.2023.01.08.23.56.59; Sun, 08 Jan 2023 23:57:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233367AbjAIHz5 (ORCPT <rfc822;zhanglyra.2023@gmail.com> + 99 others); Mon, 9 Jan 2023 02:55:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235659AbjAIHz3 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 9 Jan 2023 02:55:29 -0500 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A844FDF3B for <linux-kernel@vger.kernel.org>; Sun, 8 Jan 2023 23:55:20 -0800 (PST) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 3097sot6026017; Mon, 9 Jan 2023 08:54:50 +0100 From: Willy Tarreau <w@1wt.eu> To: "Paul E. McKenney" <paulmck@kernel.org> Cc: linux-kernel@vger.kernel.org, Willy Tarreau <w@1wt.eu> Subject: [PATCH 3/6] tools/nolibc: restore mips branch ordering in the _start block Date: Mon, 9 Jan 2023 08:54:39 +0100 Message-Id: <20230109075442.25963-4-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20230109075442.25963-1-w@1wt.eu> References: <20230109075442.25963-1-w@1wt.eu> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754530885278349338?= X-GMAIL-MSGID: =?utf-8?q?1754530885278349338?= |
Series |
pending bug fixes for nolibc
|
|
Commit Message
Willy Tarreau
Jan. 9, 2023, 7:54 a.m. UTC
Depending on the compiler used and the optimization options, the sbrk()
test was crashing, both on real hardware (mips-24kc) and in qemu. One
such example is kernel.org toolchain in version 11.3 optimizing at -Os.
Inspecting the sys_brk() call shows the following code:
0040047c <sys_brk>:
40047c: 24020fcd li v0,4045
400480: 27bdffe0 addiu sp,sp,-32
400484: 0000000c syscall
400488: 27bd0020 addiu sp,sp,32
40048c: 10e00001 beqz a3,400494 <sys_brk+0x18>
400490: 00021023 negu v0,v0
400494: 03e00008 jr ra
It is obviously wrong, the "negu" instruction is placed in beqz's
delayed slot, and worse, there's no nop nor instruction after the
return, so the next function's first instruction (addiu sip,sip,-32)
will also be executed as part of the delayed slot that follows the
return.
This is caused by the ".set noreorder" directive in the _start block,
that applies to the whole program. The compiler emits code without the
delayed slots and relies on the compiler to swap instructions when this
option is not set. Removing the option would require to change the
startup code in a way that wouldn't make it look like the resulting
code, which would not be easy to debug. Instead let's just save the
default ordering before changing it, and restore it at the end of the
_start block. Now the code is correct:
0040047c <sys_brk>:
40047c: 24020fcd li v0,4045
400480: 27bdffe0 addiu sp,sp,-32
400484: 0000000c syscall
400488: 10e00002 beqz a3,400494 <sys_brk+0x18>
40048c: 27bd0020 addiu sp,sp,32
400490: 00021023 negu v0,v0
400494: 03e00008 jr ra
400498: 00000000 nop
Fixes: 66b6f755ad45 ("rcutorture: Import a copy of nolibc") #5.0
Signed-off-by: Willy Tarreau <w@1wt.eu>
---
tools/include/nolibc/arch-mips.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-mips.h index 5fc5b8029bff..7380093ba9e7 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -192,6 +192,7 @@ struct sys_stat_struct { __asm__ (".section .text\n" ".weak __start\n" ".set nomips16\n" + ".set push\n" ".set noreorder\n" ".option pic0\n" ".ent __start\n" @@ -210,6 +211,7 @@ __asm__ (".section .text\n" "li $v0, 4001\n" // NR_exit == 4001 "syscall\n" ".end __start\n" + ".set pop\n" ""); #endif // _NOLIBC_ARCH_MIPS_H