From 3e454c21755444cf3e08abaca6746afc36fe4a56 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 28 Jan 2021 14:04:23 +0900 Subject: [PATCH] wip --- icf.cc | 12 ++++++++++-- input_sections.cc | 6 ++++++ mold.h | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/icf.cc b/icf.cc index ff29dfd6..9b6b7d3b 100644 --- a/icf.cc +++ b/icf.cc @@ -264,8 +264,11 @@ void icf_sections() { break; num_classes = n; } + t2.stop(); + // Group sections by SHA1 digest. + Timer t3("merge"); std::vector> entries; entries.resize(sections.size()); @@ -273,8 +276,13 @@ void icf_sections() { entries[i] = {sections[i], digests[slot][i]}; }); - tbb::parallel_sort(entries.begin(), entries.end(), - [](auto &a, auto &b) { return a.second < b.second; }); + tbb::parallel_sort(entries.begin(), entries.end(), [](auto &a, auto &b) { + if (a.second != b.second) + return a.second < b.second; + if (a.first->file->priority != b.first->file->priority) + return a.first->file->priority < b.first->file->priority; + return a.first->get_section_idx() < b.first->get_section_idx(); + }); tbb::enumerable_thread_specific counter; tbb::parallel_for((i64)0, (i64)entries.size() - 1, [&](i64 i) { diff --git a/input_sections.cc b/input_sections.cc index 4d1f3f52..19bf7644 100644 --- a/input_sections.cc +++ b/input_sections.cc @@ -11,6 +11,12 @@ std::string_view InputChunk::get_contents() const { return file->get_string(shdr); } +i64 InputChunk::get_section_idx() const { + assert(&file->elf_sections.front() <= &shdr && + &shdr < &file->elf_sections.back()); + return &shdr - &file->elf_sections.front(); +} + static std::string rel_to_string(u64 r_type) { switch (r_type) { case R_X86_64_NONE: return "R_X86_64_NONE"; diff --git a/mold.h b/mold.h index 8e2c52a9..79a63d44 100644 --- a/mold.h +++ b/mold.h @@ -300,6 +300,7 @@ public: virtual void copy_buf() {} inline u64 get_addr() const; std::string_view get_contents() const; + i64 get_section_idx() const; ObjectFile *file; const ElfShdr &shdr;