GNU LD: Linker script generating incorrect address
Erik Christiansen
dvalin@internode.on.net
Tue May 21 11:19:00 GMT 2013
Hi Jens,
The relevant "info ld" section is "3.10.5 The Location Counter", which
makes the point that a '.' assignment inside an output section is
relative to the start of that section, _not_ absolute.
An expression like your "_lustack = _eustack - _sustack;" will provide
a size, because the difference is the same, whether the addresses are
absolute, or relative _and_ set in the current section.
One simple way to gain absolute addresses, is e.g.:
» ABSOLUTE: For an absolute symbol giving the address of the end of the
output section .data:
.data : { *(.data) _edata = ABSOLUTE(.); }
By default, _edata would be relative to the .data section.
«
Another way to make it absolute is the form appearing in many scripts:
_edata = ADDR(.data) + SIZOF(.data) ;
The line should be placed outside (after) the .data section.
A third way which should work is:
_edata = ADDR(.data) + _data_size ;
where _data_size is from an "__data_size = . ;" assignment within the
.data section. (i.e. assignments like yours, lacking the ABSOLUTE
operator. This last expression mixes absolute and relative values in a
workable way. (AIUI, (relative + absolute) = absolute, if the right
absolute is used, else it's an error, because you're missing a third
value.)
I haven't read your post in ultimate detail, so hope I have the nub of the
problem.
møjn,
Erik
--
Leibowitz's Rule:
When hammering a nail, you will never hit your finger if you hold the
hammer with both hands.
More information about the Binutils
mailing list