diff --git a/input_sections.cc b/input_sections.cc index f40892e6..1995cf44 100644 --- a/input_sections.cc +++ b/input_sections.cc @@ -132,7 +132,8 @@ void InputSection::copy_buf() { // Copy data u8 *base = out::buf + output_section->shdr.sh_offset + offset; - copy_contents(base); + std::string_view contents = file->get_string(shdr); + memcpy(base, contents.data(), contents.size()); // Apply relocations if (shdr.sh_flags & SHF_ALLOC) @@ -141,11 +142,6 @@ void InputSection::copy_buf() { apply_reloc_nonalloc(base); } -void InputSection::copy_contents(u8 *base) { - std::string_view contents = file->get_string(shdr); - memcpy(base, contents.data(), contents.size()); -} - void InputSection::apply_reloc_alloc(u8 *base) { int ref_idx = 0; ElfRela *dynrel = nullptr; diff --git a/mold.h b/mold.h index 38bb3a55..b8ad80b0 100644 --- a/mold.h +++ b/mold.h @@ -336,7 +336,6 @@ public: bool is_comdat_member = false; bool is_alive = true; - void copy_contents(u8 *base); void apply_reloc_alloc(u8 *base); void apply_reloc_nonalloc(u8 *base); }; diff --git a/output_chunks.cc b/output_chunks.cc index 8e3f5b74..b4c5ca30 100644 --- a/output_chunks.cc +++ b/output_chunks.cc @@ -423,18 +423,19 @@ void OutputSection::copy_buf() { if (shdr.sh_type == SHT_NOBITS) return; - int num_members = members.size(); + tbb::parallel_for(0, (int)members.size(), [&](int i) { + InputSection &isec = *members[i]; + if (isec.shdr.sh_type == SHT_NOBITS) + return; - tbb::parallel_for(0, num_members, [&](int i) { - if (members[i]->shdr.sh_type != SHT_NOBITS) { - // Copy section contents to an output file - members[i]->copy_buf(); + // Copy section contents to an output file + isec.copy_buf(); - // Zero-clear trailing padding - u64 this_end = members[i]->offset + members[i]->shdr.sh_size; - u64 next_start = (i == num_members - 1) ? shdr.sh_size : members[i + 1]->offset; - memset(out::buf + shdr.sh_offset + this_end, 0, next_start - this_end); - } + // Zero-clear trailing padding + u64 this_end = isec.offset + isec.shdr.sh_size; + u64 next_start = (i == members.size() - 1) ? + shdr.sh_size : members[i + 1]->offset; + memset(out::buf + shdr.sh_offset + this_end, 0, next_start - this_end); }); }