ld: Don't allow '~' as the first char in symbol name
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 9 Oct 2017 11:17:10 +0000 (04:17 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 9 Oct 2017 11:17:24 +0000 (04:17 -0700)
Don't allow '~' as the first character in symbol name in linker script.

PR ld/22267
* ldlex.l (SYMBOLNAMECHAR1) New.
(DEFSYMEXP): Replace FILENAMECHAR1 with SYMBOLNAMECHAR1.
(EXPRESSION): Likewise.
* testsuite/ld-scripts/expr.exp: Run pr22267.
* testsuite/ld-scripts/pr22267.d: New file.
* testsuite/ld-scripts/pr22267.s: Likewise.
* testsuite/ld-scripts/pr22267.t: Likewise.

ld/ChangeLog
ld/ldlex.l
ld/testsuite/ld-scripts/expr.exp
ld/testsuite/ld-scripts/pr22267.d [new file with mode: 0644]
ld/testsuite/ld-scripts/pr22267.s [new file with mode: 0644]
ld/testsuite/ld-scripts/pr22267.t [new file with mode: 0644]

index 55e36a515bcac9cc88a12c9e2e5378c4edf7ed57..18d4b1e04787edc3c3f9c13899ff08a5cccd46e2 100644 (file)
@@ -1,3 +1,14 @@
+2017-10-09  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/22267
+       * ldlex.l (SYMBOLNAMECHAR1) New.
+       (DEFSYMEXP): Replace FILENAMECHAR1 with SYMBOLNAMECHAR1.
+       (EXPRESSION): Likewise.
+       * testsuite/ld-scripts/expr.exp: Run pr22267.
+       * testsuite/ld-scripts/pr22267.d: New file.
+       * testsuite/ld-scripts/pr22267.s: Likewise.
+       * testsuite/ld-scripts/pr22267.t: Likewise.
+
 2017-10-07  H.J. Lu  <hongjiu.lu@intel.com>
 
        * testsuite/ld-elf/merge.d: Don't expect to fail for sparc.
index ba618ecc2715bdb380752e97a919c33563042e31..795a4d7c8effb3695715fef1670afdcad55257f4 100644 (file)
@@ -94,6 +94,7 @@ static void lex_warn_invalid (char *where, char *what);
 CMDFILENAMECHAR   [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~]
 CMDFILENAMECHAR1  [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~]
 FILENAMECHAR1  [_a-zA-Z\/\.\\\$\_\~]
+SYMBOLNAMECHAR1        [_a-zA-Z\/\.\\\$\_]
 SYMBOLCHARN     [_a-zA-Z\/\.\\\$\_\~0-9]
 FILENAMECHAR   [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~]
 WILDCHAR       [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~\?\*\^\!]
@@ -136,7 +137,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
 
 <DEFSYMEXP>"-"                  { RTOKEN('-');}
 <DEFSYMEXP>"+"                  { RTOKEN('+');}
-<DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}*   { yylval.name = xstrdup (yytext); return NAME; }
+<DEFSYMEXP>{SYMBOLNAMECHAR1}{SYMBOLCHARN}*   { yylval.name = xstrdup (yytext); return NAME; }
 <DEFSYMEXP>"="                  { RTOKEN('='); }
 
 <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
@@ -390,7 +391,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
                                  yylval.name = xstrdup (yytext + 2);
                                  return LNAME;
                                }
-<EXPRESSION>{FILENAMECHAR1}{NOCFILENAMECHAR}*  {
+<EXPRESSION>{SYMBOLNAMECHAR1}{NOCFILENAMECHAR}*        {
                                 yylval.name = xstrdup (yytext);
                                  return NAME;
                                }
index 9db5366c12a97b8cb6b848f16b3d5a288a9827be..62d45dc5deabec31b3347572f3e5767386c126cd 100644 (file)
@@ -25,6 +25,7 @@ run_dump_test sane1
 run_dump_test assign-loc
 run_dump_test pr14962
 run_dump_test pr14962-2
+run_dump_test pr22267
 
 set old_ldflags $LDFLAGS
 if { [istarget spu*-*-*] } {
diff --git a/ld/testsuite/ld-scripts/pr22267.d b/ld/testsuite/ld-scripts/pr22267.d
new file mode 100644 (file)
index 0000000..f66d4be
--- /dev/null
@@ -0,0 +1,7 @@
+#ld: -T pr22267.t
+#nm: -n
+
+# Some targets may zero-extend 32-bit address to 64 bits.
+#...
+0*f+00 A foo
+#pass
diff --git a/ld/testsuite/ld-scripts/pr22267.s b/ld/testsuite/ld-scripts/pr22267.s
new file mode 100644 (file)
index 0000000..c0a5cda
--- /dev/null
@@ -0,0 +1,10 @@
+       .globl main
+       .globl start
+       .globl _start
+       .globl __start
+       .text
+main:
+start:
+_start:
+__start:
+       .dc.a foo
diff --git a/ld/testsuite/ld-scripts/pr22267.t b/ld/testsuite/ld-scripts/pr22267.t
new file mode 100644 (file)
index 0000000..a075405
--- /dev/null
@@ -0,0 +1,4 @@
+SECTIONS
+{
+  foo = ~0xFF;
+}
This page took 0.031848 seconds and 4 git commands to generate.