From: Alan Modra Date: Mon, 31 Aug 2020 23:29:05 +0000 (+0930) Subject: PR26429 UBSAN: elf32-arm.c load /store misaligned address X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f911bb2201c5642151d06622e6ad3d20d5d8cc7b;p=binutils-gdb.git PR26429 UBSAN: elf32-arm.c load /store misaligned address PR 26429 * elf32-arm.c (elf32_arm_allocate_local_sym_info): Allocate arrays in descending order of alignment. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 20918707f28..1d65c6829f5 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2020-09-01 Alan Modra + + PR 26429 + * elf32-arm.c (elf32_arm_allocate_local_sym_info): Allocate arrays + in descending order of alignment. + 2020-09-01 Alan Modra PR 26423 diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index 4366b766361..6202695ed30 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -3593,27 +3593,40 @@ elf32_arm_allocate_local_sym_info (bfd *abfd) num_syms = elf_tdata (abfd)->symtab_hdr.sh_info; size = num_syms * (sizeof (bfd_signed_vma) - + sizeof (struct arm_local_iplt_info *) + sizeof (bfd_vma) - + sizeof (char) - + sizeof (struct fdpic_local)); + + sizeof (struct arm_local_iplt_info *) + + sizeof (struct fdpic_local) + + sizeof (char)); data = bfd_zalloc (abfd, size); if (data == NULL) return FALSE; - elf32_arm_local_fdpic_cnts (abfd) = (struct fdpic_local *) data; - data += num_syms * sizeof (struct fdpic_local); - + /* It is important that these all be allocated in descending + order of required alignment, so that arrays allocated later + will be sufficiently aligned. */ elf_local_got_refcounts (abfd) = (bfd_signed_vma *) data; data += num_syms * sizeof (bfd_signed_vma); + elf32_arm_local_tlsdesc_gotent (abfd) = (bfd_vma *) data; + data += num_syms * sizeof (bfd_vma); + elf32_arm_local_iplt (abfd) = (struct arm_local_iplt_info **) data; data += num_syms * sizeof (struct arm_local_iplt_info *); - elf32_arm_local_tlsdesc_gotent (abfd) = (bfd_vma *) data; - data += num_syms * sizeof (bfd_vma); + elf32_arm_local_fdpic_cnts (abfd) = (struct fdpic_local *) data; + data += num_syms * sizeof (struct fdpic_local); elf32_arm_local_got_tls_type (abfd) = data; +#if GCC_VERSION >= 3000 + BFD_ASSERT (__alignof__ (*elf32_arm_local_tlsdesc_gotent (abfd)) + <= __alignof__ (*elf_local_got_refcounts (abfd))); + BFD_ASSERT (__alignof__ (*elf32_arm_local_iplt (abfd)) + <= __alignof__ (*elf32_arm_local_tlsdesc_gotent (abfd))); + BFD_ASSERT (__alignof__ (*elf32_arm_local_fdpic_cnts (abfd)) + <= __alignof__ (*elf32_arm_local_iplt (abfd))); + BFD_ASSERT (__alignof__ (*elf32_arm_local_got_tls_type (abfd)) + <= __alignof__ (*elf32_arm_local_fdpic_cnts (abfd))); +#endif } return TRUE; }