ld --defsym

Alan Modra amodra@gmail.com
Mon Feb 1 11:20:19 GMT 2021


This makes --defsym support the same expressions as assignment in a
script.  For example, --defsym 'HIDDEN(foo=0)', will define a hidden
visibility foo.

	* ldgram.y (defsym_expr): Use assignment rule.
	* ldlex.h (ldlex_defsym): Delete.
	* ldlex.l (DEFSYMEXP, ldlex_defsym): Delete.

diff --git a/ld/ldgram.y b/ld/ldgram.y
index 08dc110f3da..5912329c778 100644
--- a/ld/ldgram.y
+++ b/ld/ldgram.y
@@ -176,12 +176,9 @@ filename:  NAME;
 
 
 defsym_expr:
-		{ ldlex_defsym(); }
-		NAME '=' exp
-		{
-		  ldlex_popstate();
-		  lang_add_assignment (exp_defsym ($2, $4));
-		}
+		{ ldlex_expression(); }
+		assignment
+		{ ldlex_popstate(); }
 	;
 
 /* SYNTAX WITHIN AN MRI SCRIPT FILE */
diff --git a/ld/ldlex.h b/ld/ldlex.h
index d9b36ea2702..3ce1ad44716 100644
--- a/ld/ldlex.h
+++ b/ld/ldlex.h
@@ -187,7 +187,6 @@ extern void ldlex_inputlist (void);
 extern void ldlex_mri_script (void);
 extern void ldlex_version_script (void);
 extern void ldlex_version_file (void);
-extern void ldlex_defsym (void);
 extern void ldlex_expression (void);
 extern void ldlex_both (void);
 extern void ldlex_popstate (void);
diff --git a/ld/ldlex.l b/ld/ldlex.l
index 7652e8d2a29..c1b15263587 100644
--- a/ld/ldlex.l
+++ b/ld/ldlex.l
@@ -79,7 +79,6 @@ static void lex_warn_invalid (char *where, char *what);
 	SCRIPT		definitely in a script
 	INPUTLIST	definitely in a script, a filename-list
 	BOTH		either EXPRESSION or SCRIPT
-	DEFSYMEXP	in an argument to -defsym
 	MRI		in an MRI script
 	VERS_START	starting a Sun style mapfile
 	VERS_SCRIPT	a Sun style mapfile
@@ -107,7 +106,6 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
 %s INPUTLIST
 %s EXPRESSION
 %s BOTH
-%s DEFSYMEXP
 %s MRI
 %s VERS_START
 %s VERS_SCRIPT
@@ -133,12 +131,6 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
 <BOTH,SCRIPT,EXPRESSION,VERS_START,VERS_NODE,VERS_SCRIPT,INPUTLIST>"/*"	{ comment (); }
 
 
-<DEFSYMEXP>"-"			{ RTOKEN('-');}
-<DEFSYMEXP>"+"			{ RTOKEN('+');}
-<DEFSYMEXP>{SYMBOLNAMECHAR1}{SYMBOLNAMECHAR}* { yylval.name = xstrdup (yytext);
-						return NAME; }
-<DEFSYMEXP>"="			{ RTOKEN('='); }
-
 <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
 				yylval.integer = bfd_scan_vma (yytext + 1, 0, 16);
 				yylval.bigint.str = NULL;
@@ -170,7 +162,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
 				   yylval.bigint.str = NULL;
 				   return INT;
 				 }
-<SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>((("$"|0[xX])([0-9A-Fa-f])+)|(([0-9])+))(M|K|m|k)? {
+<SCRIPT,MRI,BOTH,EXPRESSION>((("$"|0[xX])([0-9A-Fa-f])+)|(([0-9])+))(M|K|m|k)? {
 				  char *s = yytext;
 				  int ibase = 0;
 
@@ -480,7 +472,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
 }
 
 <SCRIPT,MRI,VERS_START,VERS_SCRIPT,VERS_NODE>.	lex_warn_invalid (" in script", yytext);
-<EXPRESSION,DEFSYMEXP,BOTH>.	lex_warn_invalid (" in expression", yytext);
+<EXPRESSION,BOTH>.	lex_warn_invalid (" in expression", yytext);
 
 %%
 
@@ -609,13 +601,6 @@ ldlex_version_file (void)
   BEGIN (VERS_SCRIPT);
 }
 
-void
-ldlex_defsym (void)
-{
-  *(state_stack_p)++ = yy_start;
-  BEGIN (DEFSYMEXP);
-}
-
 void
 ldlex_expression (void)
 {

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list