Allow unquoted = as the first character in ldscript input_list names

* ldlex.l (INPUTLIST): New start condition.
	(comment pattern, ",", "(", ")", "AS_NEEDED")
	({FILENAMECHAR1}{FILENAMECHAR}*, "-l"{FILENAMECHAR}+)
	(quoted string pattern, whitespace pattern): Add INPUTLIST to
	valid start conditions.
	(<INPUTLIST>"="{FILENAMECHAR1}{FILENAMECHAR}*): New NAME rule.
	(ldlex_inputlist): New start-condition-setter function.
	* ldgram.y (input_list1): Rename from input_list.  All recursive
	use changed.
	(input_list): New wrapper rule for input_list1, setting
	INPUTLIST lexer state for the duration of parsing input_list1.

All this to say INPUT(=/path/to/file) and not be forced to use
INPUT("=/path/to/file") whenever there's a need to force a sysroot-
prefix.  Still, IMHO it seems better to make use of a previously
invalid syntax and not only change the meaning of quoted =-prefixed
paths (though arguably that's not very useful before this patchset).

This got a little bit hairier than I'd expected: I had to add a new
lexer state (aka. start condition) to avoid a first "=" being lexed as
the token "=", despite that not making sense in constructs expecting
file-names in the first place.  (The grammar doesn't allow for
expressions in any part of those lists.)  I guess I *could* have made
it work using that token anyway, but I didn't like the idea that you
would be able to separate the "=" from the rest of the file-name with
whitespace.
This commit is contained in:
Hans-Peter Nilsson 2014-10-15 03:10:25 +02:00
parent bfa2343443
commit eeed9cc785
4 changed files with 49 additions and 18 deletions

View File

@ -1,5 +1,16 @@
2014-10-15 Hans-Peter Nilsson <hp@axis.com> 2014-10-15 Hans-Peter Nilsson <hp@axis.com>
* ldlex.l (INPUTLIST): New start condition.
(comment pattern, ",", "(", ")", "AS_NEEDED")
({FILENAMECHAR1}{FILENAMECHAR}*, "-l"{FILENAMECHAR}+)
(quoted string pattern, whitespace pattern): Add INPUTLIST to
valid start conditions.
(<INPUTLIST>"="{FILENAMECHAR1}{FILENAMECHAR}*): New NAME rule.
(ldlex_inputlist): New start-condition-setter function.
* ldgram.y (input_list1): Rename from input_list. All recursive
use changed.
(input_list): New wrapper rule for input_list1, setting
INPUTLIST lexer state for the duration of parsing input_list1.
* ldlang.c (lang_add_input_file): If the first character in the * ldlang.c (lang_add_input_file): If the first character in the
filename is '=', prepend the sysroot and force the context of that filename is '=', prepend the sysroot and force the context of that
input file to non-sysroot. input file to non-sysroot.

View File

@ -365,38 +365,43 @@ ifile_p1:
; ;
input_list: input_list:
{ ldlex_inputlist(); }
input_list1
{ ldlex_popstate(); }
input_list1:
NAME NAME
{ lang_add_input_file($1,lang_input_file_is_search_file_enum, { lang_add_input_file($1,lang_input_file_is_search_file_enum,
(char *)NULL); } (char *)NULL); }
| input_list ',' NAME | input_list1 ',' NAME
{ lang_add_input_file($3,lang_input_file_is_search_file_enum, { lang_add_input_file($3,lang_input_file_is_search_file_enum,
(char *)NULL); } (char *)NULL); }
| input_list NAME | input_list1 NAME
{ lang_add_input_file($2,lang_input_file_is_search_file_enum, { lang_add_input_file($2,lang_input_file_is_search_file_enum,
(char *)NULL); } (char *)NULL); }
| LNAME | LNAME
{ lang_add_input_file($1,lang_input_file_is_l_enum, { lang_add_input_file($1,lang_input_file_is_l_enum,
(char *)NULL); } (char *)NULL); }
| input_list ',' LNAME | input_list1 ',' LNAME
{ lang_add_input_file($3,lang_input_file_is_l_enum, { lang_add_input_file($3,lang_input_file_is_l_enum,
(char *)NULL); } (char *)NULL); }
| input_list LNAME | input_list1 LNAME
{ lang_add_input_file($2,lang_input_file_is_l_enum, { lang_add_input_file($2,lang_input_file_is_l_enum,
(char *)NULL); } (char *)NULL); }
| AS_NEEDED '(' | AS_NEEDED '('
{ $<integer>$ = input_flags.add_DT_NEEDED_for_regular; { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
input_flags.add_DT_NEEDED_for_regular = TRUE; } input_flags.add_DT_NEEDED_for_regular = TRUE; }
input_list ')' input_list1 ')'
{ input_flags.add_DT_NEEDED_for_regular = $<integer>3; } { input_flags.add_DT_NEEDED_for_regular = $<integer>3; }
| input_list ',' AS_NEEDED '(' | input_list1 ',' AS_NEEDED '('
{ $<integer>$ = input_flags.add_DT_NEEDED_for_regular; { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
input_flags.add_DT_NEEDED_for_regular = TRUE; } input_flags.add_DT_NEEDED_for_regular = TRUE; }
input_list ')' input_list1 ')'
{ input_flags.add_DT_NEEDED_for_regular = $<integer>5; } { input_flags.add_DT_NEEDED_for_regular = $<integer>5; }
| input_list AS_NEEDED '(' | input_list1 AS_NEEDED '('
{ $<integer>$ = input_flags.add_DT_NEEDED_for_regular; { $<integer>$ = input_flags.add_DT_NEEDED_for_regular;
input_flags.add_DT_NEEDED_for_regular = TRUE; } input_flags.add_DT_NEEDED_for_regular = TRUE; }
input_list ')' input_list1 ')'
{ input_flags.add_DT_NEEDED_for_regular = $<integer>4; } { input_flags.add_DT_NEEDED_for_regular = $<integer>4; }
; ;

View File

@ -161,6 +161,7 @@ extern int yylex (void);
extern void lex_push_file (FILE *, const char *, unsigned int); extern void lex_push_file (FILE *, const char *, unsigned int);
extern void lex_redirect (const char *, const char *, unsigned int); extern void lex_redirect (const char *, const char *, unsigned int);
extern void ldlex_script (void); extern void ldlex_script (void);
extern void ldlex_inputlist (void);
extern void ldlex_mri_script (void); extern void ldlex_mri_script (void);
extern void ldlex_version_script (void); extern void ldlex_version_script (void);
extern void ldlex_version_file (void); extern void ldlex_version_file (void);

View File

@ -77,6 +77,7 @@ static void lex_warn_invalid (char *where, char *what);
/* STATES /* STATES
EXPRESSION definitely in an expression EXPRESSION definitely in an expression
SCRIPT definitely in a script SCRIPT definitely in a script
INPUTLIST definitely in a script, a filename-list
BOTH either EXPRESSION or SCRIPT BOTH either EXPRESSION or SCRIPT
DEFSYMEXP in an argument to -defsym DEFSYMEXP in an argument to -defsym
MRI in an MRI script MRI in an MRI script
@ -109,6 +110,7 @@ V_TAG [.$_a-zA-Z][._a-zA-Z0-9]*
V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)* V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
%s SCRIPT %s SCRIPT
%s INPUTLIST
%s EXPRESSION %s EXPRESSION
%s BOTH %s BOTH
%s DEFSYMEXP %s DEFSYMEXP
@ -134,7 +136,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
} }
} }
<BOTH,SCRIPT,EXPRESSION,VERS_START,VERS_NODE,VERS_SCRIPT>"/*" { comment (); } <BOTH,SCRIPT,EXPRESSION,VERS_START,VERS_NODE,VERS_SCRIPT,INPUTLIST>"/*" { comment (); }
<DEFSYMEXP>"-" { RTOKEN('-');} <DEFSYMEXP>"-" { RTOKEN('-');}
@ -221,7 +223,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
<BOTH,SCRIPT,EXPRESSION,MRI>"|=" { RTOKEN(OREQ);} <BOTH,SCRIPT,EXPRESSION,MRI>"|=" { RTOKEN(OREQ);}
<BOTH,SCRIPT,EXPRESSION,MRI>"&&" { RTOKEN(ANDAND);} <BOTH,SCRIPT,EXPRESSION,MRI>"&&" { RTOKEN(ANDAND);}
<BOTH,SCRIPT,EXPRESSION,MRI>">" { RTOKEN('>');} <BOTH,SCRIPT,EXPRESSION,MRI>">" { RTOKEN('>');}
<BOTH,SCRIPT,EXPRESSION,MRI>"," { RTOKEN(',');} <BOTH,SCRIPT,EXPRESSION,MRI,INPUTLIST>"," { RTOKEN(',');}
<BOTH,SCRIPT,EXPRESSION,MRI>"&" { RTOKEN('&');} <BOTH,SCRIPT,EXPRESSION,MRI>"&" { RTOKEN('&');}
<BOTH,SCRIPT,EXPRESSION,MRI>"|" { RTOKEN('|');} <BOTH,SCRIPT,EXPRESSION,MRI>"|" { RTOKEN('|');}
<BOTH,SCRIPT,EXPRESSION,MRI>"~" { RTOKEN('~');} <BOTH,SCRIPT,EXPRESSION,MRI>"~" { RTOKEN('~');}
@ -236,8 +238,8 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
<BOTH,SCRIPT,EXPRESSION,MRI>"=" { RTOKEN('=');} <BOTH,SCRIPT,EXPRESSION,MRI>"=" { RTOKEN('=');}
<BOTH,SCRIPT,EXPRESSION,MRI>"}" { RTOKEN('}') ; } <BOTH,SCRIPT,EXPRESSION,MRI>"}" { RTOKEN('}') ; }
<BOTH,SCRIPT,EXPRESSION,MRI>"{" { RTOKEN('{'); } <BOTH,SCRIPT,EXPRESSION,MRI>"{" { RTOKEN('{'); }
<BOTH,SCRIPT,EXPRESSION,MRI>")" { RTOKEN(')');} <BOTH,SCRIPT,EXPRESSION,MRI,INPUTLIST>")" { RTOKEN(')');}
<BOTH,SCRIPT,EXPRESSION,MRI>"(" { RTOKEN('(');} <BOTH,SCRIPT,EXPRESSION,MRI,INPUTLIST>"(" { RTOKEN('(');}
<BOTH,SCRIPT,EXPRESSION,MRI>":" { RTOKEN(':'); } <BOTH,SCRIPT,EXPRESSION,MRI>":" { RTOKEN(':'); }
<BOTH,SCRIPT,EXPRESSION,MRI>";" { RTOKEN(';');} <BOTH,SCRIPT,EXPRESSION,MRI>";" { RTOKEN(';');}
<BOTH,SCRIPT>"MEMORY" { RTOKEN(MEMORY);} <BOTH,SCRIPT>"MEMORY" { RTOKEN(MEMORY);}
@ -272,7 +274,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
<BOTH,SCRIPT>"OUTPUT" { RTOKEN(OUTPUT);} <BOTH,SCRIPT>"OUTPUT" { RTOKEN(OUTPUT);}
<BOTH,SCRIPT>"INPUT" { RTOKEN(INPUT);} <BOTH,SCRIPT>"INPUT" { RTOKEN(INPUT);}
<EXPRESSION,BOTH,SCRIPT>"GROUP" { RTOKEN(GROUP);} <EXPRESSION,BOTH,SCRIPT>"GROUP" { RTOKEN(GROUP);}
<EXPRESSION,BOTH,SCRIPT>"AS_NEEDED" { RTOKEN(AS_NEEDED);} <EXPRESSION,BOTH,SCRIPT,INPUTLIST>"AS_NEEDED" { RTOKEN(AS_NEEDED);}
<EXPRESSION,BOTH,SCRIPT>"DEFINED" { RTOKEN(DEFINED);} <EXPRESSION,BOTH,SCRIPT>"DEFINED" { RTOKEN(DEFINED);}
<BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);} <BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);}
<BOTH,SCRIPT>"CONSTRUCTORS" { RTOKEN( CONSTRUCTORS);} <BOTH,SCRIPT>"CONSTRUCTORS" { RTOKEN( CONSTRUCTORS);}
@ -373,11 +375,16 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
} }
<BOTH>{FILENAMECHAR1}{FILENAMECHAR}* { <BOTH,INPUTLIST>{FILENAMECHAR1}{FILENAMECHAR}* {
yylval.name = xstrdup (yytext); yylval.name = xstrdup (yytext);
return NAME; return NAME;
} }
<BOTH>"-l"{FILENAMECHAR}+ { <INPUTLIST>"="{FILENAMECHAR1}{FILENAMECHAR}* {
/* Filename to be prefixed by --sysroot or when non-sysrooted, nothing. */
yylval.name = xstrdup (yytext);
return NAME;
}
<BOTH,INPUTLIST>"-l"{FILENAMECHAR}+ {
yylval.name = xstrdup (yytext + 2); yylval.name = xstrdup (yytext + 2);
return LNAME; return LNAME;
} }
@ -406,7 +413,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
} }
} }
<EXPRESSION,BOTH,SCRIPT,VERS_NODE>"\""[^\"]*"\"" { <EXPRESSION,BOTH,SCRIPT,VERS_NODE,INPUTLIST>"\""[^\"]*"\"" {
/* No matter the state, quotes /* No matter the state, quotes
give what's inside */ give what's inside */
yylval.name = xstrdup (yytext + 1); yylval.name = xstrdup (yytext + 1);
@ -447,7 +454,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
<VERS_START,VERS_NODE,VERS_SCRIPT>#.* { /* Eat up comments */ } <VERS_START,VERS_NODE,VERS_SCRIPT>#.* { /* Eat up comments */ }
<VERS_START,VERS_NODE,VERS_SCRIPT>[ \t\r]+ { /* Eat up whitespace */ } <VERS_START,VERS_NODE,VERS_SCRIPT,INPUTLIST>[ \t\r]+ { /* Eat up whitespace */ }
<<EOF>> { <<EOF>> {
include_stack_ptr--; include_stack_ptr--;
@ -565,6 +572,13 @@ ldlex_script (void)
BEGIN (SCRIPT); BEGIN (SCRIPT);
} }
void
ldlex_inputlist (void)
{
*(state_stack_p)++ = yy_start;
BEGIN (INPUTLIST);
}
void void
ldlex_mri_script (void) ldlex_mri_script (void)
{ {