From patchwork Fri Sep 16 13:25:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Stelmach?= X-Patchwork-Id: 57688 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 1F8813853540 for ; Fri, 16 Sep 2022 13:31:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1F8813853540 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663335065; bh=wCp6pQ6Kdwo5I8i3hRb5+23isO1WGL7AMGSotVL3CUY=; h=To:Subject:Date:References:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=BRmhynDVK0mDA5fEo+ij0iit1KGOxTZGXX+tZ1Q3QgIS7ClVivsfeNaurxsEyKR20 FvYmBhYF1QW9M+lxtlr6u8Z91Qu2WanQFm5T+MhbKEz3xnX+wvBxjgxu8T25nxlb07 93uy9/6i3qUZgOhZKoqNC9XPwuBpUA535Dmb+xkQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by sourceware.org (Postfix) with ESMTPS id 219B83853832 for ; Fri, 16 Sep 2022 13:30:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 219B83853832 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220916133038euoutp02630c1a8fc291079fa60d5b7b7d4da849~VWme5zysI1050810508euoutp027 for ; Fri, 16 Sep 2022 13:30:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220916133038euoutp02630c1a8fc291079fa60d5b7b7d4da849~VWme5zysI1050810508euoutp027 Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220916133038eucas1p2a27d640dbaf02220b4b9a73c28852b10~VWmee-S-Q0211102111eucas1p2V; Fri, 16 Sep 2022 13:30:38 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 90.5C.07817.E7A74236; Fri, 16 Sep 2022 14:30:38 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220916133037eucas1p2aafce0ab15848778ab6b73afc57396fb~VWmeB8Lin0212702127eucas1p2T; Fri, 16 Sep 2022 13:30:37 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220916133037eusmtrp28b0476ede8e214cb6218120902a0d511~VWmeA-H9d0173401734eusmtrp2k; Fri, 16 Sep 2022 13:30:37 +0000 (GMT) X-AuditID: cbfec7f4-8abff70000011e89-c1-63247a7eec83 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 77.7F.07473.D7A74236; Fri, 16 Sep 2022 14:30:37 +0100 (BST) Received: from localhost (unknown [106.120.51.46]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220916133037eusmtip17a4f302cb995abaa7394620b460740ac~VWmd1rgHs2800628006eusmtip1l; Fri, 16 Sep 2022 13:30:37 +0000 (GMT) To: libc-alpha@sourceware.org Subject: [PATCH] RISC-V: Allow long jumps to __syscall_error Date: Fri, 16 Sep 2022 15:25:32 +0200 Message-Id: <20220916132530.1423287-1-l.stelmach@samsung.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Organization: Samsung R&D Institute Poland X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMKsWRmVeSWpSXmKPExsWy7djP87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qc7xftsHqo2OOWxidzh/WB+ LONWwKZJsns8o4w6om1/SvD9mXvu5Zea+45nSpRazfaoyD++4Rr87ZChD1Mex6nFJ5RYijMS DbWYi4oTAQdOQY5NAwAA X-CMS-MailID: 20220916133037eucas1p2aafce0ab15848778ab6b73afc57396fb X-Msg-Generator: CA X-RootMTR: 20220916133037eucas1p2aafce0ab15848778ab6b73afc57396fb X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220916133037eucas1p2aafce0ab15848778ab6b73afc57396fb References: X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?=C5=81ukasz_Stelmach_via_Libc-alpha?= From: =?utf-8?q?=C5=81ukasz_Stelmach?= Reply-To: =?utf-8?q?=C5=81ukasz_Stelmach?= Cc: k.lewandowsk@samsung.com, =?utf-8?q?=C5=81ukasz_Stelmach?= , s.rutka@samsung.com, jh80.chung@samsung.com, alistair.francis@wdc.com, joseph@codesourcery.com, jimw@sifive.com, aurelien@aurel32.net, Marek Szyprowski Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" __syscall_error may end up farther than 1MiB away from a caller, especially when linking statically large binaries. la+jr allow for 4GiB jumps. Fixes: 36960f0c76 ("RISC-V: Linux Syscall Interface") Fixes: 7f33b09c65 ("RISC-V: Linux ABI") Signed-off-by: Ɓukasz Stelmach --- I was compiling and statically linking GNU Guile and I was getting a lot of messages like this: /usr/lib64/libc.a(uname.o): in function `__uname': (.text+0x10): relocation truncated to fit: R_RISCV_JAL against symbol `__syscall_error' defined in .text section in /usr/lib64/libc.a(sysdep.o) And indeed in uname.o there was a relative jump which was marked as R_RISCV_JAL and pointed to __syscall_error. After sucessfully linking the binary with this fix applied __uname and __syscall_error end up 1125000 bytes apart. --8<---------------cut here---------------end--------------->8--- Relocation section '.rela.text' at offset 0x250 contains 4 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000000000 00000000002b R_RISCV_ALIGN 2 000000000002 00000000002b R_RISCV_ALIGN 2 00000000000e 000a00000010 R_RISCV_BRANCH 0000000000000014 .Lsyscall_error__uname + 0 000000000014 000c00000011 R_RISCV_JAL 0000000000000000 __syscall_error + 0 --8<---------------cut here---------------end--------------->8--- --8<---------------cut here---------------end--------------->8--- uname.o: file format elf64-littleriscv Disassembly of section .text: 0000000000000000 <$x>: 0: 0001 nop 2: 0001 nop 0000000000000004 <__uname>: 4: 0a000893 li a7,160 8: 00000073 ecall c: 78fd lui a7,0xfffff e: 00a8e363 bltu a7,a0,14 <.Lsyscall_error__uname> 12: 8082 ret 0000000000000014 <.Lsyscall_error__uname>: 14: fedff06f j 0 <$x> ^^^^ ^^^^^^^^^^^^^^ 18: 8082 ret ... --8<---------------cut here---------------end--------------->8--- I suspect the two nops that the jump points to were meant(?)/could(??) be used (if there were more of them) to be a placeholder for a longer jump. Alas binutils 2.38 can't handle it properly (yet?), so a manual intervention here seems reasonable. I have neither seen any errors regarding code in *context.S and vfork.S files nor tested if the altered code works, but I assume it needs to be fixed as well. sysdeps/unix/sysv/linux/riscv/clone.S | 3 ++- sysdeps/unix/sysv/linux/riscv/getcontext.S | 3 ++- sysdeps/unix/sysv/linux/riscv/setcontext.S | 3 ++- sysdeps/unix/sysv/linux/riscv/swapcontext.S | 3 ++- sysdeps/unix/sysv/linux/riscv/sysdep.h | 3 ++- sysdeps/unix/sysv/linux/riscv/vfork.S | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/sysdeps/unix/sysv/linux/riscv/clone.S b/sysdeps/unix/sysv/linux/riscv/clone.S index d7d2915e87..e716285afa 100644 --- a/sysdeps/unix/sysv/linux/riscv/clone.S +++ b/sysdeps/unix/sysv/linux/riscv/clone.S @@ -63,7 +63,8 @@ L (invalid): li a0, -EINVAL /* Something bad happened -- no child created. */ L (error): - j __syscall_error + la t0, __syscall_error + jr t0 END (__clone) /* Load up the arguments to the function. Put this block of code in diff --git a/sysdeps/unix/sysv/linux/riscv/getcontext.S b/sysdeps/unix/sysv/linux/riscv/getcontext.S index 499f70b65d..a4751ae595 100644 --- a/sysdeps/unix/sysv/linux/riscv/getcontext.S +++ b/sysdeps/unix/sysv/linux/riscv/getcontext.S @@ -70,7 +70,8 @@ LEAF (__getcontext) ret -99: j __syscall_error +99: la t0, __syscall_error + jr t0 PSEUDO_END (__getcontext) diff --git a/sysdeps/unix/sysv/linux/riscv/setcontext.S b/sysdeps/unix/sysv/linux/riscv/setcontext.S index e3bc84a2e6..fddd9d843f 100644 --- a/sysdeps/unix/sysv/linux/riscv/setcontext.S +++ b/sysdeps/unix/sysv/linux/riscv/setcontext.S @@ -92,7 +92,8 @@ LEAF (__setcontext) jr t1 -99: j __syscall_error +99: la t0, __syscall_error + jr t0 END (__setcontext) libc_hidden_def (__setcontext) diff --git a/sysdeps/unix/sysv/linux/riscv/swapcontext.S b/sysdeps/unix/sysv/linux/riscv/swapcontext.S index 4da615f6d4..8e29d96595 100644 --- a/sysdeps/unix/sysv/linux/riscv/swapcontext.S +++ b/sysdeps/unix/sysv/linux/riscv/swapcontext.S @@ -118,7 +118,8 @@ LEAF (__swapcontext) jr t1 -99: j __syscall_error +99: la t0, __syscall_error + jr t0 PSEUDO_END (__swapcontext) diff --git a/sysdeps/unix/sysv/linux/riscv/sysdep.h b/sysdeps/unix/sysv/linux/riscv/sysdep.h index 37ff07a0d7..0cd78daf2b 100644 --- a/sysdeps/unix/sysv/linux/riscv/sysdep.h +++ b/sysdeps/unix/sysv/linux/riscv/sysdep.h @@ -102,7 +102,8 @@ # else # define SYSCALL_ERROR_HANDLER(name) \ .Lsyscall_error ## name: \ - j __syscall_error; + la t0, __syscall_error; \ + jr t0; # endif /* Performs a system call, not setting errno. */ diff --git a/sysdeps/unix/sysv/linux/riscv/vfork.S b/sysdeps/unix/sysv/linux/riscv/vfork.S index 0970543619..8f1b2c9b3a 100644 --- a/sysdeps/unix/sysv/linux/riscv/vfork.S +++ b/sysdeps/unix/sysv/linux/riscv/vfork.S @@ -39,7 +39,8 @@ LEAF (__libc_vfork) bltz a0, 1f ret -1: j __syscall_error +1: la t0, __syscall_error + jr t0 END (__libc_vfork) weak_alias (__libc_vfork, vfork)