Read an expression in the form of "ABSOLUTE(<expr>) op <expr> ...".
authorRui Ueyama <ruiu@google.com>
Wed, 19 Oct 2016 23:11:21 +0000 (23:11 +0000)
committerRui Ueyama <ruiu@google.com>
Wed, 19 Oct 2016 23:11:21 +0000 (23:11 +0000)
Fixes bug 30741.

llvm-svn: 284662

lld/ELF/LinkerScript.cpp
lld/test/ELF/linkerscript/absolute.s [new file with mode: 0644]

index b7783e4..663186f 100644 (file)
@@ -1432,7 +1432,9 @@ SymbolAssignment *ScriptParser::readAssignment(StringRef Name) {
   Expr E;
   assert(Op == "=" || Op == "+=");
   if (consume("ABSOLUTE")) {
-    E = readParenExpr();
+    // The RHS may be something like "ABSOLUTE(.) & 0xff".
+    // Call readExpr1 to read the whole expression.
+    E = readExpr1(readParenExpr(), 0);
     IsAbsolute = true;
   } else {
     E = readExpr();
diff --git a/lld/test/ELF/linkerscript/absolute.s b/lld/test/ELF/linkerscript/absolute.s
new file mode 100644 (file)
index 0000000..e4b156e
--- /dev/null
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS { foo = ABSOLUTE(.) + 1; };" > %t.script
+# RUN: ld.lld -o %t --script %t.script %t.o
+# RUN: llvm-readobj --symbols %t | FileCheck %s
+
+# CHECK:        Name: foo
+# CHECK-NEXT:   Value:
+# CHECK-NEXT:   Size:
+# CHECK-NEXT:   Binding:
+# CHECK-NEXT:   Type:
+# CHECK-NEXT:   Other:
+# CHECK-NEXT:   Section: Absolute
+# CHECK-NEXT: }
+
+.text
+.globl _start
+_start: