Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the INCLUDE command in ld linker script

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

like image 723
parvus Avatar asked Oct 08 '13 15:10

parvus


People also ask

What does a linker script include?

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.

How do you declare a variable in linker?

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.

How do you use linker scripts?

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.

What is LD linker script?

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.


1 Answers

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

like image 136
Richard Pennington Avatar answered Oct 03 '22 00:10

Richard Pennington