This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Need explanation for CALC_ADDEND and RELOC_PROCESSING


Hi all,

I am trying to understand relocation addends, but looking at the code
confuses me.  My immediate interest is in the COFF format. There, the
addend is not stored in the file. Rather, it is calculated when reading
the relocations from the bfd file (see bfd/coffcode.h:
coff_slurp_reloc_table). A target can provide two macros to override
the standard behaviour: RELOC_PROCESSING and CALC_ADDEND.

What I don't understand is for example the negative addend calculated
by the default CALC_ADDEND in the following line:
      cache_ptr->addend = - (ptr->section->vma + ptr->value);

It seems to me that's some sort of fix for a linker problem, i.e. the
linker adds an offset once too much and the addend is used to bring
that back into line. At least that's how I interpret a rather long
comment in bfd/reloc.c on the apparently chaotic matter. A while back
another fellow seemed to have a similar problem in understanding this:
(http://sources.redhat.com/ml/binutils/1999-q3/msg00637.html)

However, some targets don't seem to need this, because they redefine
CALC_ADDEND and/or RELOC_PROCESSING to do something rather more simple.
If there is a problem in the linker, why does it work for those targets
(i.e. h8500)? And even more confusing, the h8500 target for example
redefines BOTH macros, although (in my understanding of the code)
CALC_ADDEND is superfluous if you define RELOC_PROCESSING.

Is it just my impression that this addend thing is rather messy? Could
someone explain what it *ought* to do and maybe then explain the
history of it, i.e. why it became so confusing?

BTW I also read the description of addend in the libbfd manual (chapter
2.10.1), but I still have difficulties to understand it. For example,
if coff doesn't store the addend in the m88k example, how can it be
calculated?

Cheers
Stefan


__________________________________________________________________

Gesendet von Yahoo! Mail - http://mail.yahoo.de
Yahoo! präsentiert als offizieller Sponsor das Fußball-Highlight des
Jahres: - http://www.FIFAworldcup.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]