Understanding fragP->fr_address in md_estimate_size_before_relax
Alan Modra
amodra@gmail.com
Tue Apr 11 02:15:47 GMT 2023
On Mon, Apr 10, 2023 at 10:40:51AM +0200, Thomas Koenig wrote:
> Hi Alan,
>
> > > I'm currently trying to do a binutils port of a yet-to-be-released ISA,
> > > and I have some trouble understanding relax. I'm looking at RISC-V
> > > as an example, but I am still somewhat confused.
> > >
> > > One point I am wondering about is the use of fragP->fr_address in
> > > md_estimate_size_before_relax. Looking at the RISC-V port (which
> > > does relax) as an example, I see that fragp->fr_address is always zero
> > > on every invocation,
> >
> > It should not always be zero. fr_address starts off as zero, but
> > non-zero addresses will be assigned in relax_segment. If addresses
> > change (which they always will) relax_seg should be called multiple
> > times for a given section.
>
> Ah, I misread my test cases (and apparently misunderstood fr_fix).
>
> The main problem I am facing at the moment is that the documentation
> is less than clear (to me) on what each function should do, and
> especially how variable length frags should be treated.
>
> For example, the doc on md_estimate_size_before_relax states
>
> "This function returns an estimate of the size of a rs_machine_dependent
> frag before any relaxing is done. It may also create any necessary
> relocations."
>
> Which size exactly is meant by that?
>
> Looking at a RISC-V example (source code attached), frag_var is called
> with max_chars=8 and var=4:
It is probably better to look at the code calling
md_estimate_size_before_relax rather than a particular
implementation. Loking at gas/write.c relax_segment you'll see that
fr_fix is added to the address for all frag types, then for
rs_machine_dependent the return from md_estimate_size_before_relax is
added. So the size is that for the variable part of the frag. This
can be either the minimum or maximum size or any reasonable size in
between, but that value must not be forgotten as it will be an input
to md_relax_frag where the actual sizing is done. The generic
relax_frag tracks the estimate using fr_subtype.
Note that the interpretation of many of the fields of struct frag for
fr_type == rs_machine_dependent depends on the implementation. You
don't need to use fr_var.
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list