This is the mail archive of the
libc-ports@sources.redhat.com
mailing list for the libc-ports project.
Re: [PATCH v2] arm: handle unaligned ABS relocs
- From: "Carlos O'Donell" <carlos at systemhalted dot org>
- To: Mike Frysinger <vapier at gentoo dot org>
- Cc: libc-ports at sourceware dot org, Richard Henderson <rth at twiddle dot net>, "Joseph S. Myers" <joseph at codesourcery dot com>
- Date: Sun, 12 Aug 2012 09:26:42 -0400
- Subject: Re: [PATCH v2] arm: handle unaligned ABS relocs
- References: <201112121920.17908.vapier@gentoo.org> <1344750618-13673-1-git-send-email-vapier@gentoo.org>
On Sun, Aug 12, 2012 at 1:50 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> When relocating a misaligned R_ARM_ABS32, glibc currently crashes.
>
> URL: https://bugs.gentoo.org/394237
> URL: http://gcc.gnu.org/PR51456
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
>
> 2012-08-12 Mike Frysinger <vapier@gentoo.org>
>
> * sysdeps/arm/dl-machine.h (elf_machine_rel) [R_ARM_ABS32]: Declare
> a new unaligned struct. Cast reloc_addr to that when updating the
> value it points to.
Almost every other architecture that does this uses a char array and pulls the
data out of the char array. Why?
> ---
> ports/sysdeps/arm/dl-machine.h | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/ports/sysdeps/arm/dl-machine.h b/ports/sysdeps/arm/dl-machine.h
> index fe39a5e..ca66e83 100644
> --- a/ports/sysdeps/arm/dl-machine.h
> +++ b/ports/sysdeps/arm/dl-machine.h
> @@ -413,6 +413,10 @@ elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc,
> break;
> case R_ARM_ABS32:
> {
> + struct unaligned
> + {
> + Elf32_Addr x;
> + } __attribute__((packed, may_alias));
Packed only says that the internals of the structure will be packed
with minimal alignment.
It doesn't say anything about the alignment of the structure itself IIRC.
Will this actually do what you want consistently and across supported
compiler versions?
As opposed to the char array method used by other machines.
> # ifndef RTLD_BOOTSTRAP
> /* This is defined in rtld.c, but nowhere in the static
> libc.a; make the reference weak so static programs can
> @@ -431,7 +435,8 @@ elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc,
> used while loading those libraries. */
> value -= map->l_addr + refsym->st_value;
> # endif
> - *reloc_addr += value;
> + /* Support relocations on mis-aligned offsets. */
> + ((struct unaligned *) reloc_addr)->x += value;
> break;
> }
> case R_ARM_TLS_DESC:
> --
> 1.7.9.7
>
Cheers,
Carlos.