binutils: Add a new function to initialise DWARF register name state
[deliverable/binutils-gdb.git] / binutils / dwarf.c
index 19ae1edca7649ec8572cc86cd7818f63b5d81872..a770c57f6083416ef2fa32d4526c310366f5bb78 100644 (file)
@@ -1848,16 +1848,9 @@ check_uvalue (const unsigned char * start,
 {
   dwarf_vma max_uvalue = end - start;
 
-  /* FIXME: Testing "(start + uvalue) < start" miscompiles with gcc 4.8.3
-     running on an x86_64 host in 32-bit mode.  So we pre-compute the value
-     here.  */
-  const unsigned char * ptr = start + uvalue;
-
   /* See PR 17512: file: 008-103549-0.001:0.1.
      and PR 24829 for examples of where these tests are triggered.  */
-  if (uvalue > max_uvalue
-      || ptr > end
-      || ptr < start)
+  if (uvalue > max_uvalue)
     {
       warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
       uvalue = max_uvalue;
@@ -2006,9 +1999,6 @@ get_type_signedness (unsigned char *        start,
 
   * is_signed = FALSE;
 
-  if (data >= end)
-    return;
-
   abbrev_number = read_uleb128 (data, & bytes_read, end);
   data += bytes_read;
 
@@ -2049,6 +2039,8 @@ get_type_signedness (unsigned char *        start,
                 NB/ We need to avoid infinite recursion.  */
              return;
            }
+         if (uvalue >= (size_t) (end - start))
+           return;
          get_type_signedness (start, start + uvalue, end, pointer_size,
                               offset_size, dwarf_version, is_signed, TRUE);
          break;
@@ -2732,7 +2724,8 @@ read_and_display_attr_value (unsigned long           attribute,
   switch (attribute)
     {
     case DW_AT_type:
-      if (level >= 0 && level < MAX_CU_NESTING)
+      if (level >= 0 && level < MAX_CU_NESTING
+         && uvalue < (size_t) (end - start))
        {
          bfd_boolean is_signed = FALSE;
 
@@ -7385,7 +7378,7 @@ frame_need_space (Frame_Chunk *fc, unsigned int reg)
   if (reg < (unsigned int) fc->ncols)
     return 0;
 
-  if (dwarf_regnames_count
+  if (dwarf_regnames_count > 0
       && reg > dwarf_regnames_count)
     return -1;
 
@@ -7396,7 +7389,7 @@ frame_need_space (Frame_Chunk *fc, unsigned int reg)
     return -1;
 
   /* PR 17512: file: 2844a11d.  */
-  if (fc->ncols > 1024)
+  if (fc->ncols > 1024 && dwarf_regnames_count == 0)
     {
       error (_("Unfeasibly large register number: %u\n"), reg);
       fc->ncols = 0;
@@ -7597,7 +7590,7 @@ init_dwarf_regnames_riscv (void)
 }
 
 void
-init_dwarf_regnames (unsigned int e_machine)
+init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine)
 {
   switch (e_machine)
     {
@@ -7632,6 +7625,54 @@ init_dwarf_regnames (unsigned int e_machine)
     }
 }
 
+/* Initialize the DWARF register name lookup state based on the
+   architecture and specific machine type of a BFD.  */
+
+void
+init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch,
+                                         unsigned long mach)
+{
+  switch (arch)
+    {
+    case bfd_arch_i386:
+      switch (mach)
+       {
+       case bfd_mach_x86_64:
+       case bfd_mach_x86_64_intel_syntax:
+       case bfd_mach_x86_64_nacl:
+       case bfd_mach_x64_32:
+       case bfd_mach_x64_32_intel_syntax:
+       case bfd_mach_x64_32_nacl:
+         init_dwarf_regnames_x86_64 ();
+         break;
+
+       default:
+         init_dwarf_regnames_i386 ();
+         break;
+       }
+      break;
+
+    case bfd_arch_iamcu:
+      init_dwarf_regnames_iamcu ();
+      break;
+
+    case bfd_arch_aarch64:
+      init_dwarf_regnames_aarch64();
+      break;
+
+    case bfd_arch_s390:
+      init_dwarf_regnames_s390 ();
+      break;
+
+    case bfd_arch_riscv:
+      init_dwarf_regnames_riscv ();
+      break;
+
+    default:
+      break;
+    }
+}
+
 static const char *
 regname (unsigned int regno, int row)
 {
This page took 0.024223 seconds and 4 git commands to generate.