From 76f361eb4934dcda0626517c311b34fbc92d09b9 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Mon, 9 Oct 2017 04:17:10 -0700 Subject: [PATCH] ld: Don't allow '~' as the first char in symbol name 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 | 11 +++++++++++ ld/ldlex.l | 5 +++-- ld/testsuite/ld-scripts/expr.exp | 1 + ld/testsuite/ld-scripts/pr22267.d | 7 +++++++ ld/testsuite/ld-scripts/pr22267.s | 10 ++++++++++ ld/testsuite/ld-scripts/pr22267.t | 4 ++++ 6 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 ld/testsuite/ld-scripts/pr22267.d create mode 100644 ld/testsuite/ld-scripts/pr22267.s create mode 100644 ld/testsuite/ld-scripts/pr22267.t diff --git a/ld/ChangeLog b/ld/ChangeLog index 55e36a515bc..18d4b1e0478 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,14 @@ +2017-10-09 H.J. Lu + + 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 * testsuite/ld-elf/merge.d: Don't expect to fail for sparc. diff --git a/ld/ldlex.l b/ld/ldlex.l index ba618ecc271..795a4d7c8ef 100644 --- a/ld/ldlex.l +++ b/ld/ldlex.l @@ -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\[\]\-\!\^\\]|::)* "-" { RTOKEN('-');} "+" { RTOKEN('+');} -{FILENAMECHAR1}{SYMBOLCHARN}* { yylval.name = xstrdup (yytext); return NAME; } +{SYMBOLNAMECHAR1}{SYMBOLCHARN}* { yylval.name = xstrdup (yytext); return NAME; } "=" { RTOKEN('='); } "$"([0-9A-Fa-f])+ { @@ -390,7 +391,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)* yylval.name = xstrdup (yytext + 2); return LNAME; } -{FILENAMECHAR1}{NOCFILENAMECHAR}* { +{SYMBOLNAMECHAR1}{NOCFILENAMECHAR}* { yylval.name = xstrdup (yytext); return NAME; } diff --git a/ld/testsuite/ld-scripts/expr.exp b/ld/testsuite/ld-scripts/expr.exp index 9db5366c12a..62d45dc5dea 100644 --- a/ld/testsuite/ld-scripts/expr.exp +++ b/ld/testsuite/ld-scripts/expr.exp @@ -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 index 00000000000..f66d4be49c1 --- /dev/null +++ b/ld/testsuite/ld-scripts/pr22267.d @@ -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 index 00000000000..c0a5cda6e95 --- /dev/null +++ b/ld/testsuite/ld-scripts/pr22267.s @@ -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 index 00000000000..a0754058e59 --- /dev/null +++ b/ld/testsuite/ld-scripts/pr22267.t @@ -0,0 +1,4 @@ +SECTIONS +{ + foo = ~0xFF; +} -- 2.30.2