Skip to content

Commit

Permalink
Fix the section-shrinking relaxation
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Aug 24, 2024
1 parent 5e72d88 commit 2d39056
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/shrink-sections.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ void shrink_sections<E>(Context<E> &ctx) {
// Technically speaking, relaxing relocations may allow more relocations
// to be relaxed because the distance between a branch instruction and
// its target may decrease as a result of relaxation. That said, the
// number of such relocations is negligible in practice, so don't bother
// to handle them. We scan relocations only once here.
// number of such relocations is negligible (I tried to self-host mold
// on RISC-V as an experiment and found that the mold-built .text is
// only ~0.04% larger than that of GNU ld), so we don't bother to handle
// them. We scan relocations only once here.
tbb::parallel_for_each(ctx.objs, [&](ObjectFile<E> *file) {
for (std::unique_ptr<InputSection<E>> &isec : file->sections)
if (is_resizable(isec.get()))
Expand All @@ -114,6 +116,12 @@ void shrink_sections<E>(Context<E> &ctx) {
sym->value -= isec->extra.r_deltas[it - rels.begin()];
}
});

// Recompute sizes of executable sections
tbb::parallel_for_each(ctx.chunks, [&](Chunk<E> *chunk) {
if (chunk->to_osec() && (chunk->shdr.sh_flags & SHF_EXECINSTR))
chunk->compute_section_size(ctx);
});
}

// Returns the distance between a relocated place and a symbol.
Expand Down

0 comments on commit 2d39056

Please sign in to comment.