public inbox for
help / color / mirror / Atom feed
From: Palmer Dabbelt <>
Subject: [glibc] riscv: Use memcpy to handle unaligned access when fixing R_RISCV_RELATIVE
Date: Thu, 30 Jun 2022 15:06:18 +0000 (GMT)	[thread overview]
Message-ID: <> (raw);h=c22d2021a9f9bdea62398976eea4f0e6ef668b7d

commit c22d2021a9f9bdea62398976eea4f0e6ef668b7d
Author: Kito Cheng <>
Date:   Tue Jun 28 21:52:19 2022 +0800

    riscv: Use memcpy to handle unaligned access when fixing R_RISCV_RELATIVE
    Although RISC-V Linux will enable the unaligned memory access handler by
    default, that is quite expensive in general, using memcpy will be much cheaper
    - just break down that into several load/store byte instructions.
    ARM and MIPS has similar issue:
    Reviewed-by: Adhemerval Zanella  <>

 sysdeps/riscv/dl-machine.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h
index 4bb858adaa..dfedc9801d 100644
--- a/sysdeps/riscv/dl-machine.h
+++ b/sysdeps/riscv/dl-machine.h
@@ -157,7 +157,10 @@ __attribute__ ((always_inline))
 elf_machine_rela_relative (ElfW(Addr) l_addr, const ElfW(Rela) *reloc,
 			  void *const reloc_addr)
-  *(ElfW(Addr) *) reloc_addr = l_addr + reloc->r_addend;
+  /* R_RISCV_RELATIVE might located in debug info section which might not
+     aligned to XLEN bytes.  Also support relocations on unaligned offsets.  */
+  ElfW(Addr) value = l_addr + reloc->r_addend;
+  memcpy (reloc_addr, &value, sizeof value);
 /* Perform a relocation described by R_INFO at the location pointed to

                 reply	other threads:[~2022-06-30 15:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \

* 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).