From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by sourceware.org (Postfix) with ESMTPS id 17B2B38197D3 for ; Fri, 16 Sep 2022 17:25:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 17B2B38197D3 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-qt1-x835.google.com with SMTP id g23so11909810qtu.2 for ; Fri, 16 Sep 2022 10:25:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date; bh=a8UB0TLR0DtWi9XVZvNeGFCjdyVCLQGmhSw0yIdntu0=; b=gMw92sXAybpmHS/tDnzXcgz+FjIPNUlqRAEjX7Z6M65Lyeah0Z76ZMn9J+sIxK/5K0 CGSJyPb96XFME6l4bh0dptu/9h2qxcnNUFSJvFTZl2iw6LdzUzwmbDEU9cxa+rBA0qp1 END2uArdt+Tw8OiWFMB/5p1mXpmJKEwn+Q+vnAd5KjVbHvs8jvjfh6FK/rXiElADJ+H8 ILD24fGdZw3S0pA0fleVuhlHcfGqoJ12N9ctacf1oXAkRhhr2Z97RJUb4fGAerCWvFWi IfQ2BE/XDqSDpXB58oKtJ88kbkonHyvXg5LBYwRtl40FCNXO/WfYZXggrWSuqqJhI9RJ 6xmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date; bh=a8UB0TLR0DtWi9XVZvNeGFCjdyVCLQGmhSw0yIdntu0=; b=a1UO90LYqVU8xpBMuzv6OEWcakSVzI1Woledtw0QBIG/XVwu6c/OU5cgYIbnDrCB4z gU/0C+Lqpuqn/5dlls9A9bakjWlWRc0we7Ev0TH1/JcX8kCggFujvTUGek0MSJuXARAk puoBJk3aQ9najaeBiIs09Bp8eIN5VA962Olc3xy29xC3ggbXUVEVGq2f9Cc71cIums69 B1vJ7JF17ymQC7qVk2/ABMPG5N1cSfnN2QHGKDGBHXREarNlQEJ/CJP0RCaxNHdsp2Iq /GmsIGUBYhNkOGMieluZ1Ezgbzpdlx/3/pNTS/yJZoex4jpOntFFyNNi43TxkAaHonqS eVIQ== X-Gm-Message-State: ACrzQf1+UmjItBjtLz/36Ze/hZ5wG9croEUF/N5BQggfCd7TEIEPmrT9 zgGBV9quuReE40rVhLiEc138rO9a9YSqZw== X-Google-Smtp-Source: AMsMyM7//nkl7EqjDvVQUwDjuOH+G+VZrlTSQs0dzco25ROojlozLvWZFgvh8CHXpkm1S5VPKLGOww== X-Received: by 2002:a05:622a:310:b0:344:89e4:cf8a with SMTP id q16-20020a05622a031000b0034489e4cf8amr5374081qtw.206.1663349135232; Fri, 16 Sep 2022 10:25:35 -0700 (PDT) Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com. [209.85.219.181]) by smtp.gmail.com with ESMTPSA id i18-20020a05620a249200b006b5e296452csm6766231qkn.54.2022.09.16.10.25.33 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Sep 2022 10:25:34 -0700 (PDT) Received: by mail-yb1-f181.google.com with SMTP id c9so33517031ybf.5 for ; Fri, 16 Sep 2022 10:25:33 -0700 (PDT) X-Received: by 2002:a25:4045:0:b0:6ae:b15a:cd81 with SMTP id n66-20020a254045000000b006aeb15acd81mr5090594yba.340.1663349133575; Fri, 16 Sep 2022 10:25:33 -0700 (PDT) MIME-Version: 1.0 References: <20220916132530.1423287-1-l.stelmach@samsung.com> In-Reply-To: <20220916132530.1423287-1-l.stelmach@samsung.com> From: Andrew Waterman Date: Fri, 16 Sep 2022 10:25:22 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] RISC-V: Allow long jumps to __syscall_error To: =?UTF-8?Q?=C5=81ukasz_Stelmach?= Cc: libc-alpha@sourceware.org, k.lewandowsk@samsung.com, s.rutka@samsung.com, jh80.chung@samsung.com, alistair.francis@wdc.com, joseph@codesourcery.com, jimw@sifive.com, aurelien@aurel32.net, Marek Szyprowski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 List-Id: Use the `tail` pseudoinstruction rather than `la` + `jr`, as this will relax to `j` when within range. On Fri, Sep 16, 2022 at 6:31 AM =C5=81ukasz Stelmach via Libc-alpha wrote: > > __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: =C5=81ukasz 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_e= rror__uname + 0 > 000000000014 000c00000011 R_RISCV_JAL 0000000000000000 __syscall_e= rror + 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/li= nux/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/sy= sv/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/sy= sv/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/s= ysv/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/l= inux/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/li= nux/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) > -- > 2.30.2 >