mirror of
git://sourceware.org/git/glibc.git
synced 2025-03-06 20:58:33 +01:00
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>
This commit is contained in:
parent
a10b6ad471
commit
07fe71f59b
1 changed files with 4 additions and 5 deletions
|
@ -349,10 +349,7 @@ elf_machine_rel (struct link_map *map, struct r_scope_elem *scope[],
|
||||||
break;
|
break;
|
||||||
case R_ARM_ABS32:
|
case R_ARM_ABS32:
|
||||||
{
|
{
|
||||||
struct unaligned
|
ElfW(Addr) tmp;
|
||||||
{
|
|
||||||
Elf32_Addr x;
|
|
||||||
} __attribute__ ((packed, may_alias));
|
|
||||||
# ifndef RTLD_BOOTSTRAP
|
# ifndef RTLD_BOOTSTRAP
|
||||||
/* This is defined in rtld.c, but nowhere in the static
|
/* This is defined in rtld.c, but nowhere in the static
|
||||||
libc.a; make the reference weak so static programs can
|
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);
|
value -= SYMBOL_ADDRESS (map, refsym, true);
|
||||||
# endif
|
# endif
|
||||||
/* Support relocations on mis-aligned offsets. */
|
/* 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;
|
break;
|
||||||
}
|
}
|
||||||
case R_ARM_TLS_DESC:
|
case R_ARM_TLS_DESC:
|
||||||
|
|
Loading…
Add table
Reference in a new issue