]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Synchronize libiberty sources with gcc mainline.
authorNick Clifton <nickc@redhat.com>
Fri, 9 Aug 2019 15:16:18 +0000 (16:16 +0100)
committerNick Clifton <nickc@redhat.com>
Fri, 9 Aug 2019 15:16:18 +0000 (16:16 +0100)
* libiberty: Sync with gcc.  Bring in:
2019-08-08  Martin Liska  <mliska@suse.cz>

PR bootstrap/91352
* lrealpath.c (is_valid_fd): New function.

2019-07-24  Martin Liska  <mliska@suse.cz>

PR lto/91228
* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
Find first '\0' starting from gnu_lto + 1.

2019-07-12  Ren Kimura  <rkx1209dev@gmail.com>

* simple-object-elf.c (simple_object_elf_match): Check zero value shstrndx.
This fixes a Bug 90924.

2019-07-22  Martin Liska  <mliska@suse.cz>

* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
Do not search for gnu_lto_v1, but search for first '\0'.

2019-07-18  Eduard-Mihai Burtescu  <eddyb@lyken.rs>

* cplus-dem.c: Include rust-demangle.h.
* rust-demangle.c: Include rust-demangle.h.
* rust-demangle.h: New file.

2019-05-31  Michael Forney  <mforney@mforney.org>

* cp-demangle.c: Don't define CP_DYNAMIC_ARRAYS if __STDC_NO_VLA__
is non-zero.

2019-04-30  Ben L  <bobsayshilol@live.co.uk>

* d-demangle.c (dlang_parse_assocarray): Correctly handle error result.
* testsuite/d-demangle-expected: Add testcase.

* d-demangle.c (dlang_parse_tuple): Correctly handle error result.
* testsuite/d-demangle-expected: Add testcase.

* d-demangle.c (dlang_parse_structlit): Correctly handle error result.
* testsuite/d-demangle-expected: Add testcase.

* d-demangle.c (dlang_parse_arrayliteral): Correctly handle error result.
* testsuite/d-demangle-expected: Add testcase.

* d-demangle.c (dlang_parse_integer): Fix stack underflow.
* testsuite/d-demangle-expected: Add testcase.

* cp-demangle (d_print_comp_inner): Guard against a NULL 'typed_name'.
* testsuite/demangle-expected: Add testcase.

* cp-demangle.c (d_encoding): Guard against NULL return values from
d_right (dc).
* testsuite/demangle-expected: Add testcase.

2019-04-29  Ben L  <bobsayshilol@live.co.uk>

* cp-demangle.c (d_expression_1): Don't peek ahead unless the current
char is valid.
* testsuite/demangle-expected: Add testcase.

2019-04-10  Nick Clifton  <nickc@redhat.com>

PR 89394
* cp-demangle.c (cplus_demangle_fill_name): Reject negative
lengths.
(d_count_templates_scopes): Replace num_templates and num_scopes
parameters with a struct d_print_info pointer parameter.  Adjust
body of the function accordingly.  Add recursion counter and check
that the recursion limit is not reached.
(d_print_init): Pass dpi parameter to d_count_templates_scopes.
Reset recursion counter afterwards, unless the recursion limit was
reached.

ChangeLog
libiberty/ChangeLog
libiberty/cp-demangle.c
libiberty/cplus-dem.c
libiberty/d-demangle.c
libiberty/lrealpath.c
libiberty/rust-demangle.c
libiberty/rust-demangle.h [new file with mode: 0644]
libiberty/simple-object-elf.c
libiberty/testsuite/d-demangle-expected
libiberty/testsuite/demangle-expected

