4fd1a7e2c047e16de5b3e91820f607037b609a74
[platform/upstream/elfutils.git] / src / ldscript.c
1 /* A Bison parser, made by GNU Bison 2.5.  */
2
3 /* Bison implementation for Yacc-like parsers in C
4    
5       Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc.
6    
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 /* As a special exception, you may create a larger work that contains
21    part or all of the Bison parser skeleton and distribute that work
22    under terms of your choice, so long as that work isn't itself a
23    parser generator using the skeleton or a modified version thereof
24    as a parser skeleton.  Alternatively, if you modify or redistribute
25    the parser skeleton itself, you may (at your option) remove this
26    special exception, which will cause the skeleton and the resulting
27    Bison output files to be licensed under the GNU General Public
28    License without this special exception.
29    
30    This special exception was added by the Free Software Foundation in
31    version 2.2 of Bison.  */
32
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34    simplifying the original so-called "semantic" parser.  */
35
36 /* All symbols defined below should begin with yy or YY, to avoid
37    infringing on user name space.  This should be done even for local
38    variables, as they might otherwise be expanded by user macros.
39    There are some unavoidable exceptions within include files to
40    define necessary library symbols; they are noted "INFRINGES ON
41    USER NAME SPACE" below.  */
42
43 /* Identify Bison output.  */
44 #define YYBISON 1
45
46 /* Bison version.  */
47 #define YYBISON_VERSION "2.5"
48
49 /* Skeleton name.  */
50 #define YYSKELETON_NAME "yacc.c"
51
52 /* Pure parsers.  */
53 #define YYPURE 0
54
55 /* Push parsers.  */
56 #define YYPUSH 0
57
58 /* Pull parsers.  */
59 #define YYPULL 1
60
61 /* Using locations.  */
62 #define YYLSP_NEEDED 0
63
64 /* Substitute the variable and function names.  */
65 #define yyparse         ldparse
66 #define yylex           ldlex
67 #define yyerror         lderror
68 #define yylval          ldlval
69 #define yychar          ldchar
70 #define yydebug         lddebug
71 #define yynerrs         ldnerrs
72
73
74 /* Copy the first part of user declarations.  */
75
76 /* Line 268 of yacc.c  */
77 #line 1 "ldscript.y"
78
79 /* Parser for linker scripts.
80    Copyright (C) 2001-2011 Red Hat, Inc.
81    This file is part of elfutils.
82    Written by Ulrich Drepper <drepper@redhat.com>, 2001.
83
84    This file is free software; you can redistribute it and/or modify
85    it under the terms of the GNU General Public License as published by
86    the Free Software Foundation; either version 3 of the License, or
87    (at your option) any later version.
88
89    elfutils is distributed in the hope that it will be useful, but
90    WITHOUT ANY WARRANTY; without even the implied warranty of
91    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
92    GNU General Public License for more details.
93
94    You should have received a copy of the GNU General Public License
95    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
96
97 #ifdef HAVE_CONFIG_H
98 # include <config.h>
99 #endif
100
101 #include <assert.h>
102 #include <error.h>
103 #include <libintl.h>
104 #include <stdbool.h>
105 #include <stdint.h>
106 #include <stdio.h>
107 #include <stdlib.h>
108 #include <string.h>
109
110 #include <system.h>
111 #include <ld.h>
112
113 /* The error handler.  */
114 static void yyerror (const char *s);
115
116 /* Some helper functions we need to construct the data structures
117    describing information from the file.  */
118 static struct expression *new_expr (int tag);
119 static struct input_section_name *new_input_section_name (const char *name,
120                                                           bool sort_flag);
121 static struct input_rule *new_input_rule (int tag);
122 static struct output_rule *new_output_rule (int tag);
123 static struct assignment *new_assignment (const char *variable,
124                                           struct expression *expression,
125                                           bool provide_flag);
126 static void new_segment (int mode, struct output_rule *output_rule);
127 static struct filename_list *new_filename_listelem (const char *string);
128 static void add_inputfiles (struct filename_list *fnames);
129 static struct id_list *new_id_listelem (const char *str);
130  static struct filename_list *mark_as_needed (struct filename_list *listp);
131 static struct version *new_version (struct id_list *local,
132                                     struct id_list *global);
133 static struct version *merge_versions (struct version *one,
134                                        struct version *two);
135 static void add_versions (struct version *versions);
136
137 extern int yylex (void);
138
139
140 /* Line 268 of yacc.c  */
141 #line 142 "ldscript.c"
142
143 /* Enabling traces.  */
144 #ifndef YYDEBUG
145 # define YYDEBUG 0
146 #endif
147
148 /* Enabling verbose error messages.  */
149 #ifdef YYERROR_VERBOSE
150 # undef YYERROR_VERBOSE
151 # define YYERROR_VERBOSE 1
152 #else
153 # define YYERROR_VERBOSE 0
154 #endif
155
156 /* Enabling the token table.  */
157 #ifndef YYTOKEN_TABLE
158 # define YYTOKEN_TABLE 0
159 #endif
160
161
162 /* Tokens.  */
163 #ifndef YYTOKENTYPE
164 # define YYTOKENTYPE
165    /* Put the tokens into the symbol table, so that GDB and other debuggers
166       know about them.  */
167    enum yytokentype {
168      kADD_OP = 258,
169      kALIGN = 259,
170      kAS_NEEDED = 260,
171      kENTRY = 261,
172      kEXCLUDE_FILE = 262,
173      kFILENAME = 263,
174      kGLOBAL = 264,
175      kGROUP = 265,
176      kID = 266,
177      kINPUT = 267,
178      kINTERP = 268,
179      kKEEP = 269,
180      kLOCAL = 270,
181      kMODE = 271,
182      kMUL_OP = 272,
183      kNUM = 273,
184      kOUTPUT_FORMAT = 274,
185      kPAGESIZE = 275,
186      kPROVIDE = 276,
187      kSEARCH_DIR = 277,
188      kSEGMENT = 278,
189      kSIZEOF_HEADERS = 279,
190      kSORT = 280,
191      kVERSION = 281,
192      kVERSION_SCRIPT = 282,
193      ADD_OP = 283,
194      MUL_OP = 284
195    };
196 #endif
197 /* Tokens.  */
198 #define kADD_OP 258
199 #define kALIGN 259
200 #define kAS_NEEDED 260
201 #define kENTRY 261
202 #define kEXCLUDE_FILE 262
203 #define kFILENAME 263
204 #define kGLOBAL 264
205 #define kGROUP 265
206 #define kID 266
207 #define kINPUT 267
208 #define kINTERP 268
209 #define kKEEP 269
210 #define kLOCAL 270
211 #define kMODE 271
212 #define kMUL_OP 272
213 #define kNUM 273
214 #define kOUTPUT_FORMAT 274
215 #define kPAGESIZE 275
216 #define kPROVIDE 276
217 #define kSEARCH_DIR 277
218 #define kSEGMENT 278
219 #define kSIZEOF_HEADERS 279
220 #define kSORT 280
221 #define kVERSION 281
222 #define kVERSION_SCRIPT 282
223 #define ADD_OP 283
224 #define MUL_OP 284
225
226
227
228
229 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
230 typedef union YYSTYPE
231 {
232
233 /* Line 293 of yacc.c  */
234 #line 63 "ldscript.y"
235
236   uintmax_t num;
237   enum expression_tag op;
238   char *str;
239   struct expression *expr;
240   struct input_section_name *sectionname;
241   struct filemask_section_name *filemask_section_name;
242   struct input_rule *input_rule;
243   struct output_rule *output_rule;
244   struct assignment *assignment;
245   struct filename_list *filename_list;
246   struct version *version;
247   struct id_list *id_list;
248
249
250
251 /* Line 293 of yacc.c  */
252 #line 253 "ldscript.c"
253 } YYSTYPE;
254 # define YYSTYPE_IS_TRIVIAL 1
255 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
256 # define YYSTYPE_IS_DECLARED 1
257 #endif
258
259
260 /* Copy the second part of user declarations.  */
261
262
263 /* Line 343 of yacc.c  */
264 #line 265 "ldscript.c"
265
266 #ifdef short
267 # undef short
268 #endif
269
270 #ifdef YYTYPE_UINT8
271 typedef YYTYPE_UINT8 yytype_uint8;
272 #else
273 typedef unsigned char yytype_uint8;
274 #endif
275
276 #ifdef YYTYPE_INT8
277 typedef YYTYPE_INT8 yytype_int8;
278 #elif (defined __STDC__ || defined __C99__FUNC__ \
279      || defined __cplusplus || defined _MSC_VER)
280 typedef signed char yytype_int8;
281 #else
282 typedef short int yytype_int8;
283 #endif
284
285 #ifdef YYTYPE_UINT16
286 typedef YYTYPE_UINT16 yytype_uint16;
287 #else
288 typedef unsigned short int yytype_uint16;
289 #endif
290
291 #ifdef YYTYPE_INT16
292 typedef YYTYPE_INT16 yytype_int16;
293 #else
294 typedef short int yytype_int16;
295 #endif
296
297 #ifndef YYSIZE_T
298 # ifdef __SIZE_TYPE__
299 #  define YYSIZE_T __SIZE_TYPE__
300 # elif defined size_t
301 #  define YYSIZE_T size_t
302 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
303      || defined __cplusplus || defined _MSC_VER)
304 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
305 #  define YYSIZE_T size_t
306 # else
307 #  define YYSIZE_T unsigned int
308 # endif
309 #endif
310
311 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
312
313 #ifndef YY_
314 # if defined YYENABLE_NLS && YYENABLE_NLS
315 #  if ENABLE_NLS
316 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
317 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
318 #  endif
319 # endif
320 # ifndef YY_
321 #  define YY_(msgid) msgid
322 # endif
323 #endif
324
325 /* Suppress unused-variable warnings by "using" E.  */
326 #if ! defined lint || defined __GNUC__
327 # define YYUSE(e) ((void) (e))
328 #else
329 # define YYUSE(e) /* empty */
330 #endif
331
332 /* Identity function, used to suppress warnings about constant conditions.  */
333 #ifndef lint
334 # define YYID(n) (n)
335 #else
336 #if (defined __STDC__ || defined __C99__FUNC__ \
337      || defined __cplusplus || defined _MSC_VER)
338 static int
339 YYID (int yyi)
340 #else
341 static int
342 YYID (yyi)
343     int yyi;
344 #endif
345 {
346   return yyi;
347 }
348 #endif
349
350 #if ! defined yyoverflow || YYERROR_VERBOSE
351
352 /* The parser invokes alloca or malloc; define the necessary symbols.  */
353
354 # ifdef YYSTACK_USE_ALLOCA
355 #  if YYSTACK_USE_ALLOCA
356 #   ifdef __GNUC__
357 #    define YYSTACK_ALLOC __builtin_alloca
358 #   elif defined __BUILTIN_VA_ARG_INCR
359 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
360 #   elif defined _AIX
361 #    define YYSTACK_ALLOC __alloca
362 #   elif defined _MSC_VER
363 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
364 #    define alloca _alloca
365 #   else
366 #    define YYSTACK_ALLOC alloca
367 #    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
368      || defined __cplusplus || defined _MSC_VER)
369 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
370 #     ifndef EXIT_SUCCESS
371 #      define EXIT_SUCCESS 0
372 #     endif
373 #    endif
374 #   endif
375 #  endif
376 # endif
377
378 # ifdef YYSTACK_ALLOC
379    /* Pacify GCC's `empty if-body' warning.  */
380 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
381 #  ifndef YYSTACK_ALLOC_MAXIMUM
382     /* The OS might guarantee only one guard page at the bottom of the stack,
383        and a page size can be as small as 4096 bytes.  So we cannot safely
384        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
385        to allow for a few compiler-allocated temporary stack slots.  */
386 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
387 #  endif
388 # else
389 #  define YYSTACK_ALLOC YYMALLOC
390 #  define YYSTACK_FREE YYFREE
391 #  ifndef YYSTACK_ALLOC_MAXIMUM
392 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
393 #  endif
394 #  if (defined __cplusplus && ! defined EXIT_SUCCESS \
395        && ! ((defined YYMALLOC || defined malloc) \
396              && (defined YYFREE || defined free)))
397 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
398 #   ifndef EXIT_SUCCESS
399 #    define EXIT_SUCCESS 0
400 #   endif
401 #  endif
402 #  ifndef YYMALLOC
403 #   define YYMALLOC malloc
404 #   if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
405      || defined __cplusplus || defined _MSC_VER)
406 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
407 #   endif
408 #  endif
409 #  ifndef YYFREE
410 #   define YYFREE free
411 #   if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
412      || defined __cplusplus || defined _MSC_VER)
413 void free (void *); /* INFRINGES ON USER NAME SPACE */
414 #   endif
415 #  endif
416 # endif
417 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
418
419
420 #if (! defined yyoverflow \
421      && (! defined __cplusplus \
422          || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
423
424 /* A type that is properly aligned for any stack member.  */
425 union yyalloc
426 {
427   yytype_int16 yyss_alloc;
428   YYSTYPE yyvs_alloc;
429 };
430
431 /* The size of the maximum gap between one aligned stack and the next.  */
432 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
433
434 /* The size of an array large to enough to hold all stacks, each with
435    N elements.  */
436 # define YYSTACK_BYTES(N) \
437      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
438       + YYSTACK_GAP_MAXIMUM)
439
440 # define YYCOPY_NEEDED 1
441
442 /* Relocate STACK from its old location to the new one.  The
443    local variables YYSIZE and YYSTACKSIZE give the old and new number of
444    elements in the stack, and YYPTR gives the new location of the
445    stack.  Advance YYPTR to a properly aligned location for the next
446    stack.  */
447 # define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
448     do                                                                  \
449       {                                                                 \
450         YYSIZE_T yynewbytes;                                            \
451         YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
452         Stack = &yyptr->Stack_alloc;                                    \
453         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
454         yyptr += yynewbytes / sizeof (*yyptr);                          \
455       }                                                                 \
456     while (YYID (0))
457
458 #endif
459
460 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
461 /* Copy COUNT objects from FROM to TO.  The source and destination do
462    not overlap.  */
463 # ifndef YYCOPY
464 #  if defined __GNUC__ && 1 < __GNUC__
465 #   define YYCOPY(To, From, Count) \
466       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
467 #  else
468 #   define YYCOPY(To, From, Count)              \
469       do                                        \
470         {                                       \
471           YYSIZE_T yyi;                         \
472           for (yyi = 0; yyi < (Count); yyi++)   \
473             (To)[yyi] = (From)[yyi];            \
474         }                                       \
475       while (YYID (0))
476 #  endif
477 # endif
478 #endif /* !YYCOPY_NEEDED */
479
480 /* YYFINAL -- State number of the termination state.  */
481 #define YYFINAL  32
482 /* YYLAST -- Last index in YYTABLE.  */
483 #define YYLAST   226
484
485 /* YYNTOKENS -- Number of terminals.  */
486 #define YYNTOKENS  40
487 /* YYNNTS -- Number of nonterminals.  */
488 #define YYNNTS  23
489 /* YYNRULES -- Number of rules.  */
490 #define YYNRULES  66
491 /* YYNRULES -- Number of states.  */
492 #define YYNSTATES  159
493
494 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
495 #define YYUNDEFTOK  2
496 #define YYMAXUTOK   284
497
498 #define YYTRANSLATE(YYX)                                                \
499   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
500
501 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
502 static const yytype_uint8 yytranslate[] =
503 {
504        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
505        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
506        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
507        2,     2,     2,     2,     2,     2,     2,     2,    29,     2,
508       33,    34,    31,     2,    39,     2,     2,     2,     2,     2,
509        2,     2,     2,     2,     2,     2,     2,     2,     2,    35,
510        2,    38,     2,     2,     2,     2,     2,     2,     2,     2,
511        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
512        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
513        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
514        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
515        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
516        2,     2,     2,    36,    28,    37,     2,     2,     2,     2,
517        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
518        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
519        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
520        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
521        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
522        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
523        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
524        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
525        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
526        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
527        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
528        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
529        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
530        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
531       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
532       25,    26,    27,    30,    32
533 };
534
535 #if YYDEBUG
536 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
537    YYRHS.  */
538 static const yytype_uint8 yyprhs[] =
539 {
540        0,     0,     3,     5,     8,    11,    13,    19,    25,    31,
541       37,    43,    49,    54,    59,    64,    69,    74,    77,    79,
542       82,    87,    90,    94,   101,   104,   106,   108,   113,   116,
543      122,   124,   129,   134,   135,   140,   144,   148,   152,   156,
544      160,   164,   166,   168,   170,   172,   176,   178,   180,   181,
545      186,   191,   193,   196,   198,   203,   209,   216,   219,   221,
546      224,   227,   231,   234,   236,   238,   240
547 };
548
549 /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
550 static const yytype_int8 yyrhs[] =
551 {
552       41,     0,    -1,    42,    -1,    27,    56,    -1,    42,    43,
553       -1,    43,    -1,     6,    33,    11,    34,    35,    -1,    22,
554       33,    61,    34,    35,    -1,    20,    33,    18,    34,    35,
555       -1,    13,    33,    61,    34,    35,    -1,    23,    16,    36,
556       44,    37,    -1,    23,     1,    36,    44,    37,    -1,    10,
557       33,    53,    34,    -1,    12,    33,    53,    34,    -1,     5,
558       33,    53,    34,    -1,    26,    36,    56,    37,    -1,    19,
559       33,    61,    34,    -1,    44,    45,    -1,    45,    -1,    46,
560       35,    -1,    11,    36,    47,    37,    -1,    11,    35,    -1,
561       11,    38,    52,    -1,    21,    33,    11,    38,    52,    34,
562       -1,    47,    48,    -1,    48,    -1,    49,    -1,    14,    33,
563       49,    34,    -1,    46,    35,    -1,    62,    33,    51,    50,
564       34,    -1,    11,    -1,    25,    33,    11,    34,    -1,     7,
565       33,    61,    34,    -1,    -1,     4,    33,    52,    34,    -1,
566       33,    52,    34,    -1,    52,    31,    52,    -1,    52,    17,
567       52,    -1,    52,     3,    52,    -1,    52,    29,    52,    -1,
568       52,    28,    52,    -1,    18,    -1,    11,    -1,    24,    -1,
569       20,    -1,    53,    54,    55,    -1,    55,    -1,    39,    -1,
570       -1,    10,    33,    53,    34,    -1,     5,    33,    53,    34,
571       -1,    61,    -1,    56,    57,    -1,    57,    -1,    36,    58,
572       37,    35,    -1,    61,    36,    58,    37,    35,    -1,    61,
573       36,    58,    37,    61,    35,    -1,    58,    59,    -1,    59,
574       -1,     9,    60,    -1,    15,    60,    -1,    60,    62,    35,
575       -1,    62,    35,    -1,     8,    -1,    11,    -1,    61,    -1,
576       31,    -1
577 };
578
579 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
580 static const yytype_uint16 yyrline[] =
581 {
582        0,   135,   135,   136,   140,   141,   144,   149,   153,   158,
583      164,   168,   174,   185,   187,   189,   191,   195,   200,   204,
584      209,   221,   245,   247,   251,   256,   260,   265,   272,   279,
585      290,   292,   296,   299,   302,   307,   309,   315,   321,   327,
586      333,   339,   344,   349,   351,   355,   360,   364,   365,   368,
587      379,   381,   386,   391,   395,   401,   407,   416,   418,   422,
588      424,   429,   435,   439,   441,   445,   447
589 };
590 #endif
591
592 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
593 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
594    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
595 static const char *const yytname[] =
596 {
597   "$end", "error", "$undefined", "kADD_OP", "kALIGN", "kAS_NEEDED",
598   "kENTRY", "kEXCLUDE_FILE", "kFILENAME", "kGLOBAL", "kGROUP", "kID",
599   "kINPUT", "kINTERP", "kKEEP", "kLOCAL", "kMODE", "kMUL_OP", "kNUM",
600   "kOUTPUT_FORMAT", "kPAGESIZE", "kPROVIDE", "kSEARCH_DIR", "kSEGMENT",
601   "kSIZEOF_HEADERS", "kSORT", "kVERSION", "kVERSION_SCRIPT", "'|'", "'&'",
602   "ADD_OP", "'*'", "MUL_OP", "'('", "')'", "';'", "'{'", "'}'", "'='",
603   "','", "$accept", "script_or_version", "file", "content",
604   "outputsections", "outputsection", "assignment", "inputsections",
605   "inputsection", "sectionname", "sort_opt_name", "exclude_opt", "expr",
606   "filename_id_list", "comma_opt", "filename_id_listelem", "versionlist",
607   "version", "version_stmt_list", "version_stmt", "filename_id_star_list",
608   "filename_id", "filename_id_star", 0
609 };
610 #endif
611
612 # ifdef YYPRINT
613 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
614    token YYLEX-NUM.  */
615 static const yytype_uint16 yytoknum[] =
616 {
617        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
618      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
619      275,   276,   277,   278,   279,   280,   281,   282,   124,    38,
620      283,    42,   284,    40,    41,    59,   123,   125,    61,    44
621 };
622 # endif
623
624 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
625 static const yytype_uint8 yyr1[] =
626 {
627        0,    40,    41,    41,    42,    42,    43,    43,    43,    43,
628       43,    43,    43,    43,    43,    43,    43,    44,    44,    45,
629       45,    45,    46,    46,    47,    47,    48,    48,    48,    49,
630       50,    50,    51,    51,    52,    52,    52,    52,    52,    52,
631       52,    52,    52,    52,    52,    53,    53,    54,    54,    55,
632       55,    55,    56,    56,    57,    57,    57,    58,    58,    59,
633       59,    60,    60,    61,    61,    62,    62
634 };
635
636 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
637 static const yytype_uint8 yyr2[] =
638 {
639        0,     2,     1,     2,     2,     1,     5,     5,     5,     5,
640        5,     5,     4,     4,     4,     4,     4,     2,     1,     2,
641        4,     2,     3,     6,     2,     1,     1,     4,     2,     5,
642        1,     4,     4,     0,     4,     3,     3,     3,     3,     3,
643        3,     1,     1,     1,     1,     3,     1,     1,     0,     4,
644        4,     1,     2,     1,     4,     5,     6,     2,     1,     2,
645        2,     3,     2,     1,     1,     1,     1
646 };
647
648 /* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
649    Performed when YYTABLE doesn't specify something else to do.  Zero
650    means the default is an error.  */
651 static const yytype_uint8 yydefact[] =
652 {
653        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
654        0,     0,     0,     2,     5,     0,     0,     0,     0,     0,
655        0,     0,     0,     0,     0,     0,    63,    64,     0,     3,
656       53,     0,     1,     4,     0,     0,    48,    46,    51,     0,
657       48,    48,     0,     0,     0,     0,     0,     0,     0,     0,
658        0,     0,    58,    52,     0,     0,     0,    14,    47,     0,
659        0,    12,    13,     0,    16,     0,     0,     0,     0,     0,
660       18,     0,     0,    15,    66,    59,    65,     0,    60,     0,
661       57,     0,    48,    48,    45,     6,     9,     8,     7,    21,
662        0,     0,     0,    11,    17,    19,    10,     0,    62,    54,
663        0,    50,    49,    64,     0,     0,     0,    25,    26,     0,
664        0,    42,    41,    44,    43,     0,    22,     0,    61,    55,
665        0,     0,    28,    20,    24,    33,     0,     0,     0,     0,
666        0,     0,     0,     0,    56,     0,     0,     0,     0,    35,
667       38,    37,    40,    39,    36,     0,    27,     0,    30,     0,
668        0,    34,    23,     0,     0,    29,    32,     0,    31
669 };
670
671 /* YYDEFGOTO[NTERM-NUM].  */
672 static const yytype_int16 yydefgoto[] =
673 {
674       -1,    12,    13,    14,    69,    70,    71,   106,   107,   108,
675      150,   137,   116,    36,    59,    37,    29,    30,    51,    52,
676       75,    76,   109
677 };
678
679 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
680    STATE-NUM.  */
681 #define YYPACT_NINF -86
682 static const yytype_int16 yypact[] =
683 {
684      111,   -18,   -14,    23,    45,    70,    75,    85,    92,    97,
685       91,    19,   128,   134,   -86,   162,    96,   162,   162,     5,
686        5,   123,     5,    93,    99,    19,   -86,   -86,   117,    19,
687      -86,   115,   -86,   -86,   125,   144,    71,   -86,   -86,   145,
688      116,   135,   147,   148,   149,   150,   101,   101,    14,    83,
689       83,    55,   -86,   -86,   117,   162,   162,   -86,   -86,   162,
690      133,   -86,   -86,   143,   -86,   151,   152,   107,   155,    63,
691      -86,   154,    74,   -86,   -86,    83,   -86,   156,    83,   157,
692      -86,    56,   137,   141,   -86,   -86,   -86,   -86,   -86,   -86,
693       88,    48,   174,   -86,   -86,   -86,   -86,   158,   -86,   -86,
694       69,   -86,   -86,   159,   161,   160,    12,   -86,   -86,   163,
695      165,   -86,   -86,   -86,   -86,    48,    59,   164,   -86,   -86,
696      166,    83,   -86,   -86,   -86,   183,    48,     0,    48,    48,
697       48,    48,    48,    48,   -86,   169,   167,    90,     7,   -86,
698       59,    59,    44,    66,   103,    29,   -86,     5,   -86,   171,
699      172,   -86,   -86,   173,   188,   -86,   -86,   175,   -86
700 };
701
702 /* YYPGOTO[NTERM-NUM].  */
703 static const yytype_int16 yypgoto[] =
704 {
705      -86,   -86,   -86,   192,   168,    80,   -85,   -86,   102,    89,
706      -86,   -86,    33,   -16,   -86,   153,   186,    38,   170,   -39,
707      176,   -11,     4
708 };
709
710 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
711    positive, shift that token.  If negative, reduce the rule which
712    number is the opposite.  If YYTABLE_NINF, syntax error.  */
713 #define YYTABLE_NINF -1
714 static const yytype_uint8 yytable[] =
715 {
716       31,    40,    41,   128,    38,   105,    38,    38,    42,    43,
717      128,    45,    80,    26,    31,    15,    27,   129,    31,    16,
718       26,   105,    26,   103,   129,    27,   104,    26,   130,   131,
719       27,   132,   128,    68,   139,   130,   131,    31,   132,    82,
720       83,   151,    80,    74,    38,    38,   129,   128,    38,   123,
721       28,    73,   110,    77,    77,    28,    17,   130,   131,   111,
722      132,   129,   128,   152,    49,    49,   112,    53,   113,   128,
723       50,    50,   114,   131,    67,   132,   129,    26,    18,    97,
724       27,   115,    97,   129,    68,    67,    53,   130,   131,   120,
725      132,    26,    79,   100,    27,    68,    26,   132,    23,   103,
726       93,   148,   104,    19,   119,    57,   128,    39,    20,    68,
727       58,    96,    67,    24,    74,   149,     1,     2,    21,    74,
728      129,     3,    68,     4,     5,    22,    49,    25,    32,    46,
729        6,     7,    50,     8,     9,    47,   153,    10,    11,     1,
730        2,    44,    89,    90,     3,    91,     4,     5,   127,    94,
731       61,    54,    94,     6,     7,    58,     8,     9,    55,   138,
732       10,   140,   141,   142,   143,   144,   145,    34,    85,    62,
733       26,   101,    35,    27,    58,   102,    58,    56,    86,    60,
734       58,    63,    64,    65,    66,   117,    87,    88,    92,    95,
735      136,    98,    99,   118,   121,   122,   125,    91,   126,   157,
736      147,   134,   133,   146,   154,    33,   155,   156,   124,   158,
737      135,    48,    84,     0,     0,    72,     0,     0,     0,     0,
738        0,     0,     0,     0,    81,     0,    78
739 };
740
741 #define yypact_value_is_default(yystate) \
742   ((yystate) == (-86))
743
744 #define yytable_value_is_error(yytable_value) \
745   YYID (0)
746
747 static const yytype_int16 yycheck[] =
748 {
749       11,    17,    18,     3,    15,    90,    17,    18,    19,    20,
750        3,    22,    51,     8,    25,    33,    11,    17,    29,    33,
751        8,   106,     8,    11,    17,    11,    14,     8,    28,    29,
752       11,    31,     3,    21,    34,    28,    29,    48,    31,    55,
753       56,    34,    81,    31,    55,    56,    17,     3,    59,    37,
754       36,    37,     4,    49,    50,    36,    33,    28,    29,    11,
755       31,    17,     3,    34,     9,     9,    18,    29,    20,     3,
756       15,    15,    24,    29,    11,    31,    17,     8,    33,    75,
757       11,    33,    78,    17,    21,    11,    48,    28,    29,   100,
758       31,     8,    37,    37,    11,    21,     8,    31,     1,    11,
759       37,    11,    14,    33,    35,    34,     3,    11,    33,    21,
760       39,    37,    11,    16,    31,    25,     5,     6,    33,    31,
761       17,    10,    21,    12,    13,    33,     9,    36,     0,    36,
762       19,    20,    15,    22,    23,    36,   147,    26,    27,     5,
763        6,    18,    35,    36,    10,    38,    12,    13,   115,    69,
764       34,    36,    72,    19,    20,    39,    22,    23,    33,   126,
765       26,   128,   129,   130,   131,   132,   133,     5,    35,    34,
766        8,    34,    10,    11,    39,    34,    39,    33,    35,    34,
767       39,    34,    34,    34,    34,    11,    35,    35,    33,    35,
768        7,    35,    35,    35,    33,    35,    33,    38,    33,    11,
769       33,    35,    38,    34,    33,    13,    34,    34,   106,    34,
770      121,    25,    59,    -1,    -1,    47,    -1,    -1,    -1,    -1,
771       -1,    -1,    -1,    -1,    54,    -1,    50
772 };
773
774 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
775    symbol of state STATE-NUM.  */
776 static const yytype_uint8 yystos[] =
777 {
778        0,     5,     6,    10,    12,    13,    19,    20,    22,    23,
779       26,    27,    41,    42,    43,    33,    33,    33,    33,    33,
780       33,    33,    33,     1,    16,    36,     8,    11,    36,    56,
781       57,    61,     0,    43,     5,    10,    53,    55,    61,    11,
782       53,    53,    61,    61,    18,    61,    36,    36,    56,     9,
783       15,    58,    59,    57,    36,    33,    33,    34,    39,    54,
784       34,    34,    34,    34,    34,    34,    34,    11,    21,    44,
785       45,    46,    44,    37,    31,    60,    61,    62,    60,    37,
786       59,    58,    53,    53,    55,    35,    35,    35,    35,    35,
787       36,    38,    33,    37,    45,    35,    37,    62,    35,    35,
788       37,    34,    34,    11,    14,    46,    47,    48,    49,    62,
789        4,    11,    18,    20,    24,    33,    52,    11,    35,    35,
790       61,    33,    35,    37,    48,    33,    33,    52,     3,    17,
791       28,    29,    31,    38,    35,    49,     7,    51,    52,    34,
792       52,    52,    52,    52,    52,    52,    34,    33,    11,    25,
793       50,    34,    34,    61,    33,    34,    34,    11,    34
794 };
795
796 #define yyerrok         (yyerrstatus = 0)
797 #define yyclearin       (yychar = YYEMPTY)
798 #define YYEMPTY         (-2)
799 #define YYEOF           0
800
801 #define YYACCEPT        goto yyacceptlab
802 #define YYABORT         goto yyabortlab
803 #define YYERROR         goto yyerrorlab
804
805
806 /* Like YYERROR except do call yyerror.  This remains here temporarily
807    to ease the transition to the new meaning of YYERROR, for GCC.
808    Once GCC version 2 has supplanted version 1, this can go.  However,
809    YYFAIL appears to be in use.  Nevertheless, it is formally deprecated
810    in Bison 2.4.2's NEWS entry, where a plan to phase it out is
811    discussed.  */
812
813 #define YYFAIL          goto yyerrlab
814 #if defined YYFAIL
815   /* This is here to suppress warnings from the GCC cpp's
816      -Wunused-macros.  Normally we don't worry about that warning, but
817      some users do, and we want to make it easy for users to remove
818      YYFAIL uses, which will produce warnings from Bison 2.5.  */
819 #endif
820
821 #define YYRECOVERING()  (!!yyerrstatus)
822
823 #define YYBACKUP(Token, Value)                                  \
824 do                                                              \
825   if (yychar == YYEMPTY && yylen == 1)                          \
826     {                                                           \
827       yychar = (Token);                                         \
828       yylval = (Value);                                         \
829       YYPOPSTACK (1);                                           \
830       goto yybackup;                                            \
831     }                                                           \
832   else                                                          \
833     {                                                           \
834       yyerror (YY_("syntax error: cannot back up")); \
835       YYERROR;                                                  \
836     }                                                           \
837 while (YYID (0))
838
839
840 #define YYTERROR        1
841 #define YYERRCODE       256
842
843
844 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
845    If N is 0, then set CURRENT to the empty location which ends
846    the previous symbol: RHS[0] (always defined).  */
847
848 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
849 #ifndef YYLLOC_DEFAULT
850 # define YYLLOC_DEFAULT(Current, Rhs, N)                                \
851     do                                                                  \
852       if (YYID (N))                                                    \
853         {                                                               \
854           (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
855           (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
856           (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
857           (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
858         }                                                               \
859       else                                                              \
860         {                                                               \
861           (Current).first_line   = (Current).last_line   =              \
862             YYRHSLOC (Rhs, 0).last_line;                                \
863           (Current).first_column = (Current).last_column =              \
864             YYRHSLOC (Rhs, 0).last_column;                              \
865         }                                                               \
866     while (YYID (0))
867 #endif
868
869
870 /* This macro is provided for backward compatibility. */
871
872 #ifndef YY_LOCATION_PRINT
873 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
874 #endif
875
876
877 /* YYLEX -- calling `yylex' with the right arguments.  */
878
879 #ifdef YYLEX_PARAM
880 # define YYLEX yylex (YYLEX_PARAM)
881 #else
882 # define YYLEX yylex ()
883 #endif
884
885 /* Enable debugging if requested.  */
886 #if YYDEBUG
887
888 # ifndef YYFPRINTF
889 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
890 #  define YYFPRINTF fprintf
891 # endif
892
893 # define YYDPRINTF(Args)                        \
894 do {                                            \
895   if (yydebug)                                  \
896     YYFPRINTF Args;                             \
897 } while (YYID (0))
898
899 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
900 do {                                                                      \
901   if (yydebug)                                                            \
902     {                                                                     \
903       YYFPRINTF (stderr, "%s ", Title);                                   \
904       yy_symbol_print (stderr,                                            \
905                   Type, Value); \
906       YYFPRINTF (stderr, "\n");                                           \
907     }                                                                     \
908 } while (YYID (0))
909
910
911 /*--------------------------------.
912 | Print this symbol on YYOUTPUT.  |
913 `--------------------------------*/
914
915 /*ARGSUSED*/
916 #if (defined __STDC__ || defined __C99__FUNC__ \
917      || defined __cplusplus || defined _MSC_VER)
918 static void
919 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
920 #else
921 static void
922 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
923     FILE *yyoutput;
924     int yytype;
925     YYSTYPE const * const yyvaluep;
926 #endif
927 {
928   if (!yyvaluep)
929     return;
930 # ifdef YYPRINT
931   if (yytype < YYNTOKENS)
932     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
933 # else
934   YYUSE (yyoutput);
935 # endif
936   switch (yytype)
937     {
938       default:
939         break;
940     }
941 }
942
943
944 /*--------------------------------.
945 | Print this symbol on YYOUTPUT.  |
946 `--------------------------------*/
947
948 #if (defined __STDC__ || defined __C99__FUNC__ \
949      || defined __cplusplus || defined _MSC_VER)
950 static void
951 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
952 #else
953 static void
954 yy_symbol_print (yyoutput, yytype, yyvaluep)
955     FILE *yyoutput;
956     int yytype;
957     YYSTYPE const * const yyvaluep;
958 #endif
959 {
960   if (yytype < YYNTOKENS)
961     YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
962   else
963     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
964
965   yy_symbol_value_print (yyoutput, yytype, yyvaluep);
966   YYFPRINTF (yyoutput, ")");
967 }
968
969 /*------------------------------------------------------------------.
970 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
971 | TOP (included).                                                   |
972 `------------------------------------------------------------------*/
973
974 #if (defined __STDC__ || defined __C99__FUNC__ \
975      || defined __cplusplus || defined _MSC_VER)
976 static void
977 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
978 #else
979 static void
980 yy_stack_print (yybottom, yytop)
981     yytype_int16 *yybottom;
982     yytype_int16 *yytop;
983 #endif
984 {
985   YYFPRINTF (stderr, "Stack now");
986   for (; yybottom <= yytop; yybottom++)
987     {
988       int yybot = *yybottom;
989       YYFPRINTF (stderr, " %d", yybot);
990     }
991   YYFPRINTF (stderr, "\n");
992 }
993
994 # define YY_STACK_PRINT(Bottom, Top)                            \
995 do {                                                            \
996   if (yydebug)                                                  \
997     yy_stack_print ((Bottom), (Top));                           \
998 } while (YYID (0))
999
1000
1001 /*------------------------------------------------.
1002 | Report that the YYRULE is going to be reduced.  |
1003 `------------------------------------------------*/
1004
1005 #if (defined __STDC__ || defined __C99__FUNC__ \
1006      || defined __cplusplus || defined _MSC_VER)
1007 static void
1008 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
1009 #else
1010 static void
1011 yy_reduce_print (yyvsp, yyrule)
1012     YYSTYPE *yyvsp;
1013     int yyrule;
1014 #endif
1015 {
1016   int yynrhs = yyr2[yyrule];
1017   int yyi;
1018   unsigned long int yylno = yyrline[yyrule];
1019   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1020              yyrule - 1, yylno);
1021   /* The symbols being reduced.  */
1022   for (yyi = 0; yyi < yynrhs; yyi++)
1023     {
1024       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
1025       yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1026                        &(yyvsp[(yyi + 1) - (yynrhs)])
1027                                        );
1028       YYFPRINTF (stderr, "\n");
1029     }
1030 }
1031
1032 # define YY_REDUCE_PRINT(Rule)          \
1033 do {                                    \
1034   if (yydebug)                          \
1035     yy_reduce_print (yyvsp, Rule); \
1036 } while (YYID (0))
1037
1038 /* Nonzero means print parse trace.  It is left uninitialized so that
1039    multiple parsers can coexist.  */
1040 int yydebug;
1041 #else /* !YYDEBUG */
1042 # define YYDPRINTF(Args)
1043 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1044 # define YY_STACK_PRINT(Bottom, Top)
1045 # define YY_REDUCE_PRINT(Rule)
1046 #endif /* !YYDEBUG */
1047
1048
1049 /* YYINITDEPTH -- initial size of the parser's stacks.  */
1050 #ifndef YYINITDEPTH
1051 # define YYINITDEPTH 200
1052 #endif
1053
1054 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1055    if the built-in stack extension method is used).
1056
1057    Do not make this value too large; the results are undefined if
1058    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1059    evaluated with infinite-precision integer arithmetic.  */
1060
1061 #ifndef YYMAXDEPTH
1062 # define YYMAXDEPTH 10000
1063 #endif
1064
1065
1066 #if YYERROR_VERBOSE
1067
1068 # ifndef yystrlen
1069 #  if defined __GLIBC__ && defined _STRING_H
1070 #   define yystrlen strlen
1071 #  else
1072 /* Return the length of YYSTR.  */
1073 #if (defined __STDC__ || defined __C99__FUNC__ \
1074      || defined __cplusplus || defined _MSC_VER)
1075 static YYSIZE_T
1076 yystrlen (const char *yystr)
1077 #else
1078 static YYSIZE_T
1079 yystrlen (yystr)
1080     const char *yystr;
1081 #endif
1082 {
1083   YYSIZE_T yylen;
1084   for (yylen = 0; yystr[yylen]; yylen++)
1085     continue;
1086   return yylen;
1087 }
1088 #  endif
1089 # endif
1090
1091 # ifndef yystpcpy
1092 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1093 #   define yystpcpy stpcpy
1094 #  else
1095 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1096    YYDEST.  */
1097 #if (defined __STDC__ || defined __C99__FUNC__ \
1098      || defined __cplusplus || defined _MSC_VER)
1099 static char *
1100 yystpcpy (char *yydest, const char *yysrc)
1101 #else
1102 static char *
1103 yystpcpy (yydest, yysrc)
1104     char *yydest;
1105     const char *yysrc;
1106 #endif
1107 {
1108   char *yyd = yydest;
1109   const char *yys = yysrc;
1110
1111   while ((*yyd++ = *yys++) != '\0')
1112     continue;
1113
1114   return yyd - 1;
1115 }
1116 #  endif
1117 # endif
1118
1119 # ifndef yytnamerr
1120 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1121    quotes and backslashes, so that it's suitable for yyerror.  The
1122    heuristic is that double-quoting is unnecessary unless the string
1123    contains an apostrophe, a comma, or backslash (other than
1124    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
1125    null, do not copy; instead, return the length of what the result
1126    would have been.  */
1127 static YYSIZE_T
1128 yytnamerr (char *yyres, const char *yystr)
1129 {
1130   if (*yystr == '"')
1131     {
1132       YYSIZE_T yyn = 0;
1133       char const *yyp = yystr;
1134
1135       for (;;)
1136         switch (*++yyp)
1137           {
1138           case '\'':
1139           case ',':
1140             goto do_not_strip_quotes;
1141
1142           case '\\':
1143             if (*++yyp != '\\')
1144               goto do_not_strip_quotes;
1145             /* Fall through.  */
1146           default:
1147             if (yyres)
1148               yyres[yyn] = *yyp;
1149             yyn++;
1150             break;
1151
1152           case '"':
1153             if (yyres)
1154               yyres[yyn] = '\0';
1155             return yyn;
1156           }
1157     do_not_strip_quotes: ;
1158     }
1159
1160   if (! yyres)
1161     return yystrlen (yystr);
1162
1163   return yystpcpy (yyres, yystr) - yyres;
1164 }
1165 # endif
1166
1167 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1168    about the unexpected token YYTOKEN for the state stack whose top is
1169    YYSSP.
1170
1171    Return 0 if *YYMSG was successfully written.  Return 1 if *YYMSG is
1172    not large enough to hold the message.  In that case, also set
1173    *YYMSG_ALLOC to the required number of bytes.  Return 2 if the
1174    required number of bytes is too large to store.  */
1175 static int
1176 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1177                 yytype_int16 *yyssp, int yytoken)
1178 {
1179   YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]);
1180   YYSIZE_T yysize = yysize0;
1181   YYSIZE_T yysize1;
1182   enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1183   /* Internationalized format string. */
1184   const char *yyformat = 0;
1185   /* Arguments of yyformat. */
1186   char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1187   /* Number of reported tokens (one for the "unexpected", one per
1188      "expected"). */
1189   int yycount = 0;
1190
1191   /* There are many possibilities here to consider:
1192      - Assume YYFAIL is not used.  It's too flawed to consider.  See
1193        <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
1194        for details.  YYERROR is fine as it does not invoke this
1195        function.
1196      - If this state is a consistent state with a default action, then
1197        the only way this function was invoked is if the default action
1198        is an error action.  In that case, don't check for expected
1199        tokens because there are none.
1200      - The only way there can be no lookahead present (in yychar) is if
1201        this state is a consistent state with a default action.  Thus,
1202        detecting the absence of a lookahead is sufficient to determine
1203        that there is no unexpected or expected token to report.  In that
1204        case, just report a simple "syntax error".
1205      - Don't assume there isn't a lookahead just because this state is a
1206        consistent state with a default action.  There might have been a
1207        previous inconsistent state, consistent state with a non-default
1208        action, or user semantic action that manipulated yychar.
1209      - Of course, the expected token list depends on states to have
1210        correct lookahead information, and it depends on the parser not
1211        to perform extra reductions after fetching a lookahead from the
1212        scanner and before detecting a syntax error.  Thus, state merging
1213        (from LALR or IELR) and default reductions corrupt the expected
1214        token list.  However, the list is correct for canonical LR with
1215        one exception: it will still contain any token that will not be
1216        accepted due to an error action in a later state.
1217   */
1218   if (yytoken != YYEMPTY)
1219     {
1220       int yyn = yypact[*yyssp];
1221       yyarg[yycount++] = yytname[yytoken];
1222       if (!yypact_value_is_default (yyn))
1223         {
1224           /* Start YYX at -YYN if negative to avoid negative indexes in
1225              YYCHECK.  In other words, skip the first -YYN actions for
1226              this state because they are default actions.  */
1227           int yyxbegin = yyn < 0 ? -yyn : 0;
1228           /* Stay within bounds of both yycheck and yytname.  */
1229           int yychecklim = YYLAST - yyn + 1;
1230           int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1231           int yyx;
1232
1233           for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1234             if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1235                 && !yytable_value_is_error (yytable[yyx + yyn]))
1236               {
1237                 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1238                   {
1239                     yycount = 1;
1240                     yysize = yysize0;
1241                     break;
1242                   }
1243                 yyarg[yycount++] = yytname[yyx];
1244                 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1245                 if (! (yysize <= yysize1
1246                        && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1247                   return 2;
1248                 yysize = yysize1;
1249               }
1250         }
1251     }
1252
1253   switch (yycount)
1254     {
1255 # define YYCASE_(N, S)                      \
1256       case N:                               \
1257         yyformat = S;                       \
1258       break
1259       YYCASE_(0, YY_("syntax error"));
1260       YYCASE_(1, YY_("syntax error, unexpected %s"));
1261       YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1262       YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1263       YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1264       YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1265 # undef YYCASE_
1266     }
1267
1268   yysize1 = yysize + yystrlen (yyformat);
1269   if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1270     return 2;
1271   yysize = yysize1;
1272
1273   if (*yymsg_alloc < yysize)
1274     {
1275       *yymsg_alloc = 2 * yysize;
1276       if (! (yysize <= *yymsg_alloc
1277              && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1278         *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1279       return 1;
1280     }
1281
1282   /* Avoid sprintf, as that infringes on the user's name space.
1283      Don't have undefined behavior even if the translation
1284      produced a string with the wrong number of "%s"s.  */
1285   {
1286     char *yyp = *yymsg;
1287     int yyi = 0;
1288     while ((*yyp = *yyformat) != '\0')
1289       if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1290         {
1291           yyp += yytnamerr (yyp, yyarg[yyi++]);
1292           yyformat += 2;
1293         }
1294       else
1295         {
1296           yyp++;
1297           yyformat++;
1298         }
1299   }
1300   return 0;
1301 }
1302 #endif /* YYERROR_VERBOSE */
1303
1304 /*-----------------------------------------------.
1305 | Release the memory associated to this symbol.  |
1306 `-----------------------------------------------*/
1307
1308 /*ARGSUSED*/
1309 #if (defined __STDC__ || defined __C99__FUNC__ \
1310      || defined __cplusplus || defined _MSC_VER)
1311 static void
1312 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1313 #else
1314 static void
1315 yydestruct (yymsg, yytype, yyvaluep)
1316     const char *yymsg;
1317     int yytype;
1318     YYSTYPE *yyvaluep;
1319 #endif
1320 {
1321   YYUSE (yyvaluep);
1322
1323   if (!yymsg)
1324     yymsg = "Deleting";
1325   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1326
1327   switch (yytype)
1328     {
1329
1330       default:
1331         break;
1332     }
1333 }
1334
1335
1336 /* Prevent warnings from -Wmissing-prototypes.  */
1337 #ifdef YYPARSE_PARAM
1338 #if defined __STDC__ || defined __cplusplus
1339 int yyparse (void *YYPARSE_PARAM);
1340 #else
1341 int yyparse ();
1342 #endif
1343 #else /* ! YYPARSE_PARAM */
1344 #if defined __STDC__ || defined __cplusplus
1345 int yyparse (void);
1346 #else
1347 int yyparse ();
1348 #endif
1349 #endif /* ! YYPARSE_PARAM */
1350
1351
1352 /* The lookahead symbol.  */
1353 int yychar;
1354
1355 /* The semantic value of the lookahead symbol.  */
1356 YYSTYPE yylval;
1357
1358 /* Number of syntax errors so far.  */
1359 int yynerrs;
1360
1361
1362 /*----------.
1363 | yyparse.  |
1364 `----------*/
1365
1366 #ifdef YYPARSE_PARAM
1367 #if (defined __STDC__ || defined __C99__FUNC__ \
1368      || defined __cplusplus || defined _MSC_VER)
1369 int
1370 yyparse (void *YYPARSE_PARAM)
1371 #else
1372 int
1373 yyparse (YYPARSE_PARAM)
1374     void *YYPARSE_PARAM;
1375 #endif
1376 #else /* ! YYPARSE_PARAM */
1377 #if (defined __STDC__ || defined __C99__FUNC__ \
1378      || defined __cplusplus || defined _MSC_VER)
1379 int
1380 yyparse (void)
1381 #else
1382 int
1383 yyparse ()
1384
1385 #endif
1386 #endif
1387 {
1388     int yystate;
1389     /* Number of tokens to shift before error messages enabled.  */
1390     int yyerrstatus;
1391
1392     /* The stacks and their tools:
1393        `yyss': related to states.
1394        `yyvs': related to semantic values.
1395
1396        Refer to the stacks thru separate pointers, to allow yyoverflow
1397        to reallocate them elsewhere.  */
1398
1399     /* The state stack.  */
1400     yytype_int16 yyssa[YYINITDEPTH];
1401     yytype_int16 *yyss;
1402     yytype_int16 *yyssp;
1403
1404     /* The semantic value stack.  */
1405     YYSTYPE yyvsa[YYINITDEPTH];
1406     YYSTYPE *yyvs;
1407     YYSTYPE *yyvsp;
1408
1409     YYSIZE_T yystacksize;
1410
1411   int yyn;
1412   int yyresult;
1413   /* Lookahead token as an internal (translated) token number.  */
1414   int yytoken;
1415   /* The variables used to return semantic value and location from the
1416      action routines.  */
1417   YYSTYPE yyval;
1418
1419 #if YYERROR_VERBOSE
1420   /* Buffer for error messages, and its allocated size.  */
1421   char yymsgbuf[128];
1422   char *yymsg = yymsgbuf;
1423   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1424 #endif
1425
1426 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1427
1428   /* The number of symbols on the RHS of the reduced rule.
1429      Keep to zero when no symbol should be popped.  */
1430   int yylen = 0;
1431
1432   yytoken = 0;
1433   yyss = yyssa;
1434   yyvs = yyvsa;
1435   yystacksize = YYINITDEPTH;
1436
1437   YYDPRINTF ((stderr, "Starting parse\n"));
1438
1439   yystate = 0;
1440   yyerrstatus = 0;
1441   yynerrs = 0;
1442   yychar = YYEMPTY; /* Cause a token to be read.  */
1443
1444   /* Initialize stack pointers.
1445      Waste one element of value and location stack
1446      so that they stay on the same level as the state stack.
1447      The wasted elements are never initialized.  */
1448   yyssp = yyss;
1449   yyvsp = yyvs;
1450
1451   goto yysetstate;
1452
1453 /*------------------------------------------------------------.
1454 | yynewstate -- Push a new state, which is found in yystate.  |
1455 `------------------------------------------------------------*/
1456  yynewstate:
1457   /* In all cases, when you get here, the value and location stacks
1458      have just been pushed.  So pushing a state here evens the stacks.  */
1459   yyssp++;
1460
1461  yysetstate:
1462   *yyssp = yystate;
1463
1464   if (yyss + yystacksize - 1 <= yyssp)
1465     {
1466       /* Get the current used size of the three stacks, in elements.  */
1467       YYSIZE_T yysize = yyssp - yyss + 1;
1468
1469 #ifdef yyoverflow
1470       {
1471         /* Give user a chance to reallocate the stack.  Use copies of
1472            these so that the &'s don't force the real ones into
1473            memory.  */
1474         YYSTYPE *yyvs1 = yyvs;
1475         yytype_int16 *yyss1 = yyss;
1476
1477         /* Each stack pointer address is followed by the size of the
1478            data in use in that stack, in bytes.  This used to be a
1479            conditional around just the two extra args, but that might
1480            be undefined if yyoverflow is a macro.  */
1481         yyoverflow (YY_("memory exhausted"),
1482                     &yyss1, yysize * sizeof (*yyssp),
1483                     &yyvs1, yysize * sizeof (*yyvsp),
1484                     &yystacksize);
1485
1486         yyss = yyss1;
1487         yyvs = yyvs1;
1488       }
1489 #else /* no yyoverflow */
1490 # ifndef YYSTACK_RELOCATE
1491       goto yyexhaustedlab;
1492 # else
1493       /* Extend the stack our own way.  */
1494       if (YYMAXDEPTH <= yystacksize)
1495         goto yyexhaustedlab;
1496       yystacksize *= 2;
1497       if (YYMAXDEPTH < yystacksize)
1498         yystacksize = YYMAXDEPTH;
1499
1500       {
1501         yytype_int16 *yyss1 = yyss;
1502         union yyalloc *yyptr =
1503           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1504         if (! yyptr)
1505           goto yyexhaustedlab;
1506         YYSTACK_RELOCATE (yyss_alloc, yyss);
1507         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1508 #  undef YYSTACK_RELOCATE
1509         if (yyss1 != yyssa)
1510           YYSTACK_FREE (yyss1);
1511       }
1512 # endif
1513 #endif /* no yyoverflow */
1514
1515       yyssp = yyss + yysize - 1;
1516       yyvsp = yyvs + yysize - 1;
1517
1518       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1519                   (unsigned long int) yystacksize));
1520
1521       if (yyss + yystacksize - 1 <= yyssp)
1522         YYABORT;
1523     }
1524
1525   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1526
1527   if (yystate == YYFINAL)
1528     YYACCEPT;
1529
1530   goto yybackup;
1531
1532 /*-----------.
1533 | yybackup.  |
1534 `-----------*/
1535 yybackup:
1536
1537   /* Do appropriate processing given the current state.  Read a
1538      lookahead token if we need one and don't already have one.  */
1539
1540   /* First try to decide what to do without reference to lookahead token.  */
1541   yyn = yypact[yystate];
1542   if (yypact_value_is_default (yyn))
1543     goto yydefault;
1544
1545   /* Not known => get a lookahead token if don't already have one.  */
1546
1547   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
1548   if (yychar == YYEMPTY)
1549     {
1550       YYDPRINTF ((stderr, "Reading a token: "));
1551       yychar = YYLEX;
1552     }
1553
1554   if (yychar <= YYEOF)
1555     {
1556       yychar = yytoken = YYEOF;
1557       YYDPRINTF ((stderr, "Now at end of input.\n"));
1558     }
1559   else
1560     {
1561       yytoken = YYTRANSLATE (yychar);
1562       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1563     }
1564
1565   /* If the proper action on seeing token YYTOKEN is to reduce or to
1566      detect an error, take that action.  */
1567   yyn += yytoken;
1568   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1569     goto yydefault;
1570   yyn = yytable[yyn];
1571   if (yyn <= 0)
1572     {
1573       if (yytable_value_is_error (yyn))
1574         goto yyerrlab;
1575       yyn = -yyn;
1576       goto yyreduce;
1577     }
1578
1579   /* Count tokens shifted since error; after three, turn off error
1580      status.  */
1581   if (yyerrstatus)
1582     yyerrstatus--;
1583
1584   /* Shift the lookahead token.  */
1585   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1586
1587   /* Discard the shifted token.  */
1588   yychar = YYEMPTY;
1589
1590   yystate = yyn;
1591   *++yyvsp = yylval;
1592
1593   goto yynewstate;
1594
1595
1596 /*-----------------------------------------------------------.
1597 | yydefault -- do the default action for the current state.  |
1598 `-----------------------------------------------------------*/
1599 yydefault:
1600   yyn = yydefact[yystate];
1601   if (yyn == 0)
1602     goto yyerrlab;
1603   goto yyreduce;
1604
1605
1606 /*-----------------------------.
1607 | yyreduce -- Do a reduction.  |
1608 `-----------------------------*/
1609 yyreduce:
1610   /* yyn is the number of a rule to reduce with.  */
1611   yylen = yyr2[yyn];
1612
1613   /* If YYLEN is nonzero, implement the default value of the action:
1614      `$$ = $1'.
1615
1616      Otherwise, the following line sets YYVAL to garbage.
1617      This behavior is undocumented and Bison
1618      users should not rely upon it.  Assigning to YYVAL
1619      unconditionally makes the parser a bit smaller, and it avoids a
1620      GCC warning that YYVAL may be used uninitialized.  */
1621   yyval = yyvsp[1-yylen];
1622
1623
1624   YY_REDUCE_PRINT (yyn);
1625   switch (yyn)
1626     {
1627         case 3:
1628
1629 /* Line 1806 of yacc.c  */
1630 #line 137 "ldscript.y"
1631     { add_versions ((yyvsp[(2) - (2)].version)); }
1632     break;
1633
1634   case 6:
1635
1636 /* Line 1806 of yacc.c  */
1637 #line 145 "ldscript.y"
1638     {
1639                       if (likely (ld_state.entry == NULL))
1640                         ld_state.entry = (yyvsp[(3) - (5)].str);
1641                     }
1642     break;
1643
1644   case 7:
1645
1646 /* Line 1806 of yacc.c  */
1647 #line 150 "ldscript.y"
1648     {
1649                       ld_new_searchdir ((yyvsp[(3) - (5)].str));
1650                     }
1651     break;
1652
1653   case 8:
1654
1655 /* Line 1806 of yacc.c  */
1656 #line 154 "ldscript.y"
1657     {
1658                       if (likely (ld_state.pagesize == 0))
1659                         ld_state.pagesize = (yyvsp[(3) - (5)].num);
1660                     }
1661     break;
1662
1663   case 9:
1664
1665 /* Line 1806 of yacc.c  */
1666 #line 159 "ldscript.y"
1667     {
1668                       if (likely (ld_state.interp == NULL)
1669                           && ld_state.file_type != dso_file_type)
1670                         ld_state.interp = (yyvsp[(3) - (5)].str);
1671                     }
1672     break;
1673
1674   case 10:
1675
1676 /* Line 1806 of yacc.c  */
1677 #line 165 "ldscript.y"
1678     {
1679                       new_segment ((yyvsp[(2) - (5)].num), (yyvsp[(4) - (5)].output_rule));
1680                     }
1681     break;
1682
1683   case 11:
1684
1685 /* Line 1806 of yacc.c  */
1686 #line 169 "ldscript.y"
1687     {
1688                       fputs_unlocked (gettext ("mode for segment invalid\n"),
1689                                       stderr);
1690                       new_segment (0, (yyvsp[(4) - (5)].output_rule));
1691                     }
1692     break;
1693
1694   case 12:
1695
1696 /* Line 1806 of yacc.c  */
1697 #line 175 "ldscript.y"
1698     {
1699                       /* First little optimization.  If there is only one
1700                          file in the group don't do anything.  */
1701                       if ((yyvsp[(3) - (4)].filename_list) != (yyvsp[(3) - (4)].filename_list)->next)
1702                         {
1703                           (yyvsp[(3) - (4)].filename_list)->next->group_start = 1;
1704                           (yyvsp[(3) - (4)].filename_list)->group_end = 1;
1705                         }
1706                       add_inputfiles ((yyvsp[(3) - (4)].filename_list));
1707                     }
1708     break;
1709
1710   case 13:
1711
1712 /* Line 1806 of yacc.c  */
1713 #line 186 "ldscript.y"
1714     { add_inputfiles ((yyvsp[(3) - (4)].filename_list)); }
1715     break;
1716
1717   case 14:
1718
1719 /* Line 1806 of yacc.c  */
1720 #line 188 "ldscript.y"
1721     { add_inputfiles (mark_as_needed ((yyvsp[(3) - (4)].filename_list))); }
1722     break;
1723
1724   case 15:
1725
1726 /* Line 1806 of yacc.c  */
1727 #line 190 "ldscript.y"
1728     { add_versions ((yyvsp[(3) - (4)].version)); }
1729     break;
1730
1731   case 16:
1732
1733 /* Line 1806 of yacc.c  */
1734 #line 192 "ldscript.y"
1735     { /* XXX TODO */ }
1736     break;
1737
1738   case 17:
1739
1740 /* Line 1806 of yacc.c  */
1741 #line 196 "ldscript.y"
1742     {
1743                       (yyvsp[(2) - (2)].output_rule)->next = (yyvsp[(1) - (2)].output_rule)->next;
1744                       (yyval.output_rule) = (yyvsp[(1) - (2)].output_rule)->next = (yyvsp[(2) - (2)].output_rule);
1745                     }
1746     break;
1747
1748   case 18:
1749
1750 /* Line 1806 of yacc.c  */
1751 #line 201 "ldscript.y"
1752     { (yyval.output_rule) = (yyvsp[(1) - (1)].output_rule); }
1753     break;
1754
1755   case 19:
1756
1757 /* Line 1806 of yacc.c  */
1758 #line 205 "ldscript.y"
1759     {
1760                       (yyval.output_rule) = new_output_rule (output_assignment);
1761                       (yyval.output_rule)->val.assignment = (yyvsp[(1) - (2)].assignment);
1762                     }
1763     break;
1764
1765   case 20:
1766
1767 /* Line 1806 of yacc.c  */
1768 #line 210 "ldscript.y"
1769     {
1770                       (yyval.output_rule) = new_output_rule (output_section);
1771                       (yyval.output_rule)->val.section.name = (yyvsp[(1) - (4)].str);
1772                       (yyval.output_rule)->val.section.input = (yyvsp[(3) - (4)].input_rule)->next;
1773                       if (ld_state.strip == strip_debug
1774                           && ebl_debugscn_p (ld_state.ebl, (yyvsp[(1) - (4)].str)))
1775                         (yyval.output_rule)->val.section.ignored = true;
1776                       else
1777                         (yyval.output_rule)->val.section.ignored = false;
1778                       (yyvsp[(3) - (4)].input_rule)->next = NULL;
1779                     }
1780     break;
1781
1782   case 21:
1783
1784 /* Line 1806 of yacc.c  */
1785 #line 222 "ldscript.y"
1786     {
1787                       /* This is a short cut for "ID { *(ID) }".  */
1788                       (yyval.output_rule) = new_output_rule (output_section);
1789                       (yyval.output_rule)->val.section.name = (yyvsp[(1) - (2)].str);
1790                       (yyval.output_rule)->val.section.input = new_input_rule (input_section);
1791                       (yyval.output_rule)->val.section.input->next = NULL;
1792                       (yyval.output_rule)->val.section.input->val.section =
1793                         (struct filemask_section_name *)
1794                           obstack_alloc (&ld_state.smem,
1795                                          sizeof (struct filemask_section_name));
1796                       (yyval.output_rule)->val.section.input->val.section->filemask = NULL;
1797                       (yyval.output_rule)->val.section.input->val.section->excludemask = NULL;
1798                       (yyval.output_rule)->val.section.input->val.section->section_name =
1799                         new_input_section_name ((yyvsp[(1) - (2)].str), false);
1800                       (yyval.output_rule)->val.section.input->val.section->keep_flag = false;
1801                       if (ld_state.strip == strip_debug
1802                           && ebl_debugscn_p (ld_state.ebl, (yyvsp[(1) - (2)].str)))
1803                         (yyval.output_rule)->val.section.ignored = true;
1804                       else
1805                         (yyval.output_rule)->val.section.ignored = false;
1806                     }
1807     break;
1808
1809   case 22:
1810
1811 /* Line 1806 of yacc.c  */
1812 #line 246 "ldscript.y"
1813     { (yyval.assignment) = new_assignment ((yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].expr), false); }
1814     break;
1815
1816   case 23:
1817
1818 /* Line 1806 of yacc.c  */
1819 #line 248 "ldscript.y"
1820     { (yyval.assignment) = new_assignment ((yyvsp[(3) - (6)].str), (yyvsp[(5) - (6)].expr), true); }
1821     break;
1822
1823   case 24:
1824
1825 /* Line 1806 of yacc.c  */
1826 #line 252 "ldscript.y"
1827     {
1828                       (yyvsp[(2) - (2)].input_rule)->next = (yyvsp[(1) - (2)].input_rule)->next;
1829                       (yyval.input_rule) = (yyvsp[(1) - (2)].input_rule)->next = (yyvsp[(2) - (2)].input_rule);
1830                     }
1831     break;
1832
1833   case 25:
1834
1835 /* Line 1806 of yacc.c  */
1836 #line 257 "ldscript.y"
1837     { (yyval.input_rule) = (yyvsp[(1) - (1)].input_rule); }
1838     break;
1839
1840   case 26:
1841
1842 /* Line 1806 of yacc.c  */
1843 #line 261 "ldscript.y"
1844     {
1845                       (yyval.input_rule) = new_input_rule (input_section);
1846                       (yyval.input_rule)->val.section = (yyvsp[(1) - (1)].filemask_section_name);
1847                     }
1848     break;
1849
1850   case 27:
1851
1852 /* Line 1806 of yacc.c  */
1853 #line 266 "ldscript.y"
1854     {
1855                       (yyvsp[(3) - (4)].filemask_section_name)->keep_flag = true;
1856
1857                       (yyval.input_rule) = new_input_rule (input_section);
1858                       (yyval.input_rule)->val.section = (yyvsp[(3) - (4)].filemask_section_name);
1859                     }
1860     break;
1861
1862   case 28:
1863
1864 /* Line 1806 of yacc.c  */
1865 #line 273 "ldscript.y"
1866     {
1867                       (yyval.input_rule) = new_input_rule (input_assignment);
1868                       (yyval.input_rule)->val.assignment = (yyvsp[(1) - (2)].assignment);
1869                     }
1870     break;
1871
1872   case 29:
1873
1874 /* Line 1806 of yacc.c  */
1875 #line 280 "ldscript.y"
1876     {
1877                       (yyval.filemask_section_name) = (struct filemask_section_name *)
1878                         obstack_alloc (&ld_state.smem, sizeof (*(yyval.filemask_section_name)));
1879                       (yyval.filemask_section_name)->filemask = (yyvsp[(1) - (5)].str);
1880                       (yyval.filemask_section_name)->excludemask = (yyvsp[(3) - (5)].str);
1881                       (yyval.filemask_section_name)->section_name = (yyvsp[(4) - (5)].sectionname);
1882                       (yyval.filemask_section_name)->keep_flag = false;
1883                     }
1884     break;
1885
1886   case 30:
1887
1888 /* Line 1806 of yacc.c  */
1889 #line 291 "ldscript.y"
1890     { (yyval.sectionname) = new_input_section_name ((yyvsp[(1) - (1)].str), false); }
1891     break;
1892
1893   case 31:
1894
1895 /* Line 1806 of yacc.c  */
1896 #line 293 "ldscript.y"
1897     { (yyval.sectionname) = new_input_section_name ((yyvsp[(3) - (4)].str), true); }
1898     break;
1899
1900   case 32:
1901
1902 /* Line 1806 of yacc.c  */
1903 #line 297 "ldscript.y"
1904     { (yyval.str) = (yyvsp[(3) - (4)].str); }
1905     break;
1906
1907   case 33:
1908
1909 /* Line 1806 of yacc.c  */
1910 #line 299 "ldscript.y"
1911     { (yyval.str) = NULL; }
1912     break;
1913
1914   case 34:
1915
1916 /* Line 1806 of yacc.c  */
1917 #line 303 "ldscript.y"
1918     {
1919                       (yyval.expr) = new_expr (exp_align);
1920                       (yyval.expr)->val.child = (yyvsp[(3) - (4)].expr);
1921                     }
1922     break;
1923
1924   case 35:
1925
1926 /* Line 1806 of yacc.c  */
1927 #line 308 "ldscript.y"
1928     { (yyval.expr) = (yyvsp[(2) - (3)].expr); }
1929     break;
1930
1931   case 36:
1932
1933 /* Line 1806 of yacc.c  */
1934 #line 310 "ldscript.y"
1935     {
1936                       (yyval.expr) = new_expr (exp_mult);
1937                       (yyval.expr)->val.binary.left = (yyvsp[(1) - (3)].expr);
1938                       (yyval.expr)->val.binary.right = (yyvsp[(3) - (3)].expr);
1939                     }
1940     break;
1941
1942   case 37:
1943
1944 /* Line 1806 of yacc.c  */
1945 #line 316 "ldscript.y"
1946     {
1947                       (yyval.expr) = new_expr ((yyvsp[(2) - (3)].op));
1948                       (yyval.expr)->val.binary.left = (yyvsp[(1) - (3)].expr);
1949                       (yyval.expr)->val.binary.right = (yyvsp[(3) - (3)].expr);
1950                     }
1951     break;
1952
1953   case 38:
1954
1955 /* Line 1806 of yacc.c  */
1956 #line 322 "ldscript.y"
1957     {
1958                       (yyval.expr) = new_expr ((yyvsp[(2) - (3)].op));
1959                       (yyval.expr)->val.binary.left = (yyvsp[(1) - (3)].expr);
1960                       (yyval.expr)->val.binary.right = (yyvsp[(3) - (3)].expr);
1961                     }
1962     break;
1963
1964   case 39:
1965
1966 /* Line 1806 of yacc.c  */
1967 #line 328 "ldscript.y"
1968     {
1969                       (yyval.expr) = new_expr (exp_and);
1970                       (yyval.expr)->val.binary.left = (yyvsp[(1) - (3)].expr);
1971                       (yyval.expr)->val.binary.right = (yyvsp[(3) - (3)].expr);
1972                     }
1973     break;
1974
1975   case 40:
1976
1977 /* Line 1806 of yacc.c  */
1978 #line 334 "ldscript.y"
1979     {
1980                       (yyval.expr) = new_expr (exp_or);
1981                       (yyval.expr)->val.binary.left = (yyvsp[(1) - (3)].expr);
1982                       (yyval.expr)->val.binary.right = (yyvsp[(3) - (3)].expr);
1983                     }
1984     break;
1985
1986   case 41:
1987
1988 /* Line 1806 of yacc.c  */
1989 #line 340 "ldscript.y"
1990     {
1991                       (yyval.expr) = new_expr (exp_num);
1992                       (yyval.expr)->val.num = (yyvsp[(1) - (1)].num);
1993                     }
1994     break;
1995
1996   case 42:
1997
1998 /* Line 1806 of yacc.c  */
1999 #line 345 "ldscript.y"
2000     {
2001                       (yyval.expr) = new_expr (exp_id);
2002                       (yyval.expr)->val.str = (yyvsp[(1) - (1)].str);
2003                     }
2004     break;
2005
2006   case 43:
2007
2008 /* Line 1806 of yacc.c  */
2009 #line 350 "ldscript.y"
2010     { (yyval.expr) = new_expr (exp_sizeof_headers); }
2011     break;
2012
2013   case 44:
2014
2015 /* Line 1806 of yacc.c  */
2016 #line 352 "ldscript.y"
2017     { (yyval.expr) = new_expr (exp_pagesize); }
2018     break;
2019
2020   case 45:
2021
2022 /* Line 1806 of yacc.c  */
2023 #line 356 "ldscript.y"
2024     {
2025                       (yyvsp[(3) - (3)].filename_list)->next = (yyvsp[(1) - (3)].filename_list)->next;
2026                       (yyval.filename_list) = (yyvsp[(1) - (3)].filename_list)->next = (yyvsp[(3) - (3)].filename_list);
2027                     }
2028     break;
2029
2030   case 46:
2031
2032 /* Line 1806 of yacc.c  */
2033 #line 361 "ldscript.y"
2034     { (yyval.filename_list) = (yyvsp[(1) - (1)].filename_list); }
2035     break;
2036
2037   case 49:
2038
2039 /* Line 1806 of yacc.c  */
2040 #line 369 "ldscript.y"
2041     {
2042                       /* First little optimization.  If there is only one
2043                          file in the group don't do anything.  */
2044                       if ((yyvsp[(3) - (4)].filename_list) != (yyvsp[(3) - (4)].filename_list)->next)
2045                         {
2046                           (yyvsp[(3) - (4)].filename_list)->next->group_start = 1;
2047                           (yyvsp[(3) - (4)].filename_list)->group_end = 1;
2048                         }
2049                       (yyval.filename_list) = (yyvsp[(3) - (4)].filename_list);
2050                     }
2051     break;
2052
2053   case 50:
2054
2055 /* Line 1806 of yacc.c  */
2056 #line 380 "ldscript.y"
2057     { (yyval.filename_list) = mark_as_needed ((yyvsp[(3) - (4)].filename_list)); }
2058     break;
2059
2060   case 51:
2061
2062 /* Line 1806 of yacc.c  */
2063 #line 382 "ldscript.y"
2064     { (yyval.filename_list) = new_filename_listelem ((yyvsp[(1) - (1)].str)); }
2065     break;
2066
2067   case 52:
2068
2069 /* Line 1806 of yacc.c  */
2070 #line 387 "ldscript.y"
2071     {
2072                       (yyvsp[(2) - (2)].version)->next = (yyvsp[(1) - (2)].version)->next;
2073                       (yyval.version) = (yyvsp[(1) - (2)].version)->next = (yyvsp[(2) - (2)].version);
2074                     }
2075     break;
2076
2077   case 53:
2078
2079 /* Line 1806 of yacc.c  */
2080 #line 392 "ldscript.y"
2081     { (yyval.version) = (yyvsp[(1) - (1)].version); }
2082     break;
2083
2084   case 54:
2085
2086 /* Line 1806 of yacc.c  */
2087 #line 396 "ldscript.y"
2088     {
2089                       (yyvsp[(2) - (4)].version)->versionname = "";
2090                       (yyvsp[(2) - (4)].version)->parentname = NULL;
2091                       (yyval.version) = (yyvsp[(2) - (4)].version);
2092                     }
2093     break;
2094
2095   case 55:
2096
2097 /* Line 1806 of yacc.c  */
2098 #line 402 "ldscript.y"
2099     {
2100                       (yyvsp[(3) - (5)].version)->versionname = (yyvsp[(1) - (5)].str);
2101                       (yyvsp[(3) - (5)].version)->parentname = NULL;
2102                       (yyval.version) = (yyvsp[(3) - (5)].version);
2103                     }
2104     break;
2105
2106   case 56:
2107
2108 /* Line 1806 of yacc.c  */
2109 #line 408 "ldscript.y"
2110     {
2111                       (yyvsp[(3) - (6)].version)->versionname = (yyvsp[(1) - (6)].str);
2112                       (yyvsp[(3) - (6)].version)->parentname = (yyvsp[(5) - (6)].str);
2113                       (yyval.version) = (yyvsp[(3) - (6)].version);
2114                     }
2115     break;
2116
2117   case 57:
2118
2119 /* Line 1806 of yacc.c  */
2120 #line 417 "ldscript.y"
2121     { (yyval.version) = merge_versions ((yyvsp[(1) - (2)].version), (yyvsp[(2) - (2)].version)); }
2122     break;
2123
2124   case 58:
2125
2126 /* Line 1806 of yacc.c  */
2127 #line 419 "ldscript.y"
2128     { (yyval.version) = (yyvsp[(1) - (1)].version); }
2129     break;
2130
2131   case 59:
2132
2133 /* Line 1806 of yacc.c  */
2134 #line 423 "ldscript.y"
2135     { (yyval.version) = new_version (NULL, (yyvsp[(2) - (2)].id_list)); }
2136     break;
2137
2138   case 60:
2139
2140 /* Line 1806 of yacc.c  */
2141 #line 425 "ldscript.y"
2142     { (yyval.version) = new_version ((yyvsp[(2) - (2)].id_list), NULL); }
2143     break;
2144
2145   case 61:
2146
2147 /* Line 1806 of yacc.c  */
2148 #line 430 "ldscript.y"
2149     {
2150                       struct id_list *newp = new_id_listelem ((yyvsp[(2) - (3)].str));
2151                       newp->next = (yyvsp[(1) - (3)].id_list)->next;
2152                       (yyval.id_list) = (yyvsp[(1) - (3)].id_list)->next = newp;
2153                     }
2154     break;
2155
2156   case 62:
2157
2158 /* Line 1806 of yacc.c  */
2159 #line 436 "ldscript.y"
2160     { (yyval.id_list) = new_id_listelem ((yyvsp[(1) - (2)].str)); }
2161     break;
2162
2163   case 63:
2164
2165 /* Line 1806 of yacc.c  */
2166 #line 440 "ldscript.y"
2167     { (yyval.str) = (yyvsp[(1) - (1)].str); }
2168     break;
2169
2170   case 64:
2171
2172 /* Line 1806 of yacc.c  */
2173 #line 442 "ldscript.y"
2174     { (yyval.str) = (yyvsp[(1) - (1)].str); }
2175     break;
2176
2177   case 65:
2178
2179 /* Line 1806 of yacc.c  */
2180 #line 446 "ldscript.y"
2181     { (yyval.str) = (yyvsp[(1) - (1)].str); }
2182     break;
2183
2184   case 66:
2185
2186 /* Line 1806 of yacc.c  */
2187 #line 448 "ldscript.y"
2188     { (yyval.str) = NULL; }
2189     break;
2190
2191
2192
2193 /* Line 1806 of yacc.c  */
2194 #line 2195 "ldscript.c"
2195       default: break;
2196     }
2197   /* User semantic actions sometimes alter yychar, and that requires
2198      that yytoken be updated with the new translation.  We take the
2199      approach of translating immediately before every use of yytoken.
2200      One alternative is translating here after every semantic action,
2201      but that translation would be missed if the semantic action invokes
2202      YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
2203      if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
2204      incorrect destructor might then be invoked immediately.  In the
2205      case of YYERROR or YYBACKUP, subsequent parser actions might lead
2206      to an incorrect destructor call or verbose syntax error message
2207      before the lookahead is translated.  */
2208   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2209
2210   YYPOPSTACK (yylen);
2211   yylen = 0;
2212   YY_STACK_PRINT (yyss, yyssp);
2213
2214   *++yyvsp = yyval;
2215
2216   /* Now `shift' the result of the reduction.  Determine what state
2217      that goes to, based on the state we popped back to and the rule
2218      number reduced by.  */
2219
2220   yyn = yyr1[yyn];
2221
2222   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2223   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2224     yystate = yytable[yystate];
2225   else
2226     yystate = yydefgoto[yyn - YYNTOKENS];
2227
2228   goto yynewstate;
2229
2230
2231 /*------------------------------------.
2232 | yyerrlab -- here on detecting error |
2233 `------------------------------------*/
2234 yyerrlab:
2235   /* Make sure we have latest lookahead translation.  See comments at
2236      user semantic actions for why this is necessary.  */
2237   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
2238
2239   /* If not already recovering from an error, report this error.  */
2240   if (!yyerrstatus)
2241     {
2242       ++yynerrs;
2243 #if ! YYERROR_VERBOSE
2244       yyerror (YY_("syntax error"));
2245 #else
2246 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
2247                                         yyssp, yytoken)
2248       {
2249         char const *yymsgp = YY_("syntax error");
2250         int yysyntax_error_status;
2251         yysyntax_error_status = YYSYNTAX_ERROR;
2252         if (yysyntax_error_status == 0)
2253           yymsgp = yymsg;
2254         else if (yysyntax_error_status == 1)
2255           {
2256             if (yymsg != yymsgbuf)
2257               YYSTACK_FREE (yymsg);
2258             yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
2259             if (!yymsg)
2260               {
2261                 yymsg = yymsgbuf;
2262                 yymsg_alloc = sizeof yymsgbuf;
2263                 yysyntax_error_status = 2;
2264               }
2265             else
2266               {
2267                 yysyntax_error_status = YYSYNTAX_ERROR;
2268                 yymsgp = yymsg;
2269               }
2270           }
2271         yyerror (yymsgp);
2272         if (yysyntax_error_status == 2)
2273           goto yyexhaustedlab;
2274       }
2275 # undef YYSYNTAX_ERROR
2276 #endif
2277     }
2278
2279
2280
2281   if (yyerrstatus == 3)
2282     {
2283       /* If just tried and failed to reuse lookahead token after an
2284          error, discard it.  */
2285
2286       if (yychar <= YYEOF)
2287         {
2288           /* Return failure if at end of input.  */
2289           if (yychar == YYEOF)
2290             YYABORT;
2291         }
2292       else
2293         {
2294           yydestruct ("Error: discarding",
2295                       yytoken, &yylval);
2296           yychar = YYEMPTY;
2297         }
2298     }
2299
2300   /* Else will try to reuse lookahead token after shifting the error
2301      token.  */
2302   goto yyerrlab1;
2303
2304
2305 /*---------------------------------------------------.
2306 | yyerrorlab -- error raised explicitly by YYERROR.  |
2307 `---------------------------------------------------*/
2308 yyerrorlab:
2309
2310   /* Pacify compilers like GCC when the user code never invokes
2311      YYERROR and the label yyerrorlab therefore never appears in user
2312      code.  */
2313   if (/*CONSTCOND*/ 0)
2314      goto yyerrorlab;
2315
2316   /* Do not reclaim the symbols of the rule which action triggered
2317      this YYERROR.  */
2318   YYPOPSTACK (yylen);
2319   yylen = 0;
2320   YY_STACK_PRINT (yyss, yyssp);
2321   yystate = *yyssp;
2322   goto yyerrlab1;
2323
2324
2325 /*-------------------------------------------------------------.
2326 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
2327 `-------------------------------------------------------------*/
2328 yyerrlab1:
2329   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
2330
2331   for (;;)
2332     {
2333       yyn = yypact[yystate];
2334       if (!yypact_value_is_default (yyn))
2335         {
2336           yyn += YYTERROR;
2337           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2338             {
2339               yyn = yytable[yyn];
2340               if (0 < yyn)
2341                 break;
2342             }
2343         }
2344
2345       /* Pop the current state because it cannot handle the error token.  */
2346       if (yyssp == yyss)
2347         YYABORT;
2348
2349
2350       yydestruct ("Error: popping",
2351                   yystos[yystate], yyvsp);
2352       YYPOPSTACK (1);
2353       yystate = *yyssp;
2354       YY_STACK_PRINT (yyss, yyssp);
2355     }
2356
2357   *++yyvsp = yylval;
2358
2359
2360   /* Shift the error token.  */
2361   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2362
2363   yystate = yyn;
2364   goto yynewstate;
2365
2366
2367 /*-------------------------------------.
2368 | yyacceptlab -- YYACCEPT comes here.  |
2369 `-------------------------------------*/
2370 yyacceptlab:
2371   yyresult = 0;
2372   goto yyreturn;
2373
2374 /*-----------------------------------.
2375 | yyabortlab -- YYABORT comes here.  |
2376 `-----------------------------------*/
2377 yyabortlab:
2378   yyresult = 1;
2379   goto yyreturn;
2380
2381 #if !defined(yyoverflow) || YYERROR_VERBOSE
2382 /*-------------------------------------------------.
2383 | yyexhaustedlab -- memory exhaustion comes here.  |
2384 `-------------------------------------------------*/
2385 yyexhaustedlab:
2386   yyerror (YY_("memory exhausted"));
2387   yyresult = 2;
2388   /* Fall through.  */
2389 #endif
2390
2391 yyreturn:
2392   if (yychar != YYEMPTY)
2393     {
2394       /* Make sure we have latest lookahead translation.  See comments at
2395          user semantic actions for why this is necessary.  */
2396       yytoken = YYTRANSLATE (yychar);
2397       yydestruct ("Cleanup: discarding lookahead",
2398                   yytoken, &yylval);
2399     }
2400   /* Do not reclaim the symbols of the rule which action triggered
2401      this YYABORT or YYACCEPT.  */
2402   YYPOPSTACK (yylen);
2403   YY_STACK_PRINT (yyss, yyssp);
2404   while (yyssp != yyss)
2405     {
2406       yydestruct ("Cleanup: popping",
2407                   yystos[*yyssp], yyvsp);
2408       YYPOPSTACK (1);
2409     }
2410 #ifndef yyoverflow
2411   if (yyss != yyssa)
2412     YYSTACK_FREE (yyss);
2413 #endif
2414 #if YYERROR_VERBOSE
2415   if (yymsg != yymsgbuf)
2416     YYSTACK_FREE (yymsg);
2417 #endif
2418   /* Make sure YYID is used.  */
2419   return YYID (yyresult);
2420 }
2421
2422
2423
2424 /* Line 2067 of yacc.c  */
2425 #line 451 "ldscript.y"
2426
2427
2428 static void
2429 yyerror (const char *s)
2430 {
2431   error (0, 0, (ld_scan_version_script
2432                 ? gettext ("while reading version script '%s': %s at line %d")
2433                 : gettext ("while reading linker script '%s': %s at line %d")),
2434          ldin_fname, gettext (s), ldlineno);
2435 }
2436
2437
2438 static struct expression *
2439 new_expr (int tag)
2440 {
2441   struct expression *newp = (struct expression *)
2442     obstack_alloc (&ld_state.smem, sizeof (*newp));
2443
2444   newp->tag = tag;
2445   return newp;
2446 }
2447
2448
2449 static struct input_section_name *
2450 new_input_section_name (const char *name, bool sort_flag)
2451 {
2452   struct input_section_name *newp = (struct input_section_name *)
2453     obstack_alloc (&ld_state.smem, sizeof (*newp));
2454
2455   newp->name = name;
2456   newp->sort_flag = sort_flag;
2457   return newp;
2458 }
2459
2460
2461 static struct input_rule *
2462 new_input_rule (int tag)
2463 {
2464   struct input_rule *newp = (struct input_rule *)
2465     obstack_alloc (&ld_state.smem, sizeof (*newp));
2466
2467   newp->tag = tag;
2468   newp->next = newp;
2469   return newp;
2470 }
2471
2472
2473 static struct output_rule *
2474 new_output_rule (int tag)
2475 {
2476   struct output_rule *newp = (struct output_rule *)
2477     memset (obstack_alloc (&ld_state.smem, sizeof (*newp)),
2478             '\0', sizeof (*newp));
2479
2480   newp->tag = tag;
2481   newp->next = newp;
2482   return newp;
2483 }
2484
2485
2486 static struct assignment *
2487 new_assignment (const char *variable, struct expression *expression,
2488                 bool provide_flag)
2489 {
2490   struct assignment *newp = (struct assignment *)
2491     obstack_alloc (&ld_state.smem, sizeof (*newp));
2492
2493   newp->variable = variable;
2494   newp->expression = expression;
2495   newp->sym = NULL;
2496   newp->provide_flag = provide_flag;
2497
2498   /* Insert the symbol into a hash table.  We will later have to matc*/
2499   return newp;
2500 }
2501
2502
2503 static void
2504 new_segment (int mode, struct output_rule *output_rule)
2505 {
2506   struct output_segment *newp;
2507
2508   newp
2509     = (struct output_segment *) obstack_alloc (&ld_state.smem, sizeof (*newp));
2510   newp->mode = mode;
2511   newp->next = newp;
2512
2513   newp->output_rules = output_rule->next;
2514   output_rule->next = NULL;
2515
2516   /* Enqueue the output segment description.  */
2517   if (ld_state.output_segments == NULL)
2518     ld_state.output_segments = newp;
2519   else
2520     {
2521       newp->next = ld_state.output_segments->next;
2522       ld_state.output_segments = ld_state.output_segments->next = newp;
2523     }
2524
2525   /* If the output file should be stripped of all symbol set the flag
2526      in the structures of all output sections.  */
2527   if (mode == 0 && ld_state.strip == strip_all)
2528     {
2529       struct output_rule *runp;
2530
2531       for (runp = newp->output_rules; runp != NULL; runp = runp->next)
2532         if (runp->tag == output_section)
2533           runp->val.section.ignored = true;
2534     }
2535 }
2536
2537
2538 static struct filename_list *
2539 new_filename_listelem (const char *string)
2540 {
2541   struct filename_list *newp;
2542
2543   /* We use calloc and not the obstack since this object can be freed soon.  */
2544   newp = (struct filename_list *) xcalloc (1, sizeof (*newp));
2545   newp->name = string;
2546   newp->next = newp;
2547   return newp;
2548 }
2549
2550
2551 static struct filename_list *
2552 mark_as_needed (struct filename_list *listp)
2553 {
2554   struct filename_list *runp = listp;
2555   do
2556     {
2557       runp->as_needed = true;
2558       runp = runp->next;
2559     }
2560   while (runp != listp);
2561
2562   return listp;
2563 }
2564
2565
2566 static void
2567 add_inputfiles (struct filename_list *fnames)
2568 {
2569   assert (fnames != NULL);
2570
2571   if (ld_state.srcfiles == NULL)
2572     ld_state.srcfiles = fnames;
2573   else
2574     {
2575       struct filename_list *first = ld_state.srcfiles->next;
2576
2577       ld_state.srcfiles->next = fnames->next;
2578       fnames->next = first;
2579       ld_state.srcfiles->next = fnames;
2580     }
2581 }
2582
2583
2584 static _Bool
2585 special_char_p (const char *str)
2586 {
2587   while (*str != '\0')
2588     {
2589       if (__builtin_expect (*str == '*', 0)
2590           || __builtin_expect (*str == '?', 0)
2591           || __builtin_expect (*str == '[', 0))
2592         return true;
2593
2594       ++str;
2595     }
2596
2597   return false;
2598 }
2599
2600
2601 static struct id_list *
2602 new_id_listelem (const char *str)
2603 {
2604   struct id_list *newp;
2605
2606   newp = (struct id_list *) obstack_alloc (&ld_state.smem, sizeof (*newp));
2607   if (str == NULL)
2608     newp->u.id_type = id_all;
2609   else if (__builtin_expect (special_char_p (str), false))
2610     newp->u.id_type = id_wild;
2611   else
2612     newp->u.id_type = id_str;
2613   newp->id = str;
2614   newp->next = newp;
2615
2616   return newp;
2617 }
2618
2619
2620 static struct version *
2621 new_version (struct id_list *local, struct id_list *global)
2622 {
2623   struct version *newp;
2624
2625   newp = (struct version *) obstack_alloc (&ld_state.smem, sizeof (*newp));
2626   newp->next = newp;
2627   newp->local_names = local;
2628   newp->global_names = global;
2629   newp->versionname = NULL;
2630   newp->parentname = NULL;
2631
2632   return newp;
2633 }
2634
2635
2636 static struct version *
2637 merge_versions (struct version *one, struct version *two)
2638 {
2639   assert (two->local_names == NULL || two->global_names == NULL);
2640
2641   if (two->local_names != NULL)
2642     {
2643       if (one->local_names == NULL)
2644         one->local_names = two->local_names;
2645       else
2646         {
2647           two->local_names->next = one->local_names->next;
2648           one->local_names = one->local_names->next = two->local_names;
2649         }
2650     }
2651   else
2652     {
2653       if (one->global_names == NULL)
2654         one->global_names = two->global_names;
2655       else
2656         {
2657           two->global_names->next = one->global_names->next;
2658           one->global_names = one->global_names->next = two->global_names;
2659         }
2660     }
2661
2662   return one;
2663 }
2664
2665
2666 static void
2667 add_id_list (const char *versionname, struct id_list *runp, _Bool local)
2668 {
2669   struct id_list *lastp = runp;
2670
2671   if (runp == NULL)
2672     /* Nothing to do.  */
2673     return;
2674
2675   /* Convert into a simple single-linked list.  */
2676   runp = runp->next;
2677   assert (runp != NULL);
2678   lastp->next = NULL;
2679
2680   do
2681     if (runp->u.id_type == id_str)
2682       {
2683         struct id_list *curp;
2684         struct id_list *defp;
2685         unsigned long int hval = elf_hash (runp->id);
2686
2687         curp = runp;
2688         runp = runp->next;
2689
2690         defp = ld_version_str_tab_find (&ld_state.version_str_tab, hval, curp);
2691         if (defp != NULL)
2692           {
2693             /* There is already a version definition for this symbol.  */
2694             while (strcmp (defp->u.s.versionname, versionname) != 0)
2695               {
2696                 if (defp->next == NULL)
2697                   {
2698                     /* No version like this so far.  */
2699                     defp->next = curp;
2700                     curp->u.s.local = local;
2701                     curp->u.s.versionname = versionname;
2702                     curp->next = NULL;
2703                     defp = NULL;
2704                     break;
2705                   }
2706
2707                 defp = defp->next;
2708               }
2709
2710             if (defp != NULL && defp->u.s.local != local)
2711               error (EXIT_FAILURE, 0, versionname[0] == '\0'
2712                      ? gettext ("\
2713 symbol '%s' is declared both local and global for unnamed version")
2714                      : gettext ("\
2715 symbol '%s' is declared both local and global for version '%s'"),
2716                      runp->id, versionname);
2717           }
2718         else
2719           {
2720             /* This is the first version definition for this symbol.  */
2721             ld_version_str_tab_insert (&ld_state.version_str_tab, hval, curp);
2722
2723             curp->u.s.local = local;
2724             curp->u.s.versionname = versionname;
2725             curp->next = NULL;
2726           }
2727       }
2728     else if (runp->u.id_type == id_all)
2729       {
2730         if (local)
2731           {
2732             if (ld_state.default_bind_global)
2733               error (EXIT_FAILURE, 0,
2734                      gettext ("default visibility set as local and global"));
2735             ld_state.default_bind_local = true;
2736           }
2737         else
2738           {
2739             if (ld_state.default_bind_local)
2740               error (EXIT_FAILURE, 0,
2741                      gettext ("default visibility set as local and global"));
2742             ld_state.default_bind_global = true;
2743           }
2744
2745         runp = runp->next;
2746       }
2747     else
2748       {
2749         assert (runp->u.id_type == id_wild);
2750         /* XXX TBI */
2751         abort ();
2752       }
2753   while (runp != NULL);
2754 }
2755
2756
2757 static void
2758 add_versions (struct version *versions)
2759 {
2760   struct version *lastp = versions;
2761
2762   if (versions == NULL)
2763     return;
2764
2765   /* Convert into a simple single-linked list.  */
2766   versions = versions->next;
2767   assert (versions != NULL);
2768   lastp->next = NULL;
2769
2770   do
2771     {
2772       add_id_list (versions->versionname, versions->local_names, true);
2773       add_id_list (versions->versionname, versions->global_names, false);
2774
2775       versions = versions->next;
2776     }
2777   while (versions != NULL);
2778 }
2779