Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lld
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2022-06-26 06:25:34 +0300
committerFangrui Song <i@maskray.me>2022-06-26 06:25:34 +0300
commitfe0de25b2195b66d1ebac5d3ebdb18f9e1e776da (patch)
tree91d4ba79b21333da7c2d0f3bde3b53c91236bbf4 /lld
parent475d722aced687c795ec2fae1c25abe42812582b (diff)
[ELF] Allow an expression to follow = in a symbol assignment
GNU ld doesn't require whitespace before =. Match it.
Diffstat (limited to 'lld')
-rw-r--r--lld/ELF/ScriptParser.cpp17
-rw-r--r--lld/test/ELF/linkerscript/symbol-assignexpr.s6
-rw-r--r--lld/test/ELF/linkerscript/symbols.s6
3 files changed, 19 insertions, 10 deletions
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index bd9807c7f3cb..d0fa449f5823 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 8bd8a9c1c44d..abbcccb84b83 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 5f0ca603d884..d5c3c2255411 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