[PATCH] D23031: [LinkerScript] Support OR of FLAGS in PHDR directives
Rafael EspĂndola via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 2 06:58:57 PDT 2016
Just a correction. It looks like bfd supports any expressions in here.
With vanilla bfd I can use
PHDRS
{
ph_foo PT_LOAD FLAGS(1 + 2);
}
SECTIONS
{
.text : {*(.dynamic) } : ph_foo
}
But that is not documented or implemented in gold.
I did implement a hackish patch to support any expression (sorry for
the bad coordination). Let me know if you think it is worth it and I
will also implement a patch for supporting | in expressions.
Cheers,
Rafael
-------------- next part --------------
diff --git a/ELF/LinkerScript.cpp b/ELF/LinkerScript.cpp
index 8bb704c..436285e 100644
--- a/ELF/LinkerScript.cpp
+++ b/ELF/LinkerScript.cpp
@@ -645,7 +645,10 @@ 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. A general
+ // expression evaluation should take an environment as an argument.
+ // It is not clear if that is worth it for linker scripts.
+ PhdrCmd.Flags = readExpr()(0);
expect(")");
} else
setError("unexpected header attribute: " + Tok);
diff --git a/test/ELF/linkerscript/linkerscript-phdrs-flags.s b/test/ELF/linkerscript/linkerscript-phdrs-flags.s
index f198d85..d4a08f6 100644
--- a/test/ELF/linkerscript/linkerscript-phdrs-flags.s
+++ b/test/ELF/linkerscript/linkerscript-phdrs-flags.s
@@ -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: ]
More information about the llvm-commits
mailing list