Fix problems with the AArch64 linker exposed by testing it with sanitization enabled.
authorNick Clifton <nickc@redhat.com>
Fri, 21 Aug 2020 14:32:20 +0000 (15:32 +0100)
committerNick Clifton <nickc@redhat.com>
Fri, 21 Aug 2020 14:32:20 +0000 (15:32 +0100)
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
bfd/elfnn-aarch64.c
opcodes/ChangeLog
opcodes/aarch64-dis.c

index 62407f987aa2ca3ba4c3e102970b7b641dec2510..d7853371c6a23f12a642940de5fb692b14caec13 100644 (file)
@@ -1,3 +1,9 @@
+2020-08-21  Nick Clifton  <nickc@redhat.com>
+
+       * 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  <jbeulich@suse.com>
 
        * peXXigen.c (_bfd_XX_bfd_copy_private_bfd_data_common): Check
index a1c888722786b955b32fed490d56ab526173f215..9b0b51b4fb0199d39dd1c42a88646b4666bcdd78 100644 (file)
@@ -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++)
        {
index 6578fbf37f03ac53e74030620e03203c8d7281fa..55ea7c7f78374dde6a5d33420135dee85a900a43 100644 (file)
@@ -1,3 +1,8 @@
+2020-08-21  Nick Clifton  <nickc@redhat.com>
+
+       * aarch64-dis.c (get_sym_code_type): Return FALSE for non-ELF
+       symbols.
+
 2020-08-21  Cooper Qu  <cooper.qu@linux.alibaba.com>
 
        * csky-opc.h (csky_v2_opcodes): Add two operands form for bloop.
index 6567880efbaaeea5e1f2aa026df99059e9bb7471..326fabb71687d18d911e1de0ac4b7495b01d832f 100644 (file)
@@ -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.  */