I have two linker scripts: common.ld
which defines some symbols, and app.ld
which positions the sections, using these defines.
If I just cat the two files together, and feed that to ld (via gcc), it works.
If I use the INCLUDE
command:
INCLUDE common.ld
I get the error:
ld.exe: invalid syntax in flags
collect2: ld returned 1 exit status
What do I do wrong? What is a correct statement to include another load script?
From http://www.scoberlin.de/content/media/http/informatik/gcc_docs/ld_3.html#IDX204 :
INCLUDE filename
Include the linker script filename at this point. The file will be searched for in the current directory, and in any directory specified with the -L option. You can nest calls to INCLUDE up to 10 levels deep.
Note: I'm running this on a Windows 7 PC, using arm gcc tools from Code Red, full version:
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.6.2 20121016 (release) [ARM/embedded-4_6-branch revision 192487
The default linker script used by GCC creates an ELF executable file, which includes startup code from the C library and also includes information which tells the loader where the various sections reside in memory.
Linker symbols that represent a data address: In C code, declare the variable as an extern variable. Then, refer to the value of the linker symbol using the & operator. Because the variable is at a valid data address, we know that a data pointer can represent the value.
Linker script formatYou write a linker script as a series of commands. Each command is either a keyword, possibly followed by arguments or an assignment to a symbol. You may separate commands using semicolons. Whitespace is generally ignored.
Linker Scripts The ld command language is a collection of statements; some are simple keywords setting a particular option, some are used to select and group input files or name output files; and two statement types have a fundamental and pervasive impact on the linking process.
This one is interesting. Apparently there is a bug in the ld command file lexer. I'm using binutils version 2.24 and had the same problem. One of your included files has a MEMORY command something like
MEMORY
{
rom (rx) : ORIGIN = 0x00000000, LENGTH = 64M
ram (!rx) : ORIGIN = 0x48000000, LENGTH = 32M
}
I think (but haven't proven) that the lexer is returning "!rx" instead of "rx" for the second attribute in an included file. Changing the MEMORY command to
MEMORY
{
rom (rx) : ORIGIN = 0x00000000, LENGTH = 64M
ram (! rx) : ORIGIN = 0x48000000, LENGTH = 32M
}
fixes the problem. I looked at ldlex.l and ldgram.y in the ld sources but couldn't find an obvious error before my eyes started to hurt.
Bug report: https://sourceware.org/bugzilla/show_bug.cgi?id=17900
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With