mirror of
https://github.com/rui314/mold.git
synced 2024-12-28 02:44:48 +03:00
wip
This commit is contained in:
parent
c4f9abecc3
commit
f0d625d75e
30
icf.cc
30
icf.cc
@ -12,6 +12,7 @@ static constexpr i64 HASH_SIZE = 16;
|
|||||||
|
|
||||||
static bool is_eligible(InputSection &isec) {
|
static bool is_eligible(InputSection &isec) {
|
||||||
return (isec.shdr.sh_flags & SHF_ALLOC) &&
|
return (isec.shdr.sh_flags & SHF_ALLOC) &&
|
||||||
|
(isec.shdr.sh_type != SHT_NOBITS) &&
|
||||||
!(isec.shdr.sh_flags & SHF_WRITE) &&
|
!(isec.shdr.sh_flags & SHF_WRITE) &&
|
||||||
!(isec.shdr.sh_type == SHT_INIT_ARRAY || isec.name == ".init") &&
|
!(isec.shdr.sh_type == SHT_INIT_ARRAY || isec.name == ".init") &&
|
||||||
!(isec.shdr.sh_type == SHT_FINI_ARRAY || isec.name == ".fini");
|
!(isec.shdr.sh_type == SHT_FINI_ARRAY || isec.name == ".fini");
|
||||||
@ -70,7 +71,7 @@ static void gather_sections(std::vector<InputSection *> §ions,
|
|||||||
|
|
||||||
tbb::parallel_for((i64)0, (i64)out::objs.size(), [&](i64 i) {
|
tbb::parallel_for((i64)0, (i64)out::objs.size(), [&](i64 i) {
|
||||||
for (InputSection *isec : out::objs[i]->sections)
|
for (InputSection *isec : out::objs[i]->sections)
|
||||||
if (isec && isec->shdr.sh_type != SHT_NOBITS)
|
if (isec)
|
||||||
num_sections[i]++;
|
num_sections[i]++;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -84,7 +85,7 @@ static void gather_sections(std::vector<InputSection *> §ions,
|
|||||||
tbb::parallel_for((i64)0, (i64)out::objs.size(), [&](i64 i) {
|
tbb::parallel_for((i64)0, (i64)out::objs.size(), [&](i64 i) {
|
||||||
i64 idx = section_indices[i];
|
i64 idx = section_indices[i];
|
||||||
for (InputSection *isec : out::objs[i]->sections) {
|
for (InputSection *isec : out::objs[i]->sections) {
|
||||||
if (isec && isec->shdr.sh_type != SHT_NOBITS) {
|
if (isec) {
|
||||||
Entry &ent = entries[idx++];
|
Entry &ent = entries[idx++];
|
||||||
ent.isec = isec;
|
ent.isec = isec;
|
||||||
ent.is_eligible = is_eligible(*isec);
|
ent.is_eligible = is_eligible(*isec);
|
||||||
@ -130,9 +131,30 @@ static void gather_sections(std::vector<InputSection *> §ions,
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
edge_indices.resize(num_edges.size() + 1);
|
edge_indices.resize(num_edges.size());
|
||||||
for (i64 i = 0; i < num_edges.size(); i++)
|
for (i64 i = 0; i < num_edges.size() - 1; i++)
|
||||||
edge_indices[i + 1] = edge_indices[i] + num_edges[i];
|
edge_indices[i + 1] = edge_indices[i] + num_edges[i];
|
||||||
|
|
||||||
|
edges.resize(edge_indices.back() + num_edges.back());
|
||||||
|
|
||||||
|
tbb::parallel_for((i64)0, (i64)num_edges.size(), [&](i64 i) {
|
||||||
|
sections[i]->icf_idx = i;
|
||||||
|
});
|
||||||
|
|
||||||
|
tbb::parallel_for((i64)0, (i64)num_edges.size(), [&](i64 i) {
|
||||||
|
InputSection &isec = *sections[i];
|
||||||
|
i64 idx = edge_indices[i];
|
||||||
|
|
||||||
|
for (i64 j = 0; j < isec.rels.size(); j++) {
|
||||||
|
if (isec.has_fragments[i])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ElfRela &rel = isec.rels[j];
|
||||||
|
Symbol &sym = *isec.file->symbols[rel.r_sym];
|
||||||
|
if (sym.input_section)
|
||||||
|
edges[idx++] = sym.input_section->icf_idx;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void icf_sections() {
|
void icf_sections() {
|
||||||
|
1
mold.h
1
mold.h
@ -402,6 +402,7 @@ public:
|
|||||||
// For ICF
|
// For ICF
|
||||||
std::atomic_uint64_t eq_class[2] = {0, 0};
|
std::atomic_uint64_t eq_class[2] = {0, 0};
|
||||||
InputSection *leader = nullptr;
|
InputSection *leader = nullptr;
|
||||||
|
u32 icf_idx = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MergeableSection : public InputChunk {
|
class MergeableSection : public InputChunk {
|
||||||
|
Loading…
Reference in New Issue
Block a user