[lld] 8c2030b - [LLD] [ELF] Add support for linker script unary plus operator (#121508)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 21 20:05:12 PST 2025


Author: Parth Arora
Date: 2025-01-21T20:05:07-08:00
New Revision: 8c2030b7d4c4f21270577187d6413c6b05784861

URL: https://github.com/llvm/llvm-project/commit/8c2030b7d4c4f21270577187d6413c6b05784861
DIFF: https://github.com/llvm/llvm-project/commit/8c2030b7d4c4f21270577187d6413c6b05784861.diff

LOG: [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

Added: 
    

Modified: 
    lld/ELF/ScriptParser.cpp
    lld/test/ELF/linkerscript/diag.test
    lld/test/ELF/linkerscript/operators.test

Removed: 
    


################################################################################
diff  --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index f53515cc3f3c0d..06a22613ee93ac 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -1489,6 +1489,8 @@ 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/diag.test b/lld/test/ELF/linkerscript/diag.test
index fbc24659a53114..114f5c2c0820b7 100644
--- a/lld/test/ELF/linkerscript/diag.test
+++ b/lld/test/ELF/linkerscript/diag.test
@@ -12,9 +12,9 @@ SECTIONS {
 }
 
 # RUN: not ld.lld -shared 0.o -T 1.lds 2>&1 | FileCheck %s --check-prefix=CHECK1 --match-full-lines --strict-whitespace
-#      CHECK1:{{.*}}:2: malformed number: +
+#      CHECK1:{{.*}}:2: malformed number: {
 # CHECK1-NEXT:>>>   .text + { *(.text) }
-# CHECK1-NEXT:>>>         ^
+# CHECK1-NEXT:>>>           ^
 
 #--- 2.lds
 

diff  --git a/lld/test/ELF/linkerscript/operators.test b/lld/test/ELF/linkerscript/operators.test
index 27209a2e40f598..f84f23fd4d469d 100644
--- a/lld/test/ELF/linkerscript/operators.test
+++ b/lld/test/ELF/linkerscript/operators.test
@@ -73,6 +73,8 @@ SECTIONS {
   log2ceil100000000 = LOG2CEIL(0x100000000);
   log2ceil100000001 = LOG2CEIL(0x100000001);
   log2ceilmax = LOG2CEIL(0xffffffffffffffff);
+  unaryadd = +3 + ++5;
+  unaryadd_and_unaryminus = 15 + +-5 + -+7;
 }
 
 # CHECK:      0000000000000002 A unary
@@ -126,6 +128,8 @@ SECTIONS {
 # CHECK-NEXT: 0000000000000020 A log2ceil100000000
 # CHECK-NEXT: 0000000000000021 A log2ceil100000001
 # CHECK-NEXT: 0000000000000040 A log2ceilmax
+# CHECK-NEXT: 0000000000000008 A unaryadd
+# CHECK-NEXT: 0000000000000003 A unaryadd_and_unaryminus
 
 ## Mailformed number error.
 # RUN: echo "SECTIONS { . = 0x12Q41; }" > %t.script


        


More information about the llvm-commits mailing list