- objfile->minimal_symbol_count = mcount;
- objfile->msymbols = msymbols;
-
- /* Try to guess the appropriate C++ ABI by looking at the names
- of the minimal symbols in the table. */
- {
- int i;
-
- for (i = 0; i < mcount; i++)
- {
- /* If a symbol's name starts with _Z and was successfully
- demangled, then we can assume we've found a GNU v3 symbol.
- For now we set the C++ ABI globally; if the user is
- mixing ABIs then the user will need to "set cp-abi"
- manually. */
- const char *name = SYMBOL_LINKAGE_NAME (&objfile->msymbols[i]);
-
- if (name[0] == '_' && name[1] == 'Z'
- && SYMBOL_DEMANGLED_NAME (&objfile->msymbols[i]) != NULL)
- {
- set_cp_abi_as_auto_default ("gnu-v3");
- break;
- }
- }
- }
-
- /* Now build the hash tables; we can't do this incrementally
- at an earlier point since we weren't finished with the obstack
- yet. (And if the msymbol obstack gets moved, all the internal
- pointers to other msymbols need to be adjusted.) */
- build_minimal_symbol_hash_tables (objfile);
+ if (m_objfile->per_bfd->minimal_symbol_count != 0)
+ clear_minimal_symbol_hash_tables (m_objfile);
+
+ m_objfile->per_bfd->minimal_symbol_count = mcount;
+ m_objfile->per_bfd->msymbols = std::move (msym_holder);
+
+#if CXX_STD_THREAD
+ /* Mutex that is used when modifying or accessing the demangled
+ hash table. */
+ std::mutex demangled_mutex;
+#endif
+
+ std::vector<computed_hash_values> hash_values (mcount);
+
+ msymbols = m_objfile->per_bfd->msymbols.get ();
+ gdb::parallel_for_each
+ (&msymbols[0], &msymbols[mcount],
+ [&] (minimal_symbol *start, minimal_symbol *end)
+ {
+ for (minimal_symbol *msym = start; msym < end; ++msym)
+ {
+ size_t idx = msym - msymbols;
+ hash_values[idx].name_length = strlen (msym->linkage_name ());
+ if (!msym->name_set)
+ {
+ /* This will be freed later, by compute_and_set_names. */
+ char *demangled_name
+ = symbol_find_demangled_name (msym, msym->linkage_name ());
+ symbol_set_demangled_name
+ (msym, demangled_name,
+ &m_objfile->per_bfd->storage_obstack);
+ msym->name_set = 1;
+ }
+ /* This mangled_name_hash computation has to be outside of
+ the name_set check, or compute_and_set_names below will
+ be called with an invalid hash value. */
+ hash_values[idx].mangled_name_hash
+ = fast_hash (msym->linkage_name (),
+ hash_values[idx].name_length);
+ hash_values[idx].minsym_hash
+ = msymbol_hash (msym->linkage_name ());
+ /* We only use this hash code if the search name differs
+ from the linkage name. See the code in
+ build_minimal_symbol_hash_tables. */
+ if (msym->search_name () != msym->linkage_name ())
+ hash_values[idx].minsym_demangled_hash
+ = search_name_hash (msym->language (), msym->search_name ());
+ }
+ {
+ /* To limit how long we hold the lock, we only acquire it here
+ and not while we demangle the names above. */
+#if CXX_STD_THREAD
+ std::lock_guard<std::mutex> guard (demangled_mutex);
+#endif
+ for (minimal_symbol *msym = start; msym < end; ++msym)
+ {
+ size_t idx = msym - msymbols;
+ msym->compute_and_set_names
+ (gdb::string_view (msym->linkage_name (),
+ hash_values[idx].name_length),
+ false,
+ m_objfile->per_bfd,
+ hash_values[idx].mangled_name_hash);
+ }
+ }
+ });
+
+ build_minimal_symbol_hash_tables (m_objfile, hash_values);