12

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

3
  • I just found this searching for information on linker script includes. Do you still need help with this? What is the command line you're executing to invoke the linker? I would think an error in "flags" would occur at the command rather than inside the file. Commented Nov 26, 2013 at 15:04
  • Hi. I don't have any symbol name or linker filename called 'flags'. I have now worked around it by using sed in my makefile and replacing the include statement myself just before linking, and that works fine. Both files are located in the same directory, so that the file can definitely be found by the linker. Commented Nov 27, 2013 at 8:54
  • Ok, thanks for sharing that work-around. I would have thought when it said "flags" it meant "options" like command-line options. Commented Nov 30, 2013 at 3:48

3 Answers 3

13

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

Sign up to request clarification or add additional context in comments.

3 Comments

Yes! Genious, that fixes it. Thank you! Can this bug be tracked somewhere?
@richard_pennington That would be great. Have you already done so? I couldn't find it in the bug list.
I had a look at the bug list too, but also failed to find it. Interesting that ld doesn't seem to have a default assignee for bugs at the project level. :|
1

The include syntax should be correct, INCLUDE common.ld works fine here.

Maybe the Windows version of ld had a bug, or maybe there was something wrong with either one of your linker scripts or the environment?

Comments

0

I update my toolchain from arm_eabi-2011.03 to arm-2012.09. then problem appeared. I have to copy the INCLUDEd file to my link script, in order to avoid the "flag" issue.

I wonder how could a new version of toolchain ruined older version functions?

1 Comment

I guess a change in the parsing rules was not tested thoroughly enough. Did you try the accepted answer above (a space after the exclamation mark? It did the trick for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.