diff --git a/input_files.cc b/input_files.cc index 6d2a8846..4bbee60c 100644 --- a/input_files.cc +++ b/input_files.cc @@ -119,9 +119,8 @@ void ObjectFile::initialize_symbols() { for (int i = 0; i < first_global; i++) { const ELF64LE::Sym &esym = elf_syms[i]; StringRef name = CHECK(esym.getName(symbol_strtab), this); - - static ConcurrentMap map; - local_symbols.push_back(map.insert(name, LocalSymbolName(name))); + local_symbols.push_back(name); + strtab_size += name.size() + 1; } symbols.reserve(elf_syms.size() - first_global); @@ -343,6 +342,11 @@ void ObjectFile::fix_sym_addrs() { } uint64_t ObjectFile::get_strtab_size() { + uint64_t sz = strtab_size; + for (Symbol *sym : symbols) + if (sym->file == this) + sz += sym->name.size() + 1; + return sz; } StringRef ObjectFile::get_filename() { diff --git a/main.cc b/main.cc index 9c521624..a90c9eef 100644 --- a/main.cc +++ b/main.cc @@ -422,6 +422,11 @@ int main(int argc, char **argv) { for_each(files, [](ObjectFile *file) { file->scan_relocations(); }); } + { + MyTimer t("strtab_size", before_copy); + for_each(files, [](ObjectFile *file) { file->get_strtab_size(); }); + } + // Create linker-synthesized sections. out::ehdr = new OutputEhdr; out::phdr = new OutputPhdr; diff --git a/mold.h b/mold.h index 81f73911..0d86530a 100644 --- a/mold.h +++ b/mold.h @@ -458,14 +458,6 @@ struct StringPiece { std::atomic_flag flag = ATOMIC_FLAG_INIT; }; -struct LocalSymbolName { - LocalSymbolName(StringRef name) : name(name) {} - LocalSymbolName(const LocalSymbolName &other) : name(other.name) {} - - StringRef name; - std::atomic_flag claimed = ATOMIC_FLAG_INIT; -}; - class ObjectFile { public: ObjectFile(MemoryBufferRef mb, StringRef archive_name); @@ -527,9 +519,12 @@ private: ArrayRef elf_sections; ArrayRef elf_syms; - std::vector local_symbols; StringRef symbol_strtab; const ELF64LE::Shdr *symtab_sec; + + // For .strtab construction + std::vector local_symbols; + uint64_t strtab_size; }; //