PowerPC64 ha/lo insn checks
[external/binutils.git] / bfd / syms.c
index 187071f..da1c90d 100644 (file)
@@ -1,5 +1,5 @@
 /* Generic symbol-table support for the BFD library.
-   Copyright (C) 1990-2018 Free Software Foundation, Inc.
+   Copyright (C) 1990-2019 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -595,8 +595,9 @@ static const struct section_to_type stt[] =
 /* Return the single-character symbol type corresponding to
    section S, or '?' for an unknown COFF section.
 
-   Check for any leading string which matches, so .text5 returns
-   't' as well as .text */
+   Check for leading strings which match, followed by a number, '.',
+   or '$' so .text5 matches the .text entry, but .init_array doesn't
+   match the .init entry.  */
 
 static char
 coff_section_type (const char *s)
@@ -604,8 +605,12 @@ coff_section_type (const char *s)
   const struct section_to_type *t;
 
   for (t = &stt[0]; t->section; t++)
-    if (!strncmp (s, t->section, strlen (t->section)))
-      return t->type;
+    {
+      size_t len = strlen (t->section);
+      if (strncmp (s, t->section, len) == 0
+         && memchr (".$0123456789", s[len], 13) != 0)
+       return t->type;
+    }
 
   return '?';
 }
@@ -700,9 +705,9 @@ bfd_decode_symclass (asymbol *symbol)
     c = 'a';
   else if (symbol->section)
     {
-      c = coff_section_type (symbol->section->name);
+      c = decode_section_type (symbol->section);
       if (c == '?')
-       c = decode_section_type (symbol->section);
+       c = coff_section_type (symbol->section->name);
     }
   else
     return '?';
@@ -822,9 +827,16 @@ _bfd_generic_read_minisymbols (bfd *abfd,
   if (symcount < 0)
     goto error_return;
 
-  *minisymsp = syms;
-  *sizep = sizeof (asymbol *);
-
+  if (symcount == 0)
+    /* We return 0 above when storage is 0.  Exit in the same state
+       here, so as to not complicate callers with having to deal with
+       freeing memory for zero symcount.  */
+    free (syms);
+  else
+    {
+      *minisymsp = syms;
+      *sizep = sizeof (asymbol *);
+    }
   return symcount;
 
  error_return:
@@ -1035,6 +1047,10 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
                                         0, strsize))
        return FALSE;
 
+      /* Stab strings ought to be nul terminated.  Ensure the last one
+        is, to prevent running off the end of the buffer.  */
+      info->strs[strsize - 1] = 0;
+
       /* If this is a relocatable object file, we have to relocate
         the entries in .stab.  This should always be simple 32 bit
         relocations against symbols defined in this object file, so
@@ -1073,7 +1089,8 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
                  || r->howto->bitsize != 32
                  || r->howto->pc_relative
                  || r->howto->bitpos != 0
-                 || r->howto->dst_mask != 0xffffffff)
+                 || r->howto->dst_mask != 0xffffffff
+                 || r->address * bfd_octets_per_byte (abfd) + 4 > stabsize)
                {
                  _bfd_error_handler
                    (_("unsupported .stab relocation"));
@@ -1195,7 +1212,8 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
                {
                  nul_fun = stab;
                  nul_str = str;
-                 if (file_name >= (char *) info->strs + strsize || file_name < (char *) str)
+                 if (file_name >= (char *) info->strs + strsize
+                     || file_name < (char *) str)
                    file_name = NULL;
                  if (stab + STABSIZE + TYPEOFF < info->stabs + stabsize
                      && *(stab + STABSIZE + TYPEOFF) == (bfd_byte) N_SO)
@@ -1206,7 +1224,8 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
                      directory_name = file_name;
                      file_name = ((char *) str
                                   + bfd_get_32 (abfd, stab + STRDXOFF));
-                     if (file_name >= (char *) info->strs + strsize || file_name < (char *) str)
+                     if (file_name >= (char *) info->strs + strsize
+                         || file_name < (char *) str)
                        file_name = NULL;
                    }
                }
@@ -1217,7 +1236,8 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
              file_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF);
              /* PR 17512: file: 0c680a1f.  */
              /* PR 17512: file: 5da8aec4.  */
-             if (file_name >= (char *) info->strs + strsize || file_name < (char *) str)
+             if (file_name >= (char *) info->strs + strsize
+                 || file_name < (char *) str)
                file_name = NULL;
              break;
 
@@ -1226,7 +1246,8 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
              function_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF);
              if (function_name == (char *) str)
                continue;
-             if (function_name >= (char *) info->strs + strsize)
+             if (function_name >= (char *) info->strs + strsize
+                 || function_name < (char *) str)
                function_name = NULL;
 
              nul_fun = NULL;
@@ -1335,7 +1356,8 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
          if (val <= offset)
            {
              file_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF);
-             if (file_name >= (char *) info->strs + strsize || file_name < (char *) str)
+             if (file_name >= (char *) info->strs + strsize
+                 || file_name < (char *) str)
                file_name = NULL;
              *pline = 0;
            }