Computing .long .L123-.L100

Ian Lance Taylor ian@wasabisystems.com
Thu Jan 22 00:25:00 GMT 2004


Kazu Hirata <kazu@cs.umass.edu> writes:

> I have a question about computing the difference of two labels at
> assembly time.  Does gas/tc-<target>.c have to do something special?
> I thought defining DIFF_EXPR_OK would do the job, but it doesn't seem
> to.

You don't really need to define DIFF_EXPR_OK merely to compute the
difference of two labels.  gas will attempt to do that for you in all
cases.  DIFF_EXPR_OK really means that it's OK for gas to generate a
relocation for something like `foo - .'.

> Is a difference of two labels computed as soon as the values of both
> labels become available?

Well, it depends, but, in general, if both labels are in the same
frag, gas will reduce the subtraction immediately.  Note that this is
somewhat arbitrary, and in particular will generally not be the case
when producing a listing.

> While assembling the following piece of code
> on sh-elf, which does support the difference of two labels, I found
> that the value of .L3-.L9 seems to be computed from colon () in
> symbols.c.

I'm not really sure what you mean here.  I would expect the colon()
function to define the label's value, not to do any computation.

> Another related question is that sh_cons_fix_new() outputs a reloc for
> .long .L3-.L9., but the disassembly of the resulting object file does
> not contain the reloc anymore.  Where is such a reloc deleted?

In gas terminology, sh_cons_fix_new() generates a fixup.  Some fixups
are then computed by fixup_segment().  Others are passed to
tc_gen_reloc() to generate a reloc.

Ian



More information about the Binutils mailing list