4

I am looking for the formal grammar of the linker script. Something similar to the ones given to lex and yacc but not with the other yacc baggage. May be I can find the yacc like grammar if I look directly in the source code of the ld. But I don't want to do that now.

I have seen this question and its answers, but it refers to manpages of ld. The manpages are fine to a large extent but they do specify things in somewhat ambiguous manner. For example, Take this snippet from the Assignment: Defining Symbols It says:

For example, to create an absolute symbol whose address is the last byte of an output section named .data:

 SECTIONS{ ...
   .data :
     {
       *(.data)
       _edata = ABSOLUTE(.) ;
     }
 ... }

How is one to interpret the ...?

This is one example. I may be able to interpret this one thing sufficiently accurately after some struggle; but there are many such examples; so my question is: is there a better and formal specification available for linker scripts? Something like the C grammar that you see in an appendix of the book The C Language by Ritchie and Kernighan?

Community
  • 1
  • 1
Tem Pora
  • 2,043
  • 2
  • 24
  • 30
  • Voting to close as resource rec. It is unlikely that any source will be more precise than the docs, besides the source code of course... I also encourage you to produce minimal Linux 32-bit asm examples and analyze them with objdump. – Ciro Santilli OurBigBook.com Oct 06 '15 at 21:41

1 Answers1

1

Inside GNU LD source, there is ldgram.y: A YACC grammar to parse a superset of the AT&T linker scripting language. Copyright (C) 1991-2015 Free Software Foundation, Inc. Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).

See also ld/Makefile.am for the source files that make up LD: ld_new_SOURCES = ldgram.y ldlex-wrapper.c lexsup.c ldlang.c \ mri.c ldctor.c ldmain.c \ ldwrite.c ldexp.c ldemul.c ldver.c ldmisc.c ldfile.c ldcref.c $(PLUGIN_C) \ ldbuildid.c

scottt
  • 7,008
  • 27
  • 37