commit e0b62fe05559003b731b4d786f3b71e9a66fb94d Author: Mark Wielaard Date: Thu Feb 17 18:35:38 2022 +0100 Update libiberty demangler Update the libiberty demangler using the auxprogs/update-demangler script to gcc git commit d3b2ead595467166c849950ecd3710501a5094d9. This update includes: - libiberty rust-demangle, ignore .suffix - libiberty: Fix infinite recursion in rust demangler - Update copyright years - libiberty: support digits in cpp mangled clone names - d-demangle: properly skip anonymous symbols - d-demangle: remove parenthesis where it is not needed diff --git a/auxprogs/update-demangler b/auxprogs/update-demangler index 00c090467..307a0ea36 100755 --- a/auxprogs/update-demangler +++ b/auxprogs/update-demangler @@ -17,8 +17,8 @@ set -e #--------------------------------------------------------------------- # You need to modify these revision numbers for your update. -old_gcc_revision=01d92cfd79872e4cffc78bf233bb9b767336beb8 # the revision of the previous update -new_gcc_revision=b3585c0836e729bed56b9afd4292177673a25ca0 # the revision for this update +old_gcc_revision=b3585c0836e729bed56b9afd4292177673a25ca0 # the revision of the previous update +new_gcc_revision=d3b2ead595467166c849950ecd3710501a5094d9 # the revision for this update # Unless the organization of demangler related files has changed, no # changes below this line should be necessary. diff --git a/coregrind/m_demangle/ansidecl.h b/coregrind/m_demangle/ansidecl.h index 2329c8655..4275c9b9c 100644 --- a/coregrind/m_demangle/ansidecl.h +++ b/coregrind/m_demangle/ansidecl.h @@ -1,5 +1,5 @@ -/* ANSI and traditional C compatibility macros - Copyright (C) 1991-2021 Free Software Foundation, Inc. +/* ANSI and traditional C compatability macros + Copyright (C) 1991-2022 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software; you can redistribute it and/or modify diff --git a/coregrind/m_demangle/cp-demangle.c b/coregrind/m_demangle/cp-demangle.c index 1f4cd3d28..ca82c330d 100644 --- a/coregrind/m_demangle/cp-demangle.c +++ b/coregrind/m_demangle/cp-demangle.c @@ -1,5 +1,5 @@ /* Demangler for g++ V3 ABI. - Copyright (C) 2003-2021 Free Software Foundation, Inc. + Copyright (C) 2003-2022 Free Software Foundation, Inc. Written by Ian Lance Taylor . This file is part of the libiberty library, which is part of GCC. @@ -3901,10 +3901,11 @@ d_clone_suffix (struct d_info *di, struct demangle_component *encoding) const char *pend = suffix; struct demangle_component *n; - if (*pend == '.' && (IS_LOWER (pend[1]) || pend[1] == '_')) + if (*pend == '.' && (IS_LOWER (pend[1]) || IS_DIGIT (pend[1]) + || pend[1] == '_')) { pend += 2; - while (IS_LOWER (*pend) || *pend == '_') + while (IS_LOWER (*pend) || IS_DIGIT (*pend) || *pend == '_') ++pend; } while (*pend == '.' && IS_DIGIT (pend[1])) diff --git a/coregrind/m_demangle/cp-demangle.h b/coregrind/m_demangle/cp-demangle.h index cb47bdf0d..c6445036d 100644 --- a/coregrind/m_demangle/cp-demangle.h +++ b/coregrind/m_demangle/cp-demangle.h @@ -1,5 +1,5 @@ /* Internal demangler interface for g++ V3 ABI. - Copyright (C) 2003-2021 Free Software Foundation, Inc. + Copyright (C) 2003-2022 Free Software Foundation, Inc. Written by Ian Lance Taylor . This file is part of the libiberty library, which is part of GCC. diff --git a/coregrind/m_demangle/cplus-dem.c b/coregrind/m_demangle/cplus-dem.c index bf4379054..5d6e04d96 100644 --- a/coregrind/m_demangle/cplus-dem.c +++ b/coregrind/m_demangle/cplus-dem.c @@ -1,5 +1,5 @@ /* Demangler for GNU C++ - Copyright (C) 1989-2021 Free Software Foundation, Inc. + Copyright (C) 1989-2022 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.uucp) Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling Modified by Satish Pai (pai@apollo.hp.com) for HP demangling diff --git a/coregrind/m_demangle/d-demangle.c b/coregrind/m_demangle/d-demangle.c index 4525c48d4..c2c3e08c8 100644 --- a/coregrind/m_demangle/d-demangle.c +++ b/coregrind/m_demangle/d-demangle.c @@ -1,5 +1,5 @@ /* Demangler for the D programming language - Copyright (C) 2014-2021 Free Software Foundation, Inc. + Copyright (C) 2014-2022 Free Software Foundation, Inc. Written by Iain Buclaw (ibuclaw@gdcproject.org) This file is part of the libiberty library. @@ -269,15 +269,15 @@ dlang_hexdigit (const char *mangled, char *ret) c = mangled[0]; if (!ISDIGIT (c)) - (*ret) = (c - (ISUPPER (c) ? 'A' : 'a') + 10); + *ret = c - (ISUPPER (c) ? 'A' : 'a') + 10; else - (*ret) = (c - '0'); + *ret = c - '0'; c = mangled[1]; if (!ISDIGIT (c)) - (*ret) = (*ret << 4) | (c - (ISUPPER (c) ? 'A' : 'a') + 10); + *ret = (*ret << 4) | (c - (ISUPPER (c) ? 'A' : 'a') + 10); else - (*ret) = (*ret << 4) | (c - '0'); + *ret = (*ret << 4) | (c - '0'); mangled += 2; @@ -354,7 +354,7 @@ dlang_decode_backref (const char *mangled, long *ret) static const char * dlang_backref (const char *mangled, const char **ret, struct dlang_info *info) { - (*ret) = NULL; + *ret = NULL; if (mangled == NULL || *mangled != 'Q') return NULL; @@ -372,7 +372,7 @@ dlang_backref (const char *mangled, const char **ret, struct dlang_info *info) return NULL; /* Set the position of the back reference. */ - (*ret) = qpos - refpos; + *ret = qpos - refpos; return mangled; } @@ -1666,13 +1666,19 @@ dlang_parse_qualified (string *decl, const char *mangled, size_t n = 0; do { + /* Skip over anonymous symbols. */ + if (*mangled == '0') + { + do + mangled++; + while (*mangled == '0'); + + continue; + } + if (n++) string_append (decl, "."); - /* Skip over anonymous symbols. */ - while (*mangled == '0') - mangled++; - mangled = dlang_identifier (decl, mangled, info); /* Consume the encoded arguments. However if this is not followed by the diff --git a/coregrind/m_demangle/demangle.h b/coregrind/m_demangle/demangle.h index 2acb3bd4e..bbce948c5 100644 --- a/coregrind/m_demangle/demangle.h +++ b/coregrind/m_demangle/demangle.h @@ -1,5 +1,5 @@ /* Defs for interface to demanglers. - Copyright (C) 1992-2021 Free Software Foundation, Inc. + Copyright (C) 1992-2022 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License diff --git a/coregrind/m_demangle/dyn-string.c b/coregrind/m_demangle/dyn-string.c index 66948debf..89ce8e12c 100644 --- a/coregrind/m_demangle/dyn-string.c +++ b/coregrind/m_demangle/dyn-string.c @@ -1,5 +1,5 @@ /* An abstract string datatype. - Copyright (C) 1998-2021 Free Software Foundation, Inc. + Copyright (C) 1998-2022 Free Software Foundation, Inc. Contributed by Mark Mitchell (mark@markmitchell.com). This file is part of GNU CC. diff --git a/coregrind/m_demangle/dyn-string.h b/coregrind/m_demangle/dyn-string.h index 6c5e66012..be2184aa9 100644 --- a/coregrind/m_demangle/dyn-string.h +++ b/coregrind/m_demangle/dyn-string.h @@ -1,5 +1,5 @@ /* An abstract string datatype. - Copyright (C) 1998-2021 Free Software Foundation, Inc. + Copyright (C) 1998-2022 Free Software Foundation, Inc. Contributed by Mark Mitchell (mark@markmitchell.com). This file is part of GCC. diff --git a/coregrind/m_demangle/rust-demangle.c b/coregrind/m_demangle/rust-demangle.c index 0cafa3df9..0a9331ac2 100644 --- a/coregrind/m_demangle/rust-demangle.c +++ b/coregrind/m_demangle/rust-demangle.c @@ -1,5 +1,5 @@ /* Demangler for the Rust programming language - Copyright (C) 2016-2021 Free Software Foundation, Inc. + Copyright (C) 2016-2022 Free Software Foundation, Inc. Written by David Tolnay (dtolnay@gmail.com). Rewritten by Eduard-Mihai Burtescu (eddyb@lyken.rs) for v0 support. @@ -101,6 +101,12 @@ struct rust_demangler /* Rust mangling version, with legacy mangling being -1. */ int version; + /* Recursion depth. */ + unsigned int recursion; + /* Maximum number of times demangle_path may be called recursively. */ +#define RUST_MAX_RECURSION_COUNT 1024 +#define RUST_NO_RECURSION_LIMIT ((unsigned int) -1) + uint64_t bound_lifetime_depth; }; @@ -698,6 +704,15 @@ demangle_path (struct rust_demangler *rdm, int in_value) if (rdm->errored) return; + if (rdm->recursion != RUST_NO_RECURSION_LIMIT) + { + ++ rdm->recursion; + if (rdm->recursion > RUST_MAX_RECURSION_COUNT) + /* FIXME: There ought to be a way to report + that the recursion limit has been reached. */ + goto fail_return; + } + switch (tag = next (rdm)) { case 'C': @@ -715,10 +730,7 @@ demangle_path (struct rust_demangler *rdm, int in_value) case 'N': ns = next (rdm); if (!ISLOWER (ns) && !ISUPPER (ns)) - { - rdm->errored = 1; - return; - } + goto fail_return; demangle_path (rdm, in_value); @@ -803,9 +815,15 @@ demangle_path (struct rust_demangler *rdm, int in_value) } break; default: - rdm->errored = 1; - return; + goto fail_return; } + goto pass_return; + + fail_return: + rdm->errored = 1; + pass_return: + if (rdm->recursion != RUST_NO_RECURSION_LIMIT) + -- rdm->recursion; } static void @@ -897,6 +915,19 @@ demangle_type (struct rust_demangler *rdm) return; } + if (rdm->recursion != RUST_NO_RECURSION_LIMIT) + { + ++ rdm->recursion; + if (rdm->recursion > RUST_MAX_RECURSION_COUNT) + /* FIXME: There ought to be a way to report + that the recursion limit has been reached. */ + { + rdm->errored = 1; + -- rdm->recursion; + return; + } + } + switch (tag) { case 'R': @@ -1057,6 +1088,9 @@ demangle_type (struct rust_demangler *rdm) rdm->next--; demangle_path (rdm, 0); } + + if (rdm->recursion != RUST_NO_RECURSION_LIMIT) + -- rdm->recursion; } /* A trait in a trait object may have some "existential projections" @@ -1347,6 +1381,7 @@ rust_demangle_callback (const char *mangled, int options, rdm.skipping_printing = 0; rdm.verbose = (options & DMGL_VERBOSE) != 0; rdm.version = 0; + rdm.recursion = (options & DMGL_NO_RECURSE_LIMIT) ? RUST_NO_RECURSION_LIMIT : 0; rdm.bound_lifetime_depth = 0; /* Rust symbols always start with _R (v0) or _ZN (legacy). */ @@ -1367,13 +1402,19 @@ rust_demangle_callback (const char *mangled, int options, /* Rust symbols (v0) use only [_0-9a-zA-Z] characters. */ for (p = rdm.sym; *p; p++) { + /* Rust v0 symbols can have '.' suffixes, ignore those. */ + if (rdm.version == 0 && *p == '.') + break; + rdm.sym_len++; if (*p == '_' || ISALNUM (*p)) continue; - /* Legacy Rust symbols can also contain [.:$] characters. */ - if (rdm.version == -1 && (*p == '$' || *p == '.' || *p == ':')) + /* Legacy Rust symbols can also contain [.:$] characters. + Or @ in the .suffix (which will be skipped, see below). */ + if (rdm.version == -1 && (*p == '$' || *p == '.' || *p == ':' + || *p == '@')) continue; return 0; @@ -1382,7 +1423,16 @@ rust_demangle_callback (const char *mangled, int options, /* Legacy Rust symbols need to be handled separately. */ if (rdm.version == -1) { - /* Legacy Rust symbols always end with E. */ + /* Legacy Rust symbols always end with E. But can be followed by a + .suffix (which we want to ignore). */ + int dot_suffix = 1; + while (rdm.sym_len > 0 && + !(dot_suffix && rdm.sym[rdm.sym_len - 1] == 'E')) + { + dot_suffix = rdm.sym[rdm.sym_len - 1] == '.'; + rdm.sym_len--; + } + if (!(rdm.sym_len > 0 && rdm.sym[rdm.sym_len - 1] == 'E')) return 0; rdm.sym_len--; diff --git a/coregrind/m_demangle/safe-ctype.c b/coregrind/m_demangle/safe-ctype.c index 14da11918..97bc43667 100644 --- a/coregrind/m_demangle/safe-ctype.c +++ b/coregrind/m_demangle/safe-ctype.c @@ -1,6 +1,6 @@ /* replacement macros. - Copyright (C) 2000-2021 Free Software Foundation, Inc. + Copyright (C) 2000-2022 Free Software Foundation, Inc. Contributed by Zack Weinberg . This file is part of the libiberty library. diff --git a/coregrind/m_demangle/safe-ctype.h b/coregrind/m_demangle/safe-ctype.h index a7389c32e..86157ed4b 100644 --- a/coregrind/m_demangle/safe-ctype.h +++ b/coregrind/m_demangle/safe-ctype.h @@ -1,6 +1,6 @@ /* replacement macros. - Copyright (C) 2000-2021 Free Software Foundation, Inc. + Copyright (C) 2000-2022 Free Software Foundation, Inc. Contributed by Zack Weinberg . This file is part of the libiberty library.