Skip to content

Commit 2bf06d9

Browse files
committed
[ELF] Support symbol names with space in linker script expressions
Fix PR51961 Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D110490
1 parent 59540b2 commit 2bf06d9

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lld/ELF/ScriptParser.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,8 +1429,9 @@ Expr ScriptParser::readPrimary() {
14291429
return [=] { return *val; };
14301430

14311431
// Tok is a symbol name.
1432-
tok = unquote(tok);
1433-
if (!isValidSymbolName(tok))
1432+
if (tok.startswith("\""))
1433+
tok = unquote(tok);
1434+
else if (!isValidSymbolName(tok))
14341435
setError("malformed number: " + tok);
14351436
script->referencedSymbols.push_back(tok);
14361437
return [=] { return script->getSymbolValue(tok, location); };
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# REQUIRES: x86
2-
## Test that ., $ and " can be used by symbol names in expressions.
2+
## Test that ., $, space and " can be used by symbol names in expressions.
33

44
# RUN: llvm-mc -filetype=obj -triple=x86_64 /dev/null -o %t.o
55
# RUN: ld.lld -T %s %t.o -o %t
@@ -8,8 +8,10 @@
88
# CHECK: Value Size Type Bind Vis Ndx Name
99
# CHECK-DAG: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS a1
1010
# CHECK-DAG: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS a0
11-
# CHECK-DAG: 0000000000000003 0 NOTYPE GLOBAL DEFAULT ABS a2
11+
# CHECK-DAG: 0000000000000003 0 NOTYPE GLOBAL DEFAULT ABS a 2
12+
# CHECK-DAG: 0000000000000004 0 NOTYPE GLOBAL DEFAULT ABS a 3
1213

1314
a0 = DEFINED(.TOC.) ? .TOC. : 0;
1415
"a1" = DEFINED(__global_pointer$) ? __global_pointer$ : 0;
15-
"a2" = DEFINED("a1") ? "a1" + 3 : 0;
16+
"a 2" = DEFINED("a1") ? "a1" + 3 : 0;
17+
"a 3" = "a 2" + 1;

0 commit comments

Comments
 (0)