This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: GNU LD: Linker script generating incorrect address
- From: Erik Christiansen <dvalin at internode dot on dot net>
- To: Jens Bauer <jens-lists at gpio dot dk>
- Cc: binutils at sourceware dot org
- Date: Tue, 21 May 2013 21:19:09 +1000
- Subject: Re: GNU LD: Linker script generating incorrect address
- References: <20130521062602780057 dot 62ec95fc at gpio dot dk>
- Reply-to: dvalin at internode dot on dot net
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.