index 52d97d5fb8b550128558fa041c9b5f708190d87a..15615559bf978312373c1c798837782bd288b028 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,81 @@
+2019-08-09  Nick Clifton  <nickc@redhat.com>
+
+       * libiberty: Sync with gcc.  Bring in:
+       2019-08-08  Martin Liska  <mliska@suse.cz>
+
+       PR bootstrap/91352
+       * lrealpath.c (is_valid_fd): New function.
+
+       2019-07-24  Martin Liska  <mliska@suse.cz>
+
+       PR lto/91228
+       * simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
+       Find first '\0' starting from gnu_lto + 1.
+
+       2019-07-12  Ren Kimura  <rkx1209dev@gmail.com>
+
+       * simple-object-elf.c (simple_object_elf_match): Check zero value shstrndx.
+       This fixes a Bug 90924.
+
+       2019-07-22  Martin Liska  <mliska@suse.cz>
+
+       * simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
+       Do not search for gnu_lto_v1, but search for first '\0'.
+
+       2019-07-18  Eduard-Mihai Burtescu  <eddyb@lyken.rs>
+
+       * cplus-dem.c: Include rust-demangle.h.
+       * rust-demangle.c: Include rust-demangle.h.
+       * rust-demangle.h: New file.
+
+       2019-05-31  Michael Forney  <mforney@mforney.org>
+
+       * cp-demangle.c: Don't define CP_DYNAMIC_ARRAYS if __STDC_NO_VLA__
+       is non-zero.
+
+       2019-04-30  Ben L  <bobsayshilol@live.co.uk>
+
+       * d-demangle.c (dlang_parse_assocarray): Correctly handle error result.
+       * testsuite/d-demangle-expected: Add testcase.
+
+       * d-demangle.c (dlang_parse_tuple): Correctly handle error result.
+       * testsuite/d-demangle-expected: Add testcase.
+
+       * d-demangle.c (dlang_parse_structlit): Correctly handle error result.
+       * testsuite/d-demangle-expected: Add testcase.
+
+       * d-demangle.c (dlang_parse_arrayliteral): Correctly handle error result.
+       * testsuite/d-demangle-expected: Add testcase.
+
+       * d-demangle.c (dlang_parse_integer): Fix stack underflow.
+       * testsuite/d-demangle-expected: Add testcase.
+
+       * cp-demangle (d_print_comp_inner): Guard against a NULL 'typed_name'.
+       * testsuite/demangle-expected: Add testcase.
+
+       * cp-demangle.c (d_encoding): Guard against NULL return values from
+       d_right (dc).
+       * testsuite/demangle-expected: Add testcase.
+
+       2019-04-29  Ben L  <bobsayshilol@live.co.uk>
+
+       * cp-demangle.c (d_expression_1): Don't peek ahead unless the current
+       char is valid.
+       * testsuite/demangle-expected: Add testcase.
+
+       2019-04-10  Nick Clifton  <nickc@redhat.com>
+
+       PR 89394
+       * cp-demangle.c (cplus_demangle_fill_name): Reject negative
+       lengths.
+       (d_count_templates_scopes): Replace num_templates and num_scopes
+       parameters with a struct d_print_info pointer parameter.  Adjust
+       body of the function accordingly.  Add recursion counter and check
+       that the recursion limit is not reached.
+       (d_print_init): Pass dpi parameter to d_count_templates_scopes.
+       Reset recursion counter afterwards, unless the recursion limit was
+       reached.
+
 2019-07-13  Joel Brobecker  <brobecker@adacore.com>
 
        * src-release (getver): If $tool/gdbsupport/create-version.sh
