aboutsummaryrefslogtreecommitdiff
path: root/ld/ldgram.y
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2021-08-13 11:50:16 +0930
committerAlan Modra <amodra@gmail.com>2021-08-13 12:32:53 +0930
commitaf29a8abcf50ff9cb465a136c68b06bfc2ca7b75 (patch)
tree3178a2b395ebf1861809037b3bcc6e4b26113347 /ld/ldgram.y
parent41ee6d14fd3faf486036cdb9042e432664abfe48 (diff)
downloadfsf-binutils-gdb-af29a8abcf50ff9cb465a136c68b06bfc2ca7b75.zip
fsf-binutils-gdb-af29a8abcf50ff9cb465a136c68b06bfc2ca7b75.tar.gz
fsf-binutils-gdb-af29a8abcf50ff9cb465a136c68b06bfc2ca7b75.tar.bz2
PR28217, Syntax error when memory region contains a hyphen
The saga of commit 40726f16a8d7 continues. This attacks the problem of switching between SCRIPT and EXPRESSION state lexing by removing the need to do so for phdrs like ":text". Instead {WILDCHAR}* matching, the reason why ":text" lexed as one token, is restricted to within the braces of a section or overlay statement. The new WILD lexer state is switched at the non-optional brace tokens, so ldlex_backup is no longer needed. I've also removed the BOTH state, which doesn't seem to be needed any more. Besides rules involving error reporting, there was just one place where SCRIPT appeared without BOTH, the {WILDCHAR}* rule, three where BOTH appears without SCRIPT for tokens that only need EXPRESSION state, and two where BOTH appears alongside INPUT_LIST. (Since I'm editing the wild and filename rules, removing BOTH and adding WILD can also be seen as renaming the old BOTH state to SCRIPT and renaming the old SCRIPT state to WILD with a reduced scope.) As a followup, I'll look at removing EXPRESSION state from some lexer rules that no longer need it due to this cleanup. PR 28217 * ldgram.y (exp <ORIGIN, LENGTH>): Use paren_script_name. (section): Parse within braces of section in wild mode, and after brace back in script mode. Remove ldlex_backup call. Similarly for OVERLAY. (overlay_section): Similarly. (script_file): Replace ldlex_both with ldlex_script. * ldlex.h (ldlex_wild): Declare. (ldlex_both): Delete. * ldlex.l (BOTH): Delete. Remove state from all rules. (WILD): New state. Enable many tokens in this state. Enable filename match in SCRIPT mode. Enable WILDCHAR match in WILD state, disable in SCRIPT mode. (ldlex_wild): New function. * ldfile.c (ldfile_try_open_bfd): Replace ldlex_both call with ldlex_script.
Diffstat (limited to 'ld/ldgram.y')
-rw-r--r--ld/ldgram.y55
1 files changed, 20 insertions, 35 deletions
diff --git a/ld/ldgram.y b/ld/ldgram.y
index 77442818..4910e17 100644
--- a/ld/ldgram.y
+++ b/ld/ldgram.y
@@ -297,9 +297,9 @@ extern_name_list_body:
;
script_file:
- { ldlex_both(); }
+ { ldlex_script (); }
ifile_list
- { ldlex_popstate(); }
+ { ldlex_popstate (); }
;
ifile_list:
@@ -1021,10 +1021,10 @@ exp :
{ $$ = exp_binop (MIN_K, $3, $5 ); }
| ASSERT_K '(' exp ',' NAME ')'
{ $$ = exp_assert ($3, $5); }
- | ORIGIN '(' NAME ')'
- { $$ = exp_nameop (ORIGIN, $3); }
- | LENGTH '(' NAME ')'
- { $$ = exp_nameop (LENGTH, $3); }
+ | ORIGIN paren_script_name
+ { $$ = exp_nameop (ORIGIN, $2); }
+ | LENGTH paren_script_name
+ { $$ = exp_nameop (LENGTH, $2); }
| LOG2CEIL '(' exp ')'
{ $$ = exp_unop (LOG2CEIL, $3); }
;
@@ -1069,50 +1069,38 @@ section: NAME
opt_align
opt_align_with_input
opt_subalign
- { ldlex_popstate (); ldlex_script (); }
sect_constraint
- '{'
{
+ ldlex_popstate ();
+ ldlex_wild ();
lang_enter_output_section_statement($1, $3, sectype,
$5, $7, $4,
- $9, $6);
+ $8, $6);
}
+ '{'
statement_list_opt
'}'
- { ldlex_popstate (); ldlex_expression (); }
+ { ldlex_popstate (); }
memspec_opt memspec_at_opt phdr_opt fill_opt
{
- if (yychar == NAME)
- {
- yyclearin;
- ldlex_backup ();
- }
- ldlex_popstate ();
- lang_leave_output_section_statement ($18, $15,
- $17, $16);
+ lang_leave_output_section_statement ($17, $14,
+ $16, $15);
}
opt_comma
| OVERLAY
{ ldlex_expression (); }
opt_exp_without_type opt_nocrossrefs opt_at opt_subalign
- { ldlex_popstate (); ldlex_script (); }
+ { ldlex_popstate (); }
'{'
{
lang_enter_overlay ($3, $6);
}
overlay_section
'}'
- { ldlex_popstate (); ldlex_expression (); }
memspec_opt memspec_at_opt phdr_opt fill_opt
{
- if (yychar == NAME)
- {
- yyclearin;
- ldlex_backup ();
- }
- ldlex_popstate ();
lang_leave_overlay ($5, (int) $4,
- $16, $13, $15, $14);
+ $15, $12, $14, $13);
}
opt_comma
| /* The GROUP case is just enough to support the gcc
@@ -1204,18 +1192,15 @@ overlay_section:
| overlay_section
NAME
{
+ ldlex_wild ();
lang_enter_overlay_section ($2);
}
- '{' statement_list_opt '}'
- { ldlex_expression (); }
+ '{'
+ statement_list_opt
+ '}'
+ { ldlex_popstate (); }
phdr_opt fill_opt
{
- if (yychar == NAME)
- {
- yyclearin;
- ldlex_backup ();
- }
- ldlex_popstate ();
lang_leave_overlay_section ($9, $8);
}
opt_comma