Skip to content

Commit e91a3e3

Browse files
committed
[LLD] [ELF] Add support for linker script unary plus operator
This commit adds support for linker script unary plus ('+') operator. It is helpful for improving compatibility between LLD and GNU LD.
1 parent 4a890c2 commit e91a3e3

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

lld/ELF/ScriptParser.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,9 @@ Expr ScriptParser::readPrimary() {
14891489
Expr e = readPrimary();
14901490
return [=] { return -e().getValue(); };
14911491
}
1492+
if (consume("+")) {
1493+
return readPrimary();
1494+
}
14921495

14931496
StringRef tok = next();
14941497
std::string location = getCurrentLocation();

lld/test/ELF/linkerscript/operators.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ SECTIONS {
7373
log2ceil100000000 = LOG2CEIL(0x100000000);
7474
log2ceil100000001 = LOG2CEIL(0x100000001);
7575
log2ceilmax = LOG2CEIL(0xffffffffffffffff);
76+
unaryadd = +3 + ++5;
7677
}
7778

7879
# CHECK: 0000000000000002 A unary
@@ -126,6 +127,7 @@ SECTIONS {
126127
# CHECK-NEXT: 0000000000000020 A log2ceil100000000
127128
# CHECK-NEXT: 0000000000000021 A log2ceil100000001
128129
# CHECK-NEXT: 0000000000000040 A log2ceilmax
130+
# CHECK-NEXT: 0000000000000008 A unaryadd
129131

130132
## Mailformed number error.
131133
# RUN: echo "SECTIONS { . = 0x12Q41; }" > %t.script

0 commit comments

Comments
 (0)