diff --git a/input_files.cc b/input_files.cc index cfe6f9cf..c2f265d0 100644 --- a/input_files.cc +++ b/input_files.cc @@ -6,6 +6,7 @@ using namespace llvm::ELF; std::atomic_int num_defined; std::atomic_int num_undefined; std::atomic_int num_files; +std::atomic_int num_string_pieces; ObjectFile::ObjectFile(MemoryBufferRef mb, StringRef archive_name) : mb(mb), archive_name(archive_name), @@ -73,8 +74,8 @@ void ObjectFile::initialize_sections() { case SHT_NULL: break; default: { - if ((shdr.sh_flags & SHF_STRINGS) && (shdr.sh_flags & SHF_ALLOC) && - !(shdr.sh_flags & SHF_WRITE) && shdr.sh_entsize == 1) { + if ((shdr.sh_flags & SHF_STRINGS) && !(shdr.sh_flags & SHF_WRITE) && + shdr.sh_entsize == 1) { read_string_pieces(shdr); break; } @@ -118,7 +119,11 @@ void ObjectFile::initialize_symbols() { } void ObjectFile::read_string_pieces(const ELF64LE::Shdr &shdr) { - static ConcurrentMap map; + static ConcurrentMap map1; + static ConcurrentMap map2; + + bool is_alloc = shdr.sh_type & SHF_ALLOC; + ConcurrentMap &map = is_alloc ? map1 : map2; ArrayRef arr = CHECK(obj.getSectionContents(shdr), this); StringRef data((const char *)&arr[0], arr.size()); @@ -130,8 +135,14 @@ void ObjectFile::read_string_pieces(const ELF64LE::Shdr &shdr) { StringRef substr = data.substr(0, end + 1); StringPiece *piece = map.insert(substr, StringPiece(substr)); - merged_strings.push_back(piece); + + if (is_alloc) + merged_strings_alloc.push_back(piece); + else + merged_strings_noalloc.push_back(piece); + data = data.substr(end + 1); + num_string_pieces++; } } diff --git a/main.cc b/main.cc index bbec85a7..09017eae 100644 --- a/main.cc +++ b/main.cc @@ -314,7 +314,8 @@ int main(int argc, char **argv) { << " filesize=" << filesize << "\n" << " num_defined=" << num_defined << "\n" << "num_undefined=" << num_undefined << "\n" - << " num_relocs=" << num_relocs << "\n"; + << " num_relocs=" << num_relocs << "\n" + << " num_str=" << num_string_pieces << "\n"; llvm::TimerGroup::printAll(llvm::outs()); llvm::outs().flush(); diff --git a/mold.h b/mold.h index 854c36cd..5746c184 100644 --- a/mold.h +++ b/mold.h @@ -382,7 +382,8 @@ private: MemoryBufferRef mb; std::vector symbols; std::vector>> comdat_groups; - std::vector merged_strings; + std::vector merged_strings_alloc; + std::vector merged_strings_noalloc; ArrayRef elf_sections; ArrayRef elf_syms; @@ -422,3 +423,4 @@ extern std::atomic_int num_defined; extern std::atomic_int num_undefined; extern std::atomic_int num_files; extern std::atomic_int num_relocs; +extern std::atomic_int num_string_pieces;