mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-13 03:12:46 +00:00
[ELF] Support FLAGS attribute in program header definition
llvm-svn: 276260
This commit is contained in:
parent
08c588c73a
commit
865bf8637b
@ -334,7 +334,7 @@ LinkerScript<ELFT>::createPhdrs(ArrayRef<OutputSectionBase<ELFT> *> Sections) {
|
|||||||
std::vector<Phdr> Phdrs;
|
std::vector<Phdr> Phdrs;
|
||||||
|
|
||||||
for (const PhdrsCommand &Cmd : Opt.PhdrsCommands) {
|
for (const PhdrsCommand &Cmd : Opt.PhdrsCommands) {
|
||||||
Phdrs.emplace_back(Cmd.Type, PF_R);
|
Phdrs.emplace_back(Cmd.Type, Cmd.Flags == UINT_MAX ? PF_R : Cmd.Flags);
|
||||||
Phdr &Added = Phdrs.back();
|
Phdr &Added = Phdrs.back();
|
||||||
|
|
||||||
if (Cmd.HasFilehdr)
|
if (Cmd.HasFilehdr)
|
||||||
@ -387,6 +387,8 @@ LinkerScript<ELFT>::createPhdrs(ArrayRef<OutputSectionBase<ELFT> *> Sections) {
|
|||||||
// Assign headers specified by linker script
|
// Assign headers specified by linker script
|
||||||
for (size_t Id : PhdrIds) {
|
for (size_t Id : PhdrIds) {
|
||||||
Phdrs[Id].add(Sec);
|
Phdrs[Id].add(Sec);
|
||||||
|
if (Opt.PhdrsCommands[Id].Flags == UINT_MAX)
|
||||||
|
Phdrs[Id].H.p_flags |= toPhdrFlags(Sec->getFlags());
|
||||||
Phdrs[Id].H.p_flags |= toPhdrFlags(Sec->getFlags());
|
Phdrs[Id].H.p_flags |= toPhdrFlags(Sec->getFlags());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -669,7 +671,7 @@ void ScriptParser::readPhdrs() {
|
|||||||
expect("{");
|
expect("{");
|
||||||
while (!Error && !skip("}")) {
|
while (!Error && !skip("}")) {
|
||||||
StringRef Tok = next();
|
StringRef Tok = next();
|
||||||
Opt.PhdrsCommands.push_back({Tok, PT_NULL, false, false});
|
Opt.PhdrsCommands.push_back({Tok, PT_NULL, false, false, UINT_MAX});
|
||||||
PhdrsCommand &PhdrCmd = Opt.PhdrsCommands.back();
|
PhdrsCommand &PhdrCmd = Opt.PhdrsCommands.back();
|
||||||
|
|
||||||
PhdrCmd.Type = readPhdrType();
|
PhdrCmd.Type = readPhdrType();
|
||||||
@ -681,7 +683,11 @@ void ScriptParser::readPhdrs() {
|
|||||||
PhdrCmd.HasFilehdr = true;
|
PhdrCmd.HasFilehdr = true;
|
||||||
else if (Tok == "PHDRS")
|
else if (Tok == "PHDRS")
|
||||||
PhdrCmd.HasPhdrs = true;
|
PhdrCmd.HasPhdrs = true;
|
||||||
else
|
else if (Tok == "FLAGS") {
|
||||||
|
expect("(");
|
||||||
|
next().getAsInteger(0, PhdrCmd.Flags);
|
||||||
|
expect(")");
|
||||||
|
} else
|
||||||
setError("unexpected header attribute: " + Tok);
|
setError("unexpected header attribute: " + Tok);
|
||||||
} while (!Error);
|
} while (!Error);
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,7 @@ struct PhdrsCommand {
|
|||||||
unsigned Type;
|
unsigned Type;
|
||||||
bool HasFilehdr;
|
bool HasFilehdr;
|
||||||
bool HasPhdrs;
|
bool HasPhdrs;
|
||||||
|
unsigned Flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ScriptConfiguration holds linker script parse results.
|
// ScriptConfiguration holds linker script parse results.
|
||||||
|
36
lld/test/ELF/linkerscript-phdrs-flags.s
Normal file
36
lld/test/ELF/linkerscript-phdrs-flags.s
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user