[PATCH] ld: Recalculate section addresses before relaxing when need_layout is set [PR34979]
Alan Modra
amodra@gmail.com
Sun Nov 8 22:38:04 GMT 2026
On Sun, Nov 08, 2026 at 02:33:19PM +0100, Zhuo Zhi wrote:
> PR ld/34979
> * ldlang.c (lang_relax_sections): If need_layout is true,
> recalculate section addresses before running relaxation passes.
I would need to be convinced that an extra sizing pass is of benefit
to other targets. If you really need to do this for riscv then I
think it should be done by increasing link_info.relax_pass, then not
doing anything on pass 0.
However, that won't cure the general problem, which is that section
vmas can change relative to other sections due to alignment
constraints. For example, given sections A, B and C with B having a
small alignment, and C a large alignment, if A shrinks in one
relaxation pass, it is quite possible that the distance between B and
C increases for the next relax pass. Relaxation is a tricky business.
If you undo relaxations done in a previous pass, then there is a very
real possibility of oscillation.
Often the best thing you can do is accept a little imperfection, and
by that I mean don't optimise right up to the limit but leave a little
slack for section movement.
--
Alan Modra
More information about the Binutils
mailing list