Skip to content

Commit 8c2030b

Browse files
authored
[LLD] [ELF] Add support for linker script unary plus operator (#121508)
This commit adds support for linker script unary plus ('+') operator. It is helpful for improving compatibility between LLD and GNU LD. Closes #118047
1 parent 18ee7e1 commit 8c2030b

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

lld/ELF/ScriptParser.cpp

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

14931495
StringRef tok = next();
14941496
std::string location = getCurrentLocation();

lld/test/ELF/linkerscript/diag.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ SECTIONS {
1212
}
1313

1414
# RUN: not ld.lld -shared 0.o -T 1.lds 2>&1 | FileCheck %s --check-prefix=CHECK1 --match-full-lines --strict-whitespace
15-
# CHECK1:{{.*}}:2: malformed number: +
15+
# CHECK1:{{.*}}:2: malformed number: {
1616
# CHECK1-NEXT:>>> .text + { *(.text) }
17-
# CHECK1-NEXT:>>> ^
17+
# CHECK1-NEXT:>>> ^
1818

1919
#--- 2.lds
2020

lld/test/ELF/linkerscript/operators.test

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

7880
# CHECK: 0000000000000002 A unary
@@ -126,6 +128,8 @@ SECTIONS {
126128
# CHECK-NEXT: 0000000000000020 A log2ceil100000000
127129
# CHECK-NEXT: 0000000000000021 A log2ceil100000001
128130
# CHECK-NEXT: 0000000000000040 A log2ceilmax
131+
# CHECK-NEXT: 0000000000000008 A unaryadd
132+
# CHECK-NEXT: 0000000000000003 A unaryadd_and_unaryminus
129133

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

0 commit comments

Comments
 (0)