diff --git a/src/shrink-sections.cc b/src/shrink-sections.cc index aa591cc9c4..cfd3f4b37b 100644 --- a/src/shrink-sections.cc +++ b/src/shrink-sections.cc @@ -87,8 +87,10 @@ void shrink_sections(Context &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 *file) { for (std::unique_ptr> &isec : file->sections) if (is_resizable(isec.get())) @@ -114,6 +116,12 @@ void shrink_sections(Context &ctx) { sym->value -= isec->extra.r_deltas[it - rels.begin()]; } }); + + // Recompute sizes of executable sections + tbb::parallel_for_each(ctx.chunks, [&](Chunk *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.