1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-28 02:44:48 +03:00
This commit is contained in:
Rui Ueyama 2021-01-28 14:04:23 +09:00
parent 0f46de23d2
commit 3e454c2175
3 changed files with 17 additions and 2 deletions

12
icf.cc
View File

@ -264,8 +264,11 @@ void icf_sections() {
break;
num_classes = n;
}
t2.stop();
// Group sections by SHA1 digest.
Timer t3("merge");
std::vector<std::pair<InputSection *, Digest>> 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<i64> counter;
tbb::parallel_for((i64)0, (i64)entries.size() - 1, [&](i64 i) {

View File

@ -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";

1
mold.h
View File

@ -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;