From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1992) id 29C563857367; Thu, 30 Jun 2022 15:06:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 29C563857367 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Palmer Dabbelt To: glibc-cvs@sourceware.org Subject: [glibc] riscv: Use memcpy to handle unaligned access when fixing R_RISCV_RELATIVE X-Act-Checkin: glibc X-Git-Author: Kito Cheng X-Git-Refname: refs/heads/master X-Git-Oldrev: e9dd3682963a7038d699430e3ece68045b6caafc X-Git-Newrev: c22d2021a9f9bdea62398976eea4f0e6ef668b7d Message-Id: <20220630150618.29C563857367@sourceware.org> Date: Thu, 30 Jun 2022 15:06:18 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Jun 2022 15:06:18 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;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: ARM: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51456 MIPS: https://gcc.gnu.org/legacy-ml/gcc-help/2005-07/msg00325.html Reviewed-by: Adhemerval Zanella Diff: --- 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