From ccf61261eb8cce869ae4452de547a5f3afb074e4 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Fri, 21 Aug 2020 15:32:20 +0100 Subject: Fix problems with the AArch64 linker exposed by testing it with sanitization enabled. bfd * elfnn-aarch64.c (_bfd_aarch64_erratum_835769_scan): Only sort the data map if there are entries in it. (_bfd_aarch64_erratum_843419_scan): Likewise. opcodes * aarch64-dis.c (get_sym_code_type): Return FALSE for non-ELF symbols. --- bfd/ChangeLog | 6 ++++++ bfd/elfnn-aarch64.c | 10 ++++++---- opcodes/ChangeLog | 5 +++++ opcodes/aarch64-dis.c | 10 +++++++++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 62407f9..d785337 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2020-08-21 Nick Clifton + + * elfnn-aarch64.c (_bfd_aarch64_erratum_835769_scan): Only sort + the data map if there are entries in it. + (_bfd_aarch64_erratum_843419_scan): Likewise. + 2020-08-21 Jan Beulich * peXXigen.c (_bfd_XX_bfd_copy_private_bfd_data_common): Check diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index a1c8887..9b0b51b 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -3925,8 +3925,9 @@ _bfd_aarch64_erratum_835769_scan (bfd *input_bfd, sec_data = elf_aarch64_section_data (section); - qsort (sec_data->map, sec_data->mapcount, - sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping); + if (sec_data->mapcount) + qsort (sec_data->map, sec_data->mapcount, + sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping); for (span = 0; span < sec_data->mapcount; span++) { @@ -4209,8 +4210,9 @@ _bfd_aarch64_erratum_843419_scan (bfd *input_bfd, asection *section, sec_data = elf_aarch64_section_data (section); - qsort (sec_data->map, sec_data->mapcount, - sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping); + if (sec_data->mapcount) + qsort (sec_data->map, sec_data->mapcount, + sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping); for (span = 0; span < sec_data->mapcount; span++) { diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index 6578fbf..55ea7c7 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,3 +1,8 @@ +2020-08-21 Nick Clifton + + * aarch64-dis.c (get_sym_code_type): Return FALSE for non-ELF + symbols. + 2020-08-21 Cooper Qu * csky-opc.h (csky_v2_opcodes): Add two operands form for bloop. diff --git a/opcodes/aarch64-dis.c b/opcodes/aarch64-dis.c index 6567880..326fabb 100644 --- a/opcodes/aarch64-dis.c +++ b/opcodes/aarch64-dis.c @@ -3321,6 +3321,7 @@ static int get_sym_code_type (struct disassemble_info *info, int n, enum map_type *map_type) { + asymbol * as; elf_symbol_type *es; unsigned int type; const char *name; @@ -3329,7 +3330,14 @@ get_sym_code_type (struct disassemble_info *info, int n, if (info->section != NULL && info->section != info->symtab[n]->section) return FALSE; - es = *(elf_symbol_type **)(info->symtab + n); + if (n >= info->symtab_size) + return FALSE; + + as = info->symtab[n]; + if (bfd_asymbol_flavour (as) != bfd_target_elf_flavour) + return FALSE; + es = (elf_symbol_type *) as; + type = ELF_ST_TYPE (es->internal_elf_sym.st_info); /* If the symbol has function type then use that. */ -- cgit v1.1