blob: 0bd2b603b2e52ea9266c5ea98f3453d9e09789f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/* yyscript.y -- linker script grammer for gold. */
/* This is a bison grammar to parse a subset of the original GNU ld
linker script language. */
%{
#include "config.h"
#include <stddef.h>
#include <stdint.h>
#include "script-c.h"
%}
/* We need to use a pure parser because we might be multi-threaded.
We pass some arguments through the parser to the lexer. */
%pure-parser
%parse-param {void* closure}
%lex-param {void* closure}
/* Since we require bison anyhow, we take advantage of it. */
%error-verbose
/* The values associated with tokens. */
%union {
const char* string;
int64_t integer;
}
/* Operators, including a precedence table for expressions. */
%right PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
%right '?' ':'
%left OROR
%left ANDAND
%left '|'
%left '^'
%left '&'
%left EQ NE
%left '<' '>' LE GE
%left LSHIFT RSHIFT
%left '+' '-'
%left '*' '/' '%'
/* Constants. */
%token <string> STRING
%token <integer> INTEGER
/* Keywords. This list is taken from ldgram.y and ldlex.l in the old
GNU linker, with the keywords which only appear in MRI mode
removed. Not all these keywords are actually used in this grammar.
In most cases the keyword is recognized as the token name in upper
case. The comments indicate where this is not the case. */
%token ABSOLUTE
%token ADDR
%token ALIGN_K /* ALIGN */
%token ASSERT_K /* ASSERT */
%token AS_NEEDED
%token AT
%token BIND
%token BLOCK
%token BYTE
%token CONSTANT
%token CONSTRUCTORS
%token COPY
%token CREATE_OBJECT_SYMBOLS
%token DATA_SEGMENT_ALIGN
%token DATA_SEGMENT_END
%token DATA_SEGMENT_RELRO_END
%token DEFINED
%token DSECT
%token ENTRY
%token EXCLUDE_FILE
%token EXTERN
%token FILL
%token FLOAT
%token FORCE_COMMON_ALLOCATION
%token GLOBAL /* global */
%token GROUP
%token HLL
%token INCLUDE
%token INFO
%token INHIBIT_COMMON_ALLOCATION
%token INPUT
%token KEEP
%token LENGTH /* LENGTH, l, len */
%token LOADADDR
%token LOCAL /* local */
%token LONG
%token MAP
%token MAX_K /* MAX */
%token MEMORY
%token MIN_K /* MIN */
%token NEXT
%token NOCROSSREFS
%token NOFLOAT
%token NOLOAD
%token ONLY_IF_RO
%token ONLY_IF_RW
%token ORIGIN /* ORIGIN, o, org */
%token OUTPUT
%token OUTPUT_ARCH
%token OUTPUT_FORMAT
%token OVERLAY
%token PHDRS
%token PROVIDE
%token PROVIDE_HIDDEN
%token QUAD
%token SEARCH_DIR
%token SECTIONS
%token SEGMENT_START
%token SHORT
%token SIZEOF
%token SIZEOF_HEADERS /* SIZEOF_HEADERS, sizeof_headers */
%token SORT_BY_ALIGNMENT
%token SORT_BY_NAME
%token SPECIAL
%token SQUAD
%token STARTUP
%token SUBALIGN
%token SYSLIB
%token TARGET_K /* TARGET */
%token TRUNCATE
%token VERSIONK /* VERSION */
%%
file_list:
file_list file_cmd
| /* empty */
;
file_cmd:
OUTPUT_FORMAT '(' STRING ')'
| GROUP
{ script_start_group(closure); }
'(' input_list ')'
{ script_end_group(closure); }
;
input_list:
input_list_element
| input_list opt_comma input_list_element
;
input_list_element:
STRING
{ script_add_file(closure, $1); }
| AS_NEEDED
{ script_start_as_needed(closure); }
'(' input_list ')'
{ script_end_as_needed(closure); }
;
opt_comma:
','
| /* empty */
;
%%
|