[lld] e7a7ad1 - [ELF] Support quoted symbols in symbol assignments
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 25 16:26:44 PDT 2021
Author: Fangrui Song
Date: 2021-07-25T16:26:37-07:00
New Revision: e7a7ad134fe182aad190cb3ebc441164470e92f5
URL: https://github.com/llvm/llvm-project/commit/e7a7ad134fe182aad190cb3ebc441164470e92f5
DIFF: https://github.com/llvm/llvm-project/commit/e7a7ad134fe182aad190cb3ebc441164470e92f5.diff
LOG: [ELF] Support quoted symbols in symbol assignments
glibc/elf/tst-absolute-zero-lib.lds uses `"absolute" = 0;`
Added:
Modified:
lld/ELF/ScriptParser.cpp
lld/test/ELF/linkerscript/symbol-name.test
lld/test/ELF/linkerscript/symbolreferenced.s
Removed:
################################################################################
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index 4726dd1c6a2c9..2c980eb810c77 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -1001,6 +1001,7 @@ SymbolAssignment *ScriptParser::readAssignment(StringRef tok) {
}
SymbolAssignment *ScriptParser::readSymbolAssignment(StringRef name) {
+ name = unquote(name);
StringRef op = next();
assert(op == "=" || op == "+=");
Expr e = readExpr();
@@ -1350,7 +1351,7 @@ Expr ScriptParser::readPrimary() {
return [=] { return alignTo(script->getDot(), e().getValue()); };
}
if (tok == "DEFINED") {
- StringRef name = readParenLiteral();
+ StringRef name = unquote(readParenLiteral());
return [=] {
Symbol *b = symtab->find(name);
return (b && b->isDefined()) ? 1 : 0;
@@ -1428,6 +1429,7 @@ Expr ScriptParser::readPrimary() {
return [=] { return *val; };
// Tok is a symbol name.
+ tok = unquote(tok);
if (!isValidSymbolName(tok))
setError("malformed number: " + tok);
script->referencedSymbols.push_back(tok);
diff --git a/lld/test/ELF/linkerscript/symbol-name.test b/lld/test/ELF/linkerscript/symbol-name.test
index e9755add79509..d74de698b9b00 100644
--- a/lld/test/ELF/linkerscript/symbol-name.test
+++ b/lld/test/ELF/linkerscript/symbol-name.test
@@ -1,8 +1,15 @@
# REQUIRES: x86
-## Test that . and $ can be used by symbol names in expressions.
+## Test that ., $ 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 /dev/null
+# RUN: ld.lld -T %s %t.o -o %t
+# RUN: llvm-readelf -s %t | FileCheck %s
+
+# 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
a0 = DEFINED(.TOC.) ? .TOC. : 0;
-a1 = DEFINED(__global_pointer$) ? __global_pointer$ : 0;
+"a1" = DEFINED(__global_pointer$) ? __global_pointer$ : 0;
+"a2" = DEFINED("a1") ? "a1" + 3 : 0;
diff --git a/lld/test/ELF/linkerscript/symbolreferenced.s b/lld/test/ELF/linkerscript/symbolreferenced.s
index ac8a88855d910..f6d9a1214fdd9 100644
--- a/lld/test/ELF/linkerscript/symbolreferenced.s
+++ b/lld/test/ELF/linkerscript/symbolreferenced.s
@@ -13,6 +13,10 @@
# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN1 %s
# HIDDEN1: 0000000000000001 l *ABS* 0000000000000000 .hidden newsym
+# RUN: echo 'SECTIONS { PROVIDE_HIDDEN("newsym" = 1);}' > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t
+# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN1 %s
+
.global _start
_start:
nop
More information about the llvm-commits
mailing list