[lld] [LLD] [ELF] Add support for linker script unary plus operator (PR #121508)
Parth Arora via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 2 09:54:12 PST 2025
https://github.com/partaror created https://github.com/llvm/llvm-project/pull/121508
This commit adds support for linker script unary plus ('+') operator. It is helpful for improving compatibility between LLD and GNU LD.
>From c9eb22861319b5b9e30e38520a2bd59887774ccc Mon Sep 17 00:00:00 2001
From: Parth Arora <quic_partaror at quicinc.com>
Date: Thu, 2 Jan 2025 09:32:23 -0800
Subject: [PATCH] [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.
Change-Id: I37057324172667ce6bbe641dc372b15f82802a46
---
lld/ELF/ScriptParser.cpp | 3 +++
lld/test/ELF/linkerscript/operators.test | 2 ++
2 files changed, 5 insertions(+)
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index f53515cc3f3c0d..49ddd5e7999cfd 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -1489,6 +1489,9 @@ Expr ScriptParser::readPrimary() {
Expr e = readPrimary();
return [=] { return -e().getValue(); };
}
+ if (consume("+")) {
+ return readPrimary();
+ }
StringRef tok = next();
std::string location = getCurrentLocation();
diff --git a/lld/test/ELF/linkerscript/operators.test b/lld/test/ELF/linkerscript/operators.test
index 27209a2e40f598..d7b3becf36d706 100644
--- a/lld/test/ELF/linkerscript/operators.test
+++ b/lld/test/ELF/linkerscript/operators.test
@@ -73,6 +73,7 @@ SECTIONS {
log2ceil100000000 = LOG2CEIL(0x100000000);
log2ceil100000001 = LOG2CEIL(0x100000001);
log2ceilmax = LOG2CEIL(0xffffffffffffffff);
+ unaryadd = +3 + ++5;
}
# CHECK: 0000000000000002 A unary
@@ -126,6 +127,7 @@ SECTIONS {
# CHECK-NEXT: 0000000000000020 A log2ceil100000000
# CHECK-NEXT: 0000000000000021 A log2ceil100000001
# CHECK-NEXT: 0000000000000040 A log2ceilmax
+# CHECK-NEXT: 0000000000000008 A unaryadd
## Mailformed number error.
# RUN: echo "SECTIONS { . = 0x12Q41; }" > %t.script
More information about the llvm-commits
mailing list