Skip to content

Commit 81d61fc

Browse files
parth-07quic-seaswara
authored andcommitted
[LinkerScript] Parse symbol assignment inside PROVIDE in LexState::Expr
This commit fixes unexpected error when parsing symbol assignment inside PROVIDE statement when the symbol assignment does not contain whitespaces around the equal-to operator. Closes #82 Signed-off-by: Parth Arora <[email protected]>
1 parent 7a36913 commit 81d61fc

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

lib/ScriptParser/ScriptParser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ void ScriptParser::readProvideHidden(StringRef Tok) {
538538
else
539539
llvm_unreachable("Expected PROVIDE/HIDDEN/PROVIDE_HIDDEN assignments!");
540540
expect("(");
541+
llvm::SaveAndRestore SaveLexState(LexState, LexState::Expr);
541542
Tok = next();
542543
if (peek() != "=") {
543544
setError("= expected, but got " + next());
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
SECTIONS {
2+
. = 0x11;
3+
PROVIDE(foo=.);
4+
OUT: {
5+
PROVIDE(bar=foo);
6+
}
7+
}
8+
PROVIDE(baz=bar);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#---ProvideSymbolNoSpaceAroundEqualTo.test--------------------- Executable,LS------------------#
2+
#BEGIN_COMMENT
3+
# This test checks that the linker correctly parses PROVIDE(var=value) expression.
4+
#END_COMMENT
5+
RUN: %touch %t1.1.o
6+
RUN: %link %linkopts -o %t1.a.out %t1.1.o -T %p/Inputs/script.t -u foo -u bar -u baz
7+
RUN: %readelf -s %t1.a.out | %filecheck %s
8+
9+
CHECK: 11 {{.*}} ABS bar
10+
CHECK: 11 {{.*}} ABS baz
11+
CHECK: 11 {{.*}} ABS foo

0 commit comments

Comments
 (0)