index 031be3a974a2dcc656d34e5bf36ca2ed63cdf857..95cb1525f2c4c1e7a3ddb73e4c90a96ce753f3e1 100644 (file)
@@ -1,3 +1,78 @@
+2019-08-08  Martin Liska  <mliska@suse.cz>
+
+       PR bootstrap/91352
+       * lrealpath.c (is_valid_fd): New function.
+
+2019-07-24  Martin Liska  <mliska@suse.cz>
+
+       PR lto/91228
+       * simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
+       Find first '\0' starting from gnu_lto + 1.
+
+2019-07-12  Ren Kimura  <rkx1209dev@gmail.com>
+
+       * simple-object-elf.c (simple_object_elf_match): Check zero value shstrndx.
+       This fixes a Bug 90924.
+
+2019-07-22  Martin Liska  <mliska@suse.cz>
+
+       * simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
+       Do not search for gnu_lto_v1, but search for first '\0'.
+
+2019-07-18  Eduard-Mihai Burtescu  <eddyb@lyken.rs>
+
+       * cplus-dem.c: Include rust-demangle.h.
+       * rust-demangle.c: Include rust-demangle.h.
+       * rust-demangle.h: New file.
+
+2019-05-31  Michael Forney  <mforney@mforney.org>
+
+       * cp-demangle.c: Don't define CP_DYNAMIC_ARRAYS if __STDC_NO_VLA__
+       is non-zero.
+
+2019-04-30  Ben L  <bobsayshilol@live.co.uk>
+
+       * d-demangle.c (dlang_parse_assocarray): Correctly handle error result.
+       * testsuite/d-demangle-expected: Add testcase.
+
+       * d-demangle.c (dlang_parse_tuple): Correctly handle error result.
+       * testsuite/d-demangle-expected: Add testcase.
+
+       * d-demangle.c (dlang_parse_structlit): Correctly handle error result.
+       * testsuite/d-demangle-expected: Add testcase.
+
+       * d-demangle.c (dlang_parse_arrayliteral): Correctly handle error result.
+       * testsuite/d-demangle-expected: Add testcase.
+
+       * d-demangle.c (dlang_parse_integer): Fix stack underflow.
+       * testsuite/d-demangle-expected: Add testcase.
+
+       * cp-demangle (d_print_comp_inner): Guard against a NULL 'typed_name'.
+       * testsuite/demangle-expected: Add testcase.
+
+       * cp-demangle.c (d_encoding): Guard against NULL return values from
+       d_right (dc).
+       * testsuite/demangle-expected: Add testcase.
+
+2019-04-29  Ben L  <bobsayshilol@live.co.uk>
+
+       * cp-demangle.c (d_expression_1): Don't peek ahead unless the current
+       char is valid.
+       * testsuite/demangle-expected: Add testcase.
+
+2019-04-10  Nick Clifton  <nickc@redhat.com>
+
+       PR 89394
+       * cp-demangle.c (cplus_demangle_fill_name): Reject negative
+       lengths.
+       (d_count_templates_scopes): Replace num_templates and num_scopes
+       parameters with a struct d_print_info pointer parameter.  Adjust
+       body of the function accordingly.  Add recursion counter and check
+       that the recursion limit is not reached.
+       (d_print_init): Pass dpi parameter to d_count_templates_scopes.
+       Reset recursion counter afterwards, unless the recursion limit was
+       reached.
+
 2019-04-07  Alan Modra  <amodra@gmail.com>
 
        * functions.texi: Regenerate.
index 779b4e763a05f8328c40fe3775753af9947001d6..aa78c86dd443c5078c5f440ebeaafd01ae3cd8ec 100644 (file)
@@ -192,9 +192,9 @@ static void d_init_info (const char *, int, size_t, struct d_info *);
 #else
 #ifdef __STDC__
 #ifdef __STDC_VERSION__
-#if __STDC_VERSION__ >= 199901L
+#if __STDC_VERSION__ >= 199901L && !__STDC_NO_VLA__
 #define CP_DYNAMIC_ARRAYS
-#endif /* __STDC__VERSION >= 199901L */
+#endif /* __STDC_VERSION__ >= 199901L && !__STDC_NO_VLA__ */
 #endif /* defined (__STDC_VERSION__) */
 #endif /* defined (__STDC__) */
 #endif /* ! defined (__GNUC__) */
@@ -1330,8 +1330,14 @@ d_encoding (struct d_info *di, int top_level)
             really apply here; this happens when parsing a class
             which is local to a function.  */
          if (dc->type == DEMANGLE_COMPONENT_LOCAL_NAME)
