Skip to content

Commit fe0de25

Browse files
committed
[ELF] Allow an expression to follow = in a symbol assignment
GNU ld doesn't require whitespace before =. Match it.
1 parent 475d722 commit fe0de25

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

lld/ELF/ScriptParser.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "llvm/Support/FileSystem.h"
3333
#include "llvm/Support/MathExtras.h"
3434
#include "llvm/Support/Path.h"
35+
#include "llvm/Support/SaveAndRestore.h"
3536
#include "llvm/Support/TimeProfiler.h"
3637
#include <cassert>
3738
#include <limits>
@@ -1030,14 +1031,22 @@ SymbolAssignment *ScriptParser::readAssignment(StringRef tok) {
10301031

10311032
size_t oldPos = pos;
10321033
SymbolAssignment *cmd = nullptr;
1033-
if (peek() == "=" || peek() == "+=")
1034+
if (peek().startswith("=")) {
1035+
// Support = followed by an expression without whitespace.
1036+
SaveAndRestore<bool> saved(inExpr, true);
10341037
cmd = readSymbolAssignment(tok);
1035-
else if (tok == "PROVIDE")
1038+
} else if (peek() == "+=") {
1039+
cmd = readSymbolAssignment(tok);
1040+
} else if (tok == "PROVIDE") {
1041+
SaveAndRestore<bool> saved(inExpr, true);
10361042
cmd = readProvideHidden(true, false);
1037-
else if (tok == "HIDDEN")
1043+
} else if (tok == "HIDDEN") {
1044+
SaveAndRestore<bool> saved(inExpr, true);
10381045
cmd = readProvideHidden(false, true);
1039-
else if (tok == "PROVIDE_HIDDEN")
1046+
} else if (tok == "PROVIDE_HIDDEN") {
1047+
SaveAndRestore<bool> saved(inExpr, true);
10401048
cmd = readProvideHidden(true, true);
1049+
}
10411050

10421051
if (cmd) {
10431052
cmd->commandString =

lld/test/ELF/linkerscript/symbol-assignexpr.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
# RUN: symbol4 = symbol + -4; \
99
# RUN: symbol5 = symbol - ~0xfffb; \
1010
# RUN: symbol6 = symbol - ~(0xfff0 + 0xb); \
11-
# RUN: symbol7 = symbol - ~ 0xfffb + 4; \
12-
# RUN: symbol8 = ~ 0xffff + 4; \
13-
# RUN: symbol9 = - 4; \
11+
# RUN: symbol7 =symbol - ~ 0xfffb + 4; \
12+
# RUN: symbol8 =~ 0xffff + 4; \
13+
# RUN: symbol9 =- 4; \
1414
# RUN: symbol10 = 0xfedcba9876543210; \
1515
# RUN: symbol11 = ((0x28000 + 0x1fff) & ~(0x1000 + -1)); \
1616
# RUN: symbol12 = 0x1234; \

lld/test/ELF/linkerscript/symbols.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@
2222

2323
# Provide existing symbol. The value should be 0, even though we
2424
# have value of 1 in PROVIDE()
25-
# RUN: echo "SECTIONS { PROVIDE(somesym = 1);}" > %t.script
25+
# RUN: echo "SECTIONS { PROVIDE(somesym =1);}" > %t.script
2626
# RUN: ld.lld -o %t1 --script %t.script %t
2727
# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=PROVIDE2 %s
2828
# PROVIDE2: 0000000000000000 g *ABS* 0000000000000000 somesym
2929

3030
# Provide existing symbol. The value should be 0, even though we
3131
# have value of 1 in PROVIDE_HIDDEN(). Visibility should not change
32-
# RUN: echo "SECTIONS { PROVIDE_HIDDEN(somesym = 1);}" > %t.script
32+
# RUN: echo "SECTIONS { PROVIDE_HIDDEN(somesym =1);}" > %t.script
3333
# RUN: ld.lld -o %t1 --script %t.script %t
3434
# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN2 %s
3535
# HIDDEN2: 0000000000000000 g *ABS* 0000000000000000 somesym
3636

3737
# Hidden symbol assignment.
38-
# RUN: echo "SECTIONS { HIDDEN(newsym = 1);}" > %t.script
38+
# RUN: echo "SECTIONS { HIDDEN(newsym =1);}" > %t.script
3939
# RUN: ld.lld -o %t1 --script %t.script %t
4040
# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN3 %s
4141
# HIDDEN3: 0000000000000001 l *ABS* 0000000000000000 .hidden newsym

0 commit comments

Comments
 (0)