From: zengxiao@eswincomputing.com
To: binutils@sourceware.org
Cc: shihua@iscas.ac.cn, nelson@rivosinc.com, palmer@dabbelt.com,
kito.cheng@gmail.com, Xiao Zeng <zengxiao@eswincomputing.com>
Subject: [PATCH v2] RISC-V: Make R_RISCV_SUB6 conforms to riscv ABI standard
Date: Mon, 21 Nov 2022 20:00:37 +0800 [thread overview]
Message-ID: <20221121120037.19325-1-zengxiao@eswincomputing.com> (raw)
From: Xiao Zeng <zengxiao@eswincomputing.com>
The R_RISCV_SUB6 only the lower 6 bits of the code are valid, which
can be found in 8.5. Relocations of:
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/releases/download/v1.0-rc4/riscv-abi.pdf
bfd/ChangeLog:
* elfnn-riscv.c (riscv_elf_relocate_section): Take the R_RISCV_SUB6
lower 6 bits as the significant bit.
* elfxx-riscv.c (riscv_elf_add_sub_reloc): Likewise.
---
bfd/elfnn-riscv.c | 4 ++++
bfd/elfxx-riscv.c | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 0570a971b5a..a02aa64786e 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -2427,6 +2427,10 @@ riscv_elf_relocate_section (bfd *output_bfd,
break;
case R_RISCV_SUB6:
+ relocation = (old_value & ~howto->dst_mask)
+ | (((old_value & howto->dst_mask) - relocation)
+ & howto->dst_mask);
+ break;
case R_RISCV_SUB8:
case R_RISCV_SUB16:
case R_RISCV_SUB32:
diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
index afbde56b9e5..2db24acf7a5 100644
--- a/bfd/elfxx-riscv.c
+++ b/bfd/elfxx-riscv.c
@@ -994,6 +994,10 @@ riscv_elf_add_sub_reloc (bfd *abfd,
relocation = old_value + relocation;
break;
case R_RISCV_SUB6:
+ relocation = (old_value & ~howto->dst_mask)
+ | (((old_value & howto->dst_mask) - relocation)
+ & howto->dst_mask);
+ break;
case R_RISCV_SUB8:
case R_RISCV_SUB16:
case R_RISCV_SUB32:
--
2.34.1
next reply other threads:[~2022-11-21 12:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-21 12:00 zengxiao [this message]
2022-11-23 2:52 ` Nelson Chu
2022-11-23 9:05 ` Xiao Zeng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221121120037.19325-1-zengxiao@eswincomputing.com \
--to=zengxiao@eswincomputing.com \
--cc=binutils@sourceware.org \
--cc=kito.cheng@gmail.com \
--cc=nelson@rivosinc.com \
--cc=palmer@dabbelt.com \
--cc=shihua@iscas.ac.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).