aboutsummaryrefslogtreecommitdiff
path: root/libiberty
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2019-08-09 16:16:18 +0100
committerNick Clifton <nickc@redhat.com>2019-08-09 16:16:18 +0100
commitf211b8c0b91fc7b1657079a495f05a9a4d957821 (patch)
tree5f7d086cc3f1615bcf43c5d6f9054a4f104fca6d /libiberty
parentf16a9783c5f085443d806646074e9c06fdee9a88 (diff)
downloadgdb-f211b8c0b91fc7b1657079a495f05a9a4d957821.zip
gdb-f211b8c0b91fc7b1657079a495f05a9a4d957821.tar.gz
gdb-f211b8c0b91fc7b1657079a495f05a9a4d957821.tar.bz2
Synchronize libiberty sources with gcc mainline.
* 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.
Diffstat (limited to 'libiberty')
-rw-r--r--libiberty/ChangeLog75
-rw-r--r--libiberty/cp-demangle.c29
-rw-r--r--libiberty/cplus-dem.c1
-rw-r--r--libiberty/d-demangle.c20
-rw-r--r--libiberty/lrealpath.c16
-rw-r--r--libiberty/rust-demangle.c1
-rw-r--r--libiberty/rust-demangle.h45
-rw-r--r--libiberty/simple-object-elf.c33
-rw-r--r--libiberty/testsuite/d-demangle-expected20
-rw-r--r--libiberty/testsuite/demangle-expected13
10 files changed, 223 insertions, 30 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index 031be3a..95cb152 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -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.
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 779b4e7..aa78c86 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -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
diff --git a/libiberty/cplus-dem.c b/libiberty/cplus-dem.c
index afceed2..a39e2bf 100644
--- a/libiberty/cplus-dem.c
+++ b/libiberty/cplus-dem.c
@@ -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;
diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
index 8acbf04..becc402 100644
--- a/libiberty/d-demangle.c
+++ b/libiberty/d-demangle.c
@@ -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, ", ");
}
diff --git a/libiberty/lrealpath.c b/libiberty/lrealpath.c
index 7f66dc2..ac914a7 100644
--- a/libiberty/lrealpath.c
+++ b/libiberty/lrealpath.c
@@ -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
+}
diff --git a/libiberty/rust-demangle.c b/libiberty/rust-demangle.c
index 9b2d2db..2302db4 100644
--- a/libiberty/rust-demangle.c
+++ b/libiberty/rust-demangle.c
@@ -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
index 0000000..abf4c6c
--- /dev/null
+++ b/libiberty/rust-demangle.h
@@ -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);
diff --git a/libiberty/simple-object-elf.c b/libiberty/simple-object-elf.c
index 22c9ae7..7515926 100644
--- a/libiberty/simple-object-elf.c
+++ b/libiberty/simple-object-elf.c
@@ -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);
}
diff --git a/libiberty/testsuite/d-demangle-expected b/libiberty/testsuite/d-demangle-expected
index 547a2dd..490d4e1 100644
--- a/libiberty/testsuite/d-demangle-expected
+++ b/libiberty/testsuite/d-demangle-expected
@@ -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_
diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected
index 3723b7a..f21ed00 100644
--- a/libiberty/testsuite/demangle-expected
+++ b/libiberty/testsuite/demangle-expected
@@ -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_