This is the mail archive of the binutils@sourceware.org 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]

Re: linker script symbols syntax and other errors


Hi Klaus,

SECTIONS
{
 .text :
 {
   ./startup.o (.text)         /* Startup code */
    *(.text)
   *(.glue_7t) *(.glue_7)
 } >IntCodeRAM =0
 .ROM :
 {
     *(.linkToRam)
 }

1->    start_of_ROM   = .ROM;
2->  /* end_of_ROM     = .ROM + sizeof (.ROM) - 1;
}
----
The line 1 give a
test2.ld:134: undefined symbol `.ROM' referenced in expression

This is correct. .ROM is not a symbol defined in the symbol table of the executable, but rather a symbol in the SECTION directive's namespace. You can fix this by assigning the value of "." to start_of_ROM at the start of the .ROM section, like this:


} >IntCodeRAM =0

   . = .;                 /* <=== NEW */
   start_of_ROM = .;      /* <=== NEW */

   .ROM :
   {

Note, for an explanation of the ". = .;" line in the above snippet see the "Location Counter" section of the linker manual.


:test2.ld:50: syntax error

Also correct and for the same reason. You can fix this one as well, like this:


    *(linkToRam);
  }
  end_of_ROM = . - 1;

Assuming that you want end_of_ROM to be the address of the last byte in the .ROM section and not the address of the first byte after the end of the .ROM section.

what is the meaning of a PROVIDE statement? I read the manual 2 times, but it only confuses me.

OK, so basically what the PROVIDE statement does is to create a symbol and assign it a value, but only if the symbol has not appeared in any of the input files. So for example, suppose that you have this in your linker script:


PROVIDE (foo = 1);

Then if none of the input files define a symbol called "foo", the linker will create one and assign it the value of 1. If an input file does define a symbol called "foo" then the linker will use that version instead and ignore the value defined in the PROVIDE statement.

Essentially the PROVIDE statement allows the linker script to define a default value for a symbol which can be overridden by any of the input files.

Cheers
  Nick








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