This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 53a2fa47012 libc/sim: write ELF64 relocations without unaligned stores
53a2fa47012 is described below

commit 53a2fa47012a606a0d286f4cfcbaf4c75f2f006e
Author: anjiahao <[email protected]>
AuthorDate: Fri Nov 27 01:07:47 2026 +0800

    libc/sim: write ELF64 relocations without unaligned stores
    
    R_X86_64_64 and R_X86_64_PC64 store a 64-bit value straight
    through the relocation address, which is not necessarily 8-byte
    aligned; on a strict-alignment host the store traps.  Build the value
    in a local and copy it with memcpy.
    
    Signed-off-by: anjiahao <[email protected]>
---
 libs/libc/machine/sim/arch_elf64.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libs/libc/machine/sim/arch_elf64.c 
b/libs/libc/machine/sim/arch_elf64.c
index a6457d5e222..7e6bbc4cac2 100644
--- a/libs/libc/machine/sim/arch_elf64.c
+++ b/libs/libc/machine/sim/arch_elf64.c
@@ -33,6 +33,7 @@
 #include <nuttx/config.h>
 
 #include <stdlib.h>
+#include <string.h>
 #include <errno.h>
 #include <nuttx/debug.h>
 #include <assert.h>
@@ -171,7 +172,8 @@ int up_relocateadd(const Elf64_Rela *rel, const Elf64_Sym 
*sym,
   switch (relotype)
     {
       case R_X86_64_64: /* S + A */
-        *(uint64_t *)addr = sym->st_value + rel->r_addend;
+        value = sym->st_value + rel->r_addend;
+        memcpy((void *)addr, &value, sizeof(value));
         break;
       case R_X86_64_PC32:  /* S + A - P */
       case R_X86_64_PLT32: /* L + A - P */
@@ -186,7 +188,7 @@ int up_relocateadd(const Elf64_Rela *rel, const Elf64_Sym 
*sym,
         break;
       case R_X86_64_PC64:  /* S + A - P */
         value = sym->st_value + rel->r_addend - addr;
-        *(uint64_t *)addr = value;
+        memcpy((void *)addr, &value, sizeof(value));
         break;
       case R_X86_64_32:  /* S + A */
       case R_X86_64_32S: /* S + A */

Reply via email to