aboutsummaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorPalmer Dabbelt <palmer@rivosinc.com>2022-06-23 14:49:32 -0700
committerAndreas K. Hüttel <dilfridge@gentoo.org>2024-06-26 12:45:43 +0200
commit07fe71f59b13bbc336ece3ec9ef94dd95c9e0511 (patch)
treedb2786b8cafcf6a57e66225af50ddaaa2a8583d2 /sysdeps
parenta10b6ad471d7b528149f5ff32eef2f1c1dc1213c (diff)
downloadglibc-07fe71f59b13bbc336ece3ec9ef94dd95c9e0511.zip
glibc-07fe71f59b13bbc336ece3ec9ef94dd95c9e0511.tar.gz
glibc-07fe71f59b13bbc336ece3ec9ef94dd95c9e0511.tar.bz2
arm: Avoid UB in elf_machine_rel()
This recently came up during a cleanup to remove misaligned accesses from the RISC-V port. Link: https://sourceware.org/pipermail/libc-alpha/2022-June/139961.html Suggested-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com> Reviewed-by: Fangrui Song <maskray@google.com>
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/arm/dl-machine.h9
1 files changed, 4 insertions, 5 deletions
diff --git a/sysdeps/arm/dl-machine.h b/sysdeps/arm/dl-machine.h
index dd1a0f6..9186831 100644
--- a/sysdeps/arm/dl-machine.h
+++ b/sysdeps/arm/dl-machine.h
@@ -349,10 +349,7 @@ elf_machine_rel (struct link_map *map, struct r_scope_elem *scope[],
break;
case R_ARM_ABS32:
{
- struct unaligned
- {
- Elf32_Addr x;
- } __attribute__ ((packed, may_alias));
+ ElfW(Addr) tmp;
# ifndef RTLD_BOOTSTRAP
/* This is defined in rtld.c, but nowhere in the static
libc.a; make the reference weak so static programs can
@@ -372,7 +369,9 @@ elf_machine_rel (struct link_map *map, struct r_scope_elem *scope[],
value -= SYMBOL_ADDRESS (map, refsym, true);
# endif
/* Support relocations on mis-aligned offsets. */
- ((struct unaligned *) reloc_addr)->x += value;
+ memcpy (&tmp, reloc_addr, sizeof tmp);
+ tmp += value;
+ memcpy (reloc_addr, &tmp, sizeof tmp);
break;
}
case R_ARM_TLS_DESC: