Support expressions inside FLAGS.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 2 Aug 2016 22:14:57 +0000 (22:14 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 2 Aug 2016 22:14:57 +0000 (22:14 +0000)
This is an undocumented bfd feature. It is reasonable for making the
scripts a bit more readable.

llvm-svn: 277532

lld/ELF/LinkerScript.cpp
lld/test/ELF/linkerscript/linkerscript-phdrs-flags.s

index 8bb704c..c5b1984 100644 (file)
@@ -645,7 +645,9 @@ void ScriptParser::readPhdrs() {
         PhdrCmd.HasPhdrs = true;
       else if (Tok == "FLAGS") {
         expect("(");
-        next().getAsInteger(0, PhdrCmd.Flags);
+        // Passing 0 for the value of dot is a bit of a hack. It means that
+        // we accept expressions like ".|1".
+        PhdrCmd.Flags = readExpr()(0);
         expect(")");
       } else
         setError("unexpected header attribute: " + Tok);
index f198d85..d4a08f6 100644 (file)
@@ -1,6 +1,6 @@
 # REQUIRES: x86
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
-# RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS FLAGS (1);} \
+# RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS FLAGS (1 + 0x2);} \
 # RUN:       SECTIONS { \
 # RUN:           . = 0x10000200; \
 # RUN:           .text : {*(.text.*)} :all \
@@ -17,7 +17,8 @@
 # CHECK-NEXT:    PhysicalAddress: 0x10000000
 # CHECK-NEXT:    FileSize: 521
 # CHECK-NEXT:    MemSize: 521
-# CHECK-NEXT:    Flags [ (0x1)
+# CHECK-NEXT:    Flags [
+# CHECK-NEXT:      PF_W (0x2)
 # CHECK-NEXT:      PF_X (0x1)
 # CHECK-NEXT:    ]