[ELF] Support symbol names with space in linker script expressions
authorFangrui Song <i@maskray.me>
Mon, 27 Sep 2021 16:50:41 +0000 (09:50 -0700)
committerFangrui Song <i@maskray.me>
Mon, 27 Sep 2021 16:50:42 +0000 (09:50 -0700)
Fix PR51961

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D110490

lld/ELF/ScriptParser.cpp
lld/test/ELF/linkerscript/symbol-name.test

index 1c743fd47747147205e6f7d10694cf4801d8fd99..dcbcfd4b9ba84638247f61f012b32631018b146b 100644 (file)
@@ -1429,8 +1429,9 @@ Expr ScriptParser::readPrimary() {
     return [=] { return *val; };
 
   // Tok is a symbol name.
-  tok = unquote(tok);
-  if (!isValidSymbolName(tok))
+  if (tok.startswith("\""))
+    tok = unquote(tok);
+  else if (!isValidSymbolName(tok))
     setError("malformed number: " + tok);
   script->referencedSymbols.push_back(tok);
   return [=] { return script->getSymbolValue(tok, location); };
index d74de698b9b0083503bf4fc0dbaf4b549c4ea9c3..f0373e1336a166b92bc1792990eda364c544e510 100644 (file)
@@ -1,5 +1,5 @@
 # REQUIRES: x86
-## Test that ., $ and " can be used by symbol names in expressions.
+## Test that ., $, space and " can be used by symbol names in expressions.
 
 # RUN: llvm-mc -filetype=obj -triple=x86_64 /dev/null -o %t.o
 # RUN: ld.lld -T %s %t.o -o %t
@@ -8,8 +8,10 @@
 # CHECK:      Value            Size Type   Bind   Vis     Ndx Name
 # CHECK-DAG:  0000000000000000    0 NOTYPE GLOBAL DEFAULT ABS a1
 # CHECK-DAG:  0000000000000000    0 NOTYPE GLOBAL DEFAULT ABS a0
-# CHECK-DAG:  0000000000000003    0 NOTYPE GLOBAL DEFAULT ABS a2
+# CHECK-DAG:  0000000000000003    0 NOTYPE GLOBAL DEFAULT ABS a 2
+# CHECK-DAG:  0000000000000004    0 NOTYPE GLOBAL DEFAULT ABS a 3
 
 a0 = DEFINED(.TOC.) ? .TOC. : 0;
 "a1" = DEFINED(__global_pointer$) ? __global_pointer$ : 0;
-"a2" = DEFINED("a1") ? "a1" + 3 : 0;
+"a 2" = DEFINED("a1") ? "a1" + 3 : 0;
+"a 3" = "a 2" + 1;