-           while (is_fnqual_component_type (d_right (dc)->type))
-             d_right (dc) = d_left (d_right (dc));
+           {
+             while (d_right (dc) != NULL
+                    && is_fnqual_component_type (d_right (dc)->type))
+               d_right (dc) = d_left (d_right (dc));
+
+             if (d_right (dc) == NULL)
+               dc = NULL;
+           }
        }
       else
        {
@@ -3359,7 +3365,7 @@ d_expression_1 (struct d_info *di)
       d_advance (di, 2);
       if (peek == 't')
        type = cplus_demangle_type (di);
-      if (!d_peek_next_char (di))
+      if (!d_peek_char (di) || !d_peek_next_char (di))
        return NULL;
       return d_make_comp (di, DEMANGLE_COMPONENT_INITIALIZER_LIST,
                          type, d_exprlist (di, 'E'));
@@ -4761,12 +4767,8 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
            typed_name = d_right (typed_name);
            if (typed_name->type == DEMANGLE_COMPONENT_DEFAULT_ARG)
              typed_name = typed_name->u.s_unary_num.sub;
-           if (typed_name == NULL)
-             {
-               d_print_error (dpi);
-               return;
-             }
-           while (is_fnqual_component_type (typed_name->type))
+           while (typed_name != NULL
+                  && is_fnqual_component_type (typed_name->type))
              {
                if (i >= sizeof adpm / sizeof adpm[0])
                  {
@@ -4785,6 +4787,11 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
 
                typed_name = d_left (typed_name);
              }
+           if (typed_name == NULL)
+             {
+               d_print_error (dpi);
+               return;
+             }
          }
 
        /* If typed_name is a template, then it applies to the
index afceed2a1a751155fcfa4cbccd4e12e3f0377c34..a39e2bf2ed46eaaee01a95b363b46a70be31fc9f 100644 (file)
@@ -52,6 +52,7 @@ void * realloc ();
 #define CURRENT_DEMANGLING_STYLE options
 
 #include "libiberty.h"
+#include "rust-demangle.h"
 
 enum demangling_styles current_demangling_style = auto_demangling;
 
index 8acbf046f262bc1f769f14d37bcbd0c96f941541..becc402c1f82e68445b134ed4910ff9b664f11ec 100644 (file)
@@ -939,8 +939,8 @@ dlang_parse_integer (string *decl, const char *mangled, char type)
   if (type == 'a' || type == 'u' || type == 'w')
     {
       /* Parse character value.  */
-      char value[10];
-      int pos = 10;
+      char value[20];
+      int pos = sizeof(value);
       int width = 0;
       long val;
 
@@ -991,7 +991,7 @@ dlang_parse_integer (string *decl, const char *mangled, char type)
          for (; width > 0; width--)
            value[--pos] = '0';
 
-         string_appendn (decl, &(value[pos]), 10 - pos);
+         string_appendn (decl, &(value[pos]), sizeof(value) - pos);
        }
       string_append (decl, "'");
     }
@@ -1191,6 +1191,9 @@ dlang_parse_arrayliteral (string *decl, const char *mangled)
   while (elements--)
     {
       mangled = dlang_value (decl, mangled, NULL, '\0');
+      if (mangled == NULL)
+       return NULL;
+
       if (elements != 0)
        string_append (decl, ", ");
     }
@@ -1214,8 +1217,13 @@ dlang_parse_assocarray (string *decl, const char *mangled)
   while (elements--)
     {
       mangled = dlang_value (decl, mangled, NULL, '\0');
+      if (mangled == NULL)
+       return NULL;
+
       string_append (decl, ":");
       mangled = dlang_value (decl, mangled, NULL, '\0');
+      if (mangled == NULL)
+       return NULL;
 
       if (elements != 0)
        string_append (decl, ", ");
@@ -1243,6 +1251,9 @@ dlang_parse_structlit (string *decl, const char *mangled, const char *name)
   while (args--)
     {
       mangled = dlang_value (decl, mangled, NULL, '\0');
+      if (mangled == NULL)
+       return NULL;
+
       if (args != 0)
        string_append (decl, ", ");
     }
@@ -1497,6 +1508,9 @@ dlang_parse_tuple (string *decl, const char *mangled)
   while (elements--)
     {
       mangled = dlang_type (decl, mangled);
+      if (mangled == NULL)
+       return NULL;
+
       if (elements != 0)
        string_append (decl, ", ");
     }
index 7f66dc2b1bd26c41821d409a95f93e216677923d..ac914a7a4f403b09c90416c8e1fa3c6b52c1b48a 100644 (file)
@@ -49,6 +49,9 @@ components will be simplified.  The returned value will be allocated using
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
 
 /* On GNU libc systems the declaration is only visible with _GNU_SOURCE.  */
 #if defined(HAVE_CANONICALIZE_FILE_NAME) \
@@ -155,3 +158,16 @@ lrealpath (const char *filename)
   /* This system is a lost cause, just duplicate the filename.  */
   return strdup (filename);
 }
