[PATCH] D22564: [ELF] Support FLAGS attribute in PHDR definition
Eugene Leviant via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 20 03:56:30 PDT 2016
evgeny777 created this revision.
evgeny777 added a reviewer: ruiu.
evgeny777 added subscribers: grimar, ikudrin, llvm-commits.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.
Allows user to specify flags for each program header
Repository:
rL LLVM
https://reviews.llvm.org/D22564
Files:
ELF/LinkerScript.cpp
ELF/LinkerScript.h
test/ELF/linkerscript-phdrs-flags.s
Index: test/ELF/linkerscript-phdrs-flags.s
===================================================================
--- test/ELF/linkerscript-phdrs-flags.s
+++ test/ELF/linkerscript-phdrs-flags.s
@@ -0,0 +1,36 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS FLAGS (7);} \
+# RUN: SECTIONS { \
+# RUN: . = 0x10000200; \
+# RUN: .text : {*(.text.*)} :all \
+# RUN: .foo : {*(.foo.*)} :all \
+# RUN: .data : {*(.data.*)} :all}" > %t.script
+
+# RUN: ld.lld -o %t1 --script %t.script %t
+# RUN: llvm-readobj -program-headers %t1 | FileCheck %s
+# CHECK: ProgramHeaders [
+# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_LOAD (0x1)
+# CHECK-NEXT: Offset: 0x0
+# CHECK-NEXT: VirtualAddress: 0x10000000
+# CHECK-NEXT: PhysicalAddress: 0x10000000
+# CHECK-NEXT: FileSize: 521
+# CHECK-NEXT: MemSize: 521
+# CHECK-NEXT: Flags [ (0x7)
+# CHECK-NEXT: PF_R (0x4)
+# CHECK-NEXT: PF_W (0x2)
+# CHECK-NEXT: PF_X (0x1)
+# CHECK-NEXT: ]
+
+.global _start
+_start:
+ nop
+
+.section .foo.1,"a"
+foo1:
+ .long 0
+
+.section .foo.2,"a"
+foo2:
+ .long 0
Index: ELF/LinkerScript.h
===================================================================
--- ELF/LinkerScript.h
+++ ELF/LinkerScript.h
@@ -55,6 +55,8 @@
unsigned Type;
bool HasFilehdr;
bool HasPhdrs;
+ bool HasFlags;
+ unsigned Flags;
};
// ScriptConfiguration holds linker script parse results.
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -285,7 +285,7 @@
std::vector<Phdr> Phdrs;
for (const PhdrsCommand &Cmd : Opt.PhdrsCommands) {
- Phdrs.emplace_back(Cmd.Type, PF_R);
+ Phdrs.emplace_back(Cmd.Type, Cmd.HasFlags ? Cmd.Flags : PF_R);
Phdr &Added = Phdrs.back();
if (Cmd.HasFilehdr)
@@ -338,7 +338,8 @@
// Assign headers specified by linker script
for (size_t Id : PhdrIds) {
Phdrs[Id].AddSec(Sec);
- Phdrs[Id].H.p_flags |= toPhdrFlags(Sec->getFlags());
+ if (!Opt.PhdrsCommands[Id].HasFlags)
+ Phdrs[Id].H.p_flags |= toPhdrFlags(Sec->getFlags());
}
} else {
// If we have no load segment or flags've changed then we want new load
@@ -616,7 +617,7 @@
expect("{");
while (!Error && !skip("}")) {
StringRef Tok = next();
- Opt.PhdrsCommands.push_back({Tok, PT_NULL, false, false});
+ Opt.PhdrsCommands.push_back({Tok, PT_NULL, false, false, false, 0});
PhdrsCommand &PhdrCmd = Opt.PhdrsCommands.back();
PhdrCmd.Type = readPhdrType();
@@ -628,6 +629,12 @@
PhdrCmd.HasFilehdr = true;
else if (Tok == "PHDRS")
PhdrCmd.HasPhdrs = true;
+ else if (Tok == "FLAGS") {
+ PhdrCmd.HasFlags = true;
+ expect("(");
+ next().getAsInteger(0, PhdrCmd.Flags);
+ expect(")");
+ }
else
setError("unexpected header attribute: " + Tok);
} while (!Error);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22564.64656.patch
Type: text/x-patch
Size: 3076 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160720/a06b9624/attachment.bin>
More information about the llvm-commits
mailing list