mirror of
https://github.com/rui314/mold.git
synced 2024-11-11 16:58:12 +03:00
wip
This commit is contained in:
parent
9c033f9a87
commit
401e11ad05
@ -28,8 +28,13 @@ visit(InputSection *isec, std::function<void(InputSection *)> enqueue) {
|
||||
for (i64 i = 1; i < fde.rels.size(); i++)
|
||||
enqueue(fde.rels[i].sym.input_section);
|
||||
|
||||
for (ElfRela &rel : isec->rels)
|
||||
enqueue(isec->file->symbols[rel.r_sym]->input_section);
|
||||
for (ElfRela &rel : isec->rels) {
|
||||
Symbol &sym = *isec->file->symbols[rel.r_sym];
|
||||
if (sym.frag_ref.frag)
|
||||
sym.frag_ref.frag->is_alive = true;
|
||||
else
|
||||
enqueue(sym.input_section);
|
||||
}
|
||||
}
|
||||
|
||||
void gc_sections() {
|
||||
@ -55,9 +60,7 @@ void gc_sections() {
|
||||
if (!(isec->shdr.sh_flags & SHF_ALLOC))
|
||||
isec->is_visited = true;
|
||||
|
||||
if (is_init_fini(*isec))
|
||||
enqueue(isec);
|
||||
if (isec->shdr.sh_type == SHT_NOTE)
|
||||
if (is_init_fini(*isec) || isec->shdr.sh_type == SHT_NOTE)
|
||||
enqueue(isec);
|
||||
}
|
||||
});
|
||||
|
2
main.cc
2
main.cc
@ -206,6 +206,8 @@ static void handle_mergeable_strings() {
|
||||
tbb::parallel_for_each(out::objs, [](ObjectFile *file) {
|
||||
for (MergeableSection *isec : file->mergeable_sections) {
|
||||
for (SectionFragment *frag : isec->fragments) {
|
||||
if (!frag->is_alive)
|
||||
continue;
|
||||
MergeableSection *cur = frag->isec;
|
||||
while (!cur || cur->file->priority > isec->file->priority)
|
||||
if (frag->isec.compare_exchange_weak(cur, isec))
|
||||
|
12
mold.h
12
mold.h
@ -198,7 +198,7 @@ struct SectionFragment {
|
||||
std::string_view data;
|
||||
u32 offset = -1;
|
||||
u16 alignment = 1;
|
||||
std::atomic_bool is_alive = false;
|
||||
std::atomic_bool is_alive = !config.gc_sections;
|
||||
};
|
||||
|
||||
struct SectionFragmentRef {
|
||||
@ -1170,8 +1170,11 @@ inline bool Symbol::is_absolute() const {
|
||||
}
|
||||
|
||||
inline u64 Symbol::get_addr() const {
|
||||
if (frag_ref.frag)
|
||||
return frag_ref.frag->get_addr() + frag_ref.addend;
|
||||
if (frag_ref.frag) {
|
||||
if (frag_ref.frag->is_alive)
|
||||
return frag_ref.frag->get_addr() + frag_ref.addend;
|
||||
return 0; // todo: do not return 0
|
||||
}
|
||||
|
||||
if (has_copyrel)
|
||||
return out::copyrel->shdr.sh_addr + value;
|
||||
@ -1224,6 +1227,9 @@ inline u64 Symbol::get_plt_addr() const {
|
||||
}
|
||||
|
||||
inline u64 SectionFragment::get_addr() const {
|
||||
if (!is_alive)
|
||||
return 0; // todo: remove
|
||||
|
||||
MergeableSection *is = isec.load();
|
||||
return is->parent.shdr.sh_addr + is->offset + offset;
|
||||
}
|
||||
|
@ -797,9 +797,7 @@ void MergedSection::copy_buf() {
|
||||
|
||||
i64 offset = 0;
|
||||
for (SectionFragment *frag : isec->fragments) {
|
||||
if (frag->isec != isec)
|
||||
continue;
|
||||
if (frag->offset < offset)
|
||||
if (frag->isec != isec || !frag->is_alive || frag->offset < offset)
|
||||
continue;
|
||||
|
||||
// Clear padding between section fragments
|
||||
|
Loading…
Reference in New Issue
Block a user