+
+/* Return true when FD file descriptor exists.  */
+
+int
+is_valid_fd (int fd)
+{
+#if defined(_WIN32)
+  HANDLE h = (HANDLE) _get_osfhandle (fd);
+  return h != (HANDLE) -1;
+#else
+  return fcntl (fd, F_GETFD) >= 0;
+#endif
+}
index 9b2d2dbe6311bcb2388be8ee2006956c8a9cea8b..2302db45b6fbce2798721298f64149a3d3cb68ef 100644 (file)
@@ -47,6 +47,7 @@ extern void *memset(void *s, int c, size_t n);
 
 #include <demangle.h>
 #include "libiberty.h"
+#include "rust-demangle.h"
 
 
 /* Mangled Rust symbols look like this:
diff --git a/libiberty/rust-demangle.h b/libiberty/rust-demangle.h
new file mode 100644 (file)
index 0000000..abf4c6c
--- /dev/null
@@ -0,0 +1,45 @@
+/* Internal demangler interface for the Rust programming language.
+   Copyright (C) 2016-2019 Free Software Foundation, Inc.
+   Written by David Tolnay (dtolnay@gmail.com).
+
+This file is part of the libiberty library.
+Libiberty is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU Library General Public
+License, the Free Software Foundation gives you unlimited permission
+to link the compiled version of this file into combinations with other
+programs, and to distribute those combinations without any restriction
+coming from the use of this file.  (The Library Public License
+restrictions do apply in other respects; for example, they cover
+modification of the file, and distribution when not linked into a
+combined executable.)
+
+Libiberty is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with libiberty; see the file COPYING.LIB.
+If not, see <http://www.gnu.org/licenses/>.  */
+
+/* This file provides some definitions shared by cplus-dem.c and
+   rust-demangle.c.  It should not be included by any other files.  */
+
+/* Returns non-zero iff MANGLED is a rust mangled symbol.  MANGLED must
+   already have been demangled through cplus_demangle_v3.  If this function
+   returns non-zero then MANGLED can be demangled (in-place) using
+   RUST_DEMANGLE_SYM.  */
+extern int
+rust_is_mangled (const char *mangled);
+
+/* Demangles SYM (in-place) if RUST_IS_MANGLED returned non-zero for SYM.
+   If RUST_IS_MANGLED returned zero for SYM then RUST_DEMANGLE_SYM might
+   replace characters that cannot be demangled with '?' and might truncate
+   SYM.  After calling RUST_DEMANGLE_SYM SYM might be shorter, but never
+   larger.  */
+extern void
+rust_demangle_sym (char *sym);
index 22c9ae7ed2df01dfe221e9627b82e6d56f225824..7515926659694ba930aa0a7d1a22e84b05c117c8 100644 (file)
@@ -548,7 +548,15 @@ simple_object_elf_match (unsigned char header[SIMPLE_OBJECT_MATCH_HEADER_LEN],
       XDELETE (eor);
       return NULL;
     }
-
+  
+  if (eor->shstrndx == 0)
+    {
+      *errmsg = "invalid ELF shstrndx == 0";
+      *err = 0;
+      XDELETE (eor);
+      return NULL;
+    }
+  
   return (void *) eor;
 }
 
@@ -1358,9 +1366,8 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
          return errmsg;
        }
 
-      /* If we are processing .symtab purge __gnu_lto_v1 and
-        __gnu_lto_slim symbols from it and any symbols in discarded
-        sections.  */
+      /* If we are processing .symtab purge __gnu_lto_slim symbol
+        from it and any symbols in discarded sections.  */
       if (sh_type == SHT_SYMTAB)
        {
          unsigned entsize = ELF_FETCH_FIELD (type_functions, ei_class, Shdr,
@@ -1380,14 +1387,9 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
                                       sobj->offset + stroff,
                                       (unsigned char *)strings,
                                       strsz, &errmsg, err);
-         /* Find gnu_lto_ in strings.  */
-         while ((gnu_lto = (char *) memchr (gnu_lto, 'g',
-                                            strings + strsz - gnu_lto)))
-           if (strncmp (gnu_lto, "gnu_lto_v1",
-                        strings + strsz - gnu_lto) == 0)
-             break;
-           else
-             gnu_lto++;
+         /* Find first '\0' in strings.  */
+         gnu_lto = (char *) memchr (gnu_lto + 1, '\0',
+                                    strings + strsz - gnu_lto);
          /* Read the section index table if present.  */
          if (symtab_indices_shndx[i - 1] != 0)
            {
@@ -1461,10 +1463,9 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
                         undefined and sharing the gnu_lto_ name.  */
                      bind = STB_WEAK;
                      other = STV_HIDDEN;
-                     if (gnu_lto)
-                       ELF_SET_FIELD (type_functions, ei_class, Sym,
-                                      ent, st_name, Elf_Word,
-                                      gnu_lto - strings);
+                     ELF_SET_FIELD (type_functions, ei_class, Sym,
+                                    ent, st_name, Elf_Word,
+                                    gnu_lto - strings);
                      ELF_SET_FIELD (type_functions, ei_class, Sym,
                                     ent, st_shndx, Elf_Half, SHN_UNDEF);
                    }
index 547a2ddec397b44b118226275fbe46b2167eb3b1..490d4e1493144280d6377ed77ed32a63ae00a147 100644 (file)
@@ -1306,3 +1306,23 @@ rt.lifetime._d_newarrayOpT!(_d_newarrayiT)._d_newarrayOpT(const(TypeInfo), ulong
 --format=dlang
 _D4core8demangle16__T6mangleTFZPvZ6mangleFNaNbNfAxaAaZ11DotSplitter5emptyMxFNaNbNdNiNfZb
 core.demangle.mangle!(void*() function).mangle(const(char)[], char[]).DotSplitter.empty() const
+# Could crash
+--format=dlang
+_D8__T2fnVa8888888888888_
+_D8__T2fnVa8888888888888_
+# Could crash
+--format=dlang
+_D5__T2fnVmA1A1A911111111D
+_D5__T2fnVmA1A1A911111111D
+# Could crash
+--format=dlang
+_D7__T2fnVlS8S588888888888S6S5
+_D7__T2fnVlS8S588888888888S6S5
+# Could crash
+--format=dlang
+_D1_B699999999961*
+_D1_B699999999961*
+# Could crash
+--format=dlang
+_D5__T1fVHacA6666666666_
+_D5__T1fVHacA6666666666_
index 3723b7a90f1d5bc60b34cd8cfd3364539cb9aa40..f21ed00e559a235d5d6183ac7bc44f7495e2f3ce 100644 (file)
@@ -68,6 +68,19 @@ _$_H1R
 
 _Q8ccQ4M2e.
 _Q8ccQ4M2e.
+# Could crash
+
+_ZmmAtl
+_ZmmAtl
+# Could crash
+--no-params
+_ZZaSFvOEES_
+_ZZaSFvOEES_
+_ZZaSFvOEES_
+# Could crash
+
+_ZZeqFvOEES_z
+_ZZeqFvOEES_z
 #
 # demangler/80513 Test for bogus characters after __thunk_