This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
LD scripts - using expressions correctly
- From: David Paterson <dnpaterson at gmail dot com>
- To: binutils at sourceware dot org
- Date: Mon, 7 Jul 2014 14:21:17 +0100
- Subject: LD scripts - using expressions correctly
- Authentication-results: sourceware.org; auth=none
Hi folks,
I'm trying to use expressions to calculate addresses in a script but
keep getting some odd results.
My plan is, rather than having different scripts for different build
configurations, to allow users to select link options via defined
symbols.
For example, in some systems, code may execute faster from RAM, so it
might be required to copy the text section to the start of RAM.
However, the trap table might also be copied to RAM if it has to be
modified by the user's code (this is on a SPARC system BTW) so a gap
needs to be left for the trap table.
My linker script contains the following lines (I think the symbols are
self-explanatory) :-
_textLMA = .;
_textoffset = _traps_ram ? (_exec_rom ? 0 : 4K) : 0;
_textVMA = (_exec_rom > 0) ? _textLMA : _ram_start;
_textVMA += _textoffset;
. = _textVMA;
_wherestext1 = .;
.text . : AT (_textLMA)
{
_wherestext2 = .;
*(.text)
etc.
However, the text section isn't being located correctly. If I set
_traps_ram=1, and _exec_rom=0, I get :-
Idx Name Size VMA LMA File off Algn
0 .crttext 000014a8 00000000 00000000 00010000 2**3
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .text 00009b60 40000000 000014a8 00020000 2**3
CONTENTS, ALLOC, LOAD, READONLY, CODE
(crttext is a boot section which contains the ROM trap table and basic
boot code)
Even stranger, the two "wheres..." debug symbols I added have the
following values :-
40001000 g .text 00000000 _wherestext1
40000000 g .text 00000000 _wherestext2
Reading the manual, I understand that LD uses "lazy evaluation" for
expressions, but this is just baffling me - it does seem to have the
correct value somewhere internally, it just isn't using it for the
section address. Substituting "_textVMA" or "_wherestext1" for the
"." in the section definition doesn't work either, which is even more
puzzling.
Any ideas or suggestions would be appreciated, as this is slowly
driving me mad... :-)
Regards,
David P.