[lld] fe0de25 - [ELF] Allow an expression to follow = in a symbol assignment
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 25 20:25:42 PDT 2022
Author: Fangrui Song
Date: 2022-06-25T20:25:34-07:00
New Revision: fe0de25b2195b66d1ebac5d3ebdb18f9e1e776da
URL: https://github.com/llvm/llvm-project/commit/fe0de25b2195b66d1ebac5d3ebdb18f9e1e776da
DIFF: https://github.com/llvm/llvm-project/commit/fe0de25b2195b66d1ebac5d3ebdb18f9e1e776da.diff
LOG: [ELF] Allow an expression to follow = in a symbol assignment
GNU ld doesn't require whitespace before =. Match it.
Added:
Modified:
lld/ELF/ScriptParser.cpp
lld/test/ELF/linkerscript/symbol-assignexpr.s
lld/test/ELF/linkerscript/symbols.s
Removed:
################################################################################
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index bd9807c7f3cb5..d0fa449f58230 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -32,6 +32,7 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/TimeProfiler.h"
#include <cassert>
#include <limits>
@@ -1030,14 +1031,22 @@ SymbolAssignment *ScriptParser::readAssignment(StringRef tok) {
size_t oldPos = pos;
SymbolAssignment *cmd = nullptr;
- if (peek() == "=" || peek() == "+=")
+ if (peek().startswith("=")) {
+ // Support = followed by an expression without whitespace.
+ SaveAndRestore<bool> saved(inExpr, true);
cmd = readSymbolAssignment(tok);
- else if (tok == "PROVIDE")
+ } else if (peek() == "+=") {
+ cmd = readSymbolAssignment(tok);
+ } else if (tok == "PROVIDE") {
+ SaveAndRestore<bool> saved(inExpr, true);
cmd = readProvideHidden(true, false);
- else if (tok == "HIDDEN")
+ } else if (tok == "HIDDEN") {
+ SaveAndRestore<bool> saved(inExpr, true);
cmd = readProvideHidden(false, true);
- else if (tok == "PROVIDE_HIDDEN")
+ } else if (tok == "PROVIDE_HIDDEN") {
+ SaveAndRestore<bool> saved(inExpr, true);
cmd = readProvideHidden(true, true);
+ }
if (cmd) {
cmd->commandString =
diff --git a/lld/test/ELF/linkerscript/symbol-assignexpr.s b/lld/test/ELF/linkerscript/symbol-assignexpr.s
index 8bd8a9c1c44d3..abbcccb84b836 100644
--- a/lld/test/ELF/linkerscript/symbol-assignexpr.s
+++ b/lld/test/ELF/linkerscript/symbol-assignexpr.s
@@ -8,9 +8,9 @@
# RUN: symbol4 = symbol + -4; \
# RUN: symbol5 = symbol - ~0xfffb; \
# RUN: symbol6 = symbol - ~(0xfff0 + 0xb); \
-# RUN: symbol7 = symbol - ~ 0xfffb + 4; \
-# RUN: symbol8 = ~ 0xffff + 4; \
-# RUN: symbol9 = - 4; \
+# RUN: symbol7 =symbol - ~ 0xfffb + 4; \
+# RUN: symbol8 =~ 0xffff + 4; \
+# RUN: symbol9 =- 4; \
# RUN: symbol10 = 0xfedcba9876543210; \
# RUN: symbol11 = ((0x28000 + 0x1fff) & ~(0x1000 + -1)); \
# RUN: symbol12 = 0x1234; \
diff --git a/lld/test/ELF/linkerscript/symbols.s b/lld/test/ELF/linkerscript/symbols.s
index 5f0ca603d8841..d5c3c2255411d 100644
--- a/lld/test/ELF/linkerscript/symbols.s
+++ b/lld/test/ELF/linkerscript/symbols.s
@@ -22,20 +22,20 @@
# Provide existing symbol. The value should be 0, even though we
# have value of 1 in PROVIDE()
-# RUN: echo "SECTIONS { PROVIDE(somesym = 1);}" > %t.script
+# RUN: echo "SECTIONS { PROVIDE(somesym =1);}" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=PROVIDE2 %s
# PROVIDE2: 0000000000000000 g *ABS* 0000000000000000 somesym
# Provide existing symbol. The value should be 0, even though we
# have value of 1 in PROVIDE_HIDDEN(). Visibility should not change
-# RUN: echo "SECTIONS { PROVIDE_HIDDEN(somesym = 1);}" > %t.script
+# RUN: echo "SECTIONS { PROVIDE_HIDDEN(somesym =1);}" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN2 %s
# HIDDEN2: 0000000000000000 g *ABS* 0000000000000000 somesym
# Hidden symbol assignment.
-# RUN: echo "SECTIONS { HIDDEN(newsym = 1);}" > %t.script
+# RUN: echo "SECTIONS { HIDDEN(newsym =1);}" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN3 %s
# HIDDEN3: 0000000000000001 l *ABS* 0000000000000000 .hidden newsym
More information about the llvm-commits
mailing list