Skip to content

Commit e7a7ad1

Browse files
committed
[ELF] Support quoted symbols in symbol assignments
glibc/elf/tst-absolute-zero-lib.lds uses `"absolute" = 0;`
1 parent 75e7d13 commit e7a7ad1

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

lld/ELF/ScriptParser.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,7 @@ SymbolAssignment *ScriptParser::readAssignment(StringRef tok) {
10011001
}
10021002

10031003
SymbolAssignment *ScriptParser::readSymbolAssignment(StringRef name) {
1004+
name = unquote(name);
10041005
StringRef op = next();
10051006
assert(op == "=" || op == "+=");
10061007
Expr e = readExpr();
@@ -1350,7 +1351,7 @@ Expr ScriptParser::readPrimary() {
13501351
return [=] { return alignTo(script->getDot(), e().getValue()); };
13511352
}
13521353
if (tok == "DEFINED") {
1353-
StringRef name = readParenLiteral();
1354+
StringRef name = unquote(readParenLiteral());
13541355
return [=] {
13551356
Symbol *b = symtab->find(name);
13561357
return (b && b->isDefined()) ? 1 : 0;
@@ -1428,6 +1429,7 @@ Expr ScriptParser::readPrimary() {
14281429
return [=] { return *val; };
14291430

14301431
// Tok is a symbol name.
1432+
tok = unquote(tok);
14311433
if (!isValidSymbolName(tok))
14321434
setError("malformed number: " + tok);
14331435
script->referencedSymbols.push_back(tok);
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
# REQUIRES: x86
2-
## Test that . and $ can be used by symbol names in expressions.
2+
## Test that ., $ and " can be used by symbol names in expressions.
33

44
# RUN: llvm-mc -filetype=obj -triple=x86_64 /dev/null -o %t.o
5-
# RUN: ld.lld -T %s %t.o -o /dev/null
5+
# RUN: ld.lld -T %s %t.o -o %t
6+
# RUN: llvm-readelf -s %t | FileCheck %s
7+
8+
# CHECK: Value Size Type Bind Vis Ndx Name
9+
# CHECK-DAG: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS a1
10+
# CHECK-DAG: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS a0
11+
# CHECK-DAG: 0000000000000003 0 NOTYPE GLOBAL DEFAULT ABS a2
612

713
a0 = DEFINED(.TOC.) ? .TOC. : 0;
8-
a1 = DEFINED(__global_pointer$) ? __global_pointer$ : 0;
14+
"a1" = DEFINED(__global_pointer$) ? __global_pointer$ : 0;
15+
"a2" = DEFINED("a1") ? "a1" + 3 : 0;

lld/test/ELF/linkerscript/symbolreferenced.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN1 %s
1414
# HIDDEN1: 0000000000000001 l *ABS* 0000000000000000 .hidden newsym
1515

16+
# RUN: echo 'SECTIONS { PROVIDE_HIDDEN("newsym" = 1);}' > %t.script
17+
# RUN: ld.lld -o %t1 --script %t.script %t
18+
# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN1 %s
19+
1620
.global _start
1721
_start:
1822
nop

0 commit comments

Comments
 (0)