public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* LD scripts - using expressions correctly
@ 2014-07-07 13:21 David Paterson
  2014-07-07 13:56 ` Alan Modra
  0 siblings, 1 reply; 7+ messages in thread
From: David Paterson @ 2014-07-07 13:21 UTC (permalink / raw)
  To: binutils

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-07-08  8:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-07 13:21 LD scripts - using expressions correctly David Paterson
2014-07-07 13:56 ` Alan Modra
2014-07-07 14:06   ` David Paterson
2014-07-07 14:36     ` Alan Modra
2014-07-07 14:46       ` David Paterson
2014-07-07 15:10         ` David Paterson
2014-07-08  8:33           ` David Paterson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).