+ struct minimal_symbol **table
+ = objfile->per_bfd->msymbol_demangled_hash;
+ unsigned int hash_index = hash_value % MINIMAL_SYMBOL_HASH_SIZE;
+ sym->demangled_hash_next = table[hash_index];
+ table[hash_index] = sym;
+ }
+}
+
+/* Worker object for lookup_minimal_symbol. Stores temporary results
+ while walking the symbol tables. */
+
+struct found_minimal_symbols
+{
+ /* External symbols are best. */
+ bound_minimal_symbol external_symbol {};
+
+ /* File-local symbols are next best. */
+ bound_minimal_symbol file_symbol {};
+
+ /* Symbols for shared library trampolines are next best. */
+ bound_minimal_symbol trampoline_symbol {};
+
+ /* Called when a symbol name matches. Check if the minsym is a
+ better type than what we had already found, and record it in one
+ of the members fields if so. Returns true if we collected the
+ real symbol, in which case we can stop searching. */
+ bool maybe_collect (const char *sfile, objfile *objf,
+ minimal_symbol *msymbol);
+};
+
+/* See declaration above. */
+
+bool
+found_minimal_symbols::maybe_collect (const char *sfile,
+ struct objfile *objfile,
+ minimal_symbol *msymbol)
+{
+ switch (MSYMBOL_TYPE (msymbol))
+ {
+ case mst_file_text:
+ case mst_file_data:
+ case mst_file_bss:
+ if (sfile == NULL
+ || filename_cmp (msymbol->filename, sfile) == 0)
+ {
+ file_symbol.minsym = msymbol;
+ file_symbol.objfile = objfile;
+ }
+ break;
+
+ case mst_solib_trampoline:
+
+ /* If a trampoline symbol is found, we prefer to keep
+ looking for the *real* symbol. If the actual symbol
+ is not found, then we'll use the trampoline
+ entry. */
+ if (trampoline_symbol.minsym == NULL)
+ {
+ trampoline_symbol.minsym = msymbol;
+ trampoline_symbol.objfile = objfile;
+ }
+ break;
+
+ case mst_unknown:
+ default:
+ external_symbol.minsym = msymbol;
+ external_symbol.objfile = objfile;
+ /* We have the real symbol. No use looking further. */
+ return true;
+ }
+
+ /* Keep looking. */
+ return false;
+}
+
+/* Walk the mangled name hash table, and pass each symbol whose name
+ matches LOOKUP_NAME according to NAMECMP to FOUND. */
+
+static void
+lookup_minimal_symbol_mangled (const char *lookup_name,
+ const char *sfile,
+ struct objfile *objfile,
+ struct minimal_symbol **table,
+ unsigned int hash,
+ int (*namecmp) (const char *, const char *),
+ found_minimal_symbols &found)
+{
+ for (minimal_symbol *msymbol = table[hash];
+ msymbol != NULL;
+ msymbol = msymbol->hash_next)
+ {
+ const char *symbol_name = msymbol->linkage_name ();
+
+ if (namecmp (symbol_name, lookup_name) == 0
+ && found.maybe_collect (sfile, objfile, msymbol))
+ return;
+ }
+}
+
+/* Walk the demangled name hash table, and pass each symbol whose name
+ matches LOOKUP_NAME according to MATCHER to FOUND. */
+
+static void
+lookup_minimal_symbol_demangled (const lookup_name_info &lookup_name,
+ const char *sfile,
+ struct objfile *objfile,
+ struct minimal_symbol **table,
+ unsigned int hash,
+ symbol_name_matcher_ftype *matcher,
+ found_minimal_symbols &found)
+{
+ for (minimal_symbol *msymbol = table[hash];
+ msymbol != NULL;
+ msymbol = msymbol->demangled_hash_next)
+ {
+ const char *symbol_name = msymbol->search_name ();
+
+ if (matcher (symbol_name, lookup_name, NULL)
+ && found.maybe_collect (sfile, objfile, msymbol))
+ return;