Tem Pora
Tem Pora

Reputation: 2093

where can I find the formal ld linker script syntax?

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?

Upvotes: 4

Views: 1123

Answers (1)

scottt
scottt

Reputation: 7228

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 ([email protected]).

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

Upvotes: 1

Related Questions