[llvm] 2120612 - [ELF] Support for PT_GNU_PROPERTY in header and tools
Peter Smith via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 4 07:51:11 PST 2019
Author: Peter Smith
Date: 2019-12-04T15:38:12Z
New Revision: 2120612e46bc9c1b0826618229154b76cdf41309
URL: https://github.com/llvm/llvm-project/commit/2120612e46bc9c1b0826618229154b76cdf41309
DIFF: https://github.com/llvm/llvm-project/commit/2120612e46bc9c1b0826618229154b76cdf41309.diff
LOG: [ELF] Support for PT_GNU_PROPERTY in header and tools
The PT_GNU_PROPERTY is generated by a linker to describe the
.note.gnu.property section. The Linux kernel uses this program header to
locate the .note.gnu.property section.
It is described in "The Linux gABI extension"
Include support for llvm-readelf, llvm-readobj and the yaml reader and
writers.
Differential Revision: https://reviews.llvm.org/D70959
Added:
llvm/test/tools/llvm-objdump/elf-pt-gnu-property.test
llvm/test/tools/llvm-readobj/elf-pt-gnu-property.test
Modified:
llvm/include/llvm/BinaryFormat/ELF.h
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/test/tools/yaml2obj/ELF/program-header.yaml
llvm/tools/llvm-objdump/ELFDump.cpp
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h
index 46edfb6260be..caab91da9c83 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -1199,8 +1199,9 @@ enum {
PT_SUNW_EH_FRAME = 0x6474e550,
PT_SUNW_UNWIND = 0x6464e550,
- PT_GNU_STACK = 0x6474e551, // Indicates stack executability.
- PT_GNU_RELRO = 0x6474e552, // Read-only after relocation.
+ PT_GNU_STACK = 0x6474e551, // Indicates stack executability.
+ PT_GNU_RELRO = 0x6474e552, // Read-only after relocation.
+ PT_GNU_PROPERTY = 0x6474e553, // .note.gnu.property notes sections.
PT_OPENBSD_RANDOMIZE = 0x65a3dbe6, // Fill with random data.
PT_OPENBSD_WXNEEDED = 0x65a3dbe7, // Program does W^X violations.
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index 2a9d51486f6a..c8de7a662fc1 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -54,6 +54,7 @@ void ScalarEnumerationTraits<ELFYAML::ELF_PT>::enumeration(
ECase(PT_GNU_EH_FRAME);
ECase(PT_GNU_STACK);
ECase(PT_GNU_RELRO);
+ ECase(PT_GNU_PROPERTY);
#undef ECase
IO.enumFallback<Hex32>(Value);
}
diff --git a/llvm/test/tools/llvm-objdump/elf-pt-gnu-property.test b/llvm/test/tools/llvm-objdump/elf-pt-gnu-property.test
new file mode 100644
index 000000000000..246337866a77
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/elf-pt-gnu-property.test
@@ -0,0 +1,14 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-objdump -p %t | FileCheck %s
+
+# CHECK: Program Header:
+# CHECK-NEXT: {{ }}PROPERTY{{ }}
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_AARCH64
+ProgramHeaders:
+ - Type: PT_GNU_PROPERTY
diff --git a/llvm/test/tools/llvm-readobj/elf-pt-gnu-property.test b/llvm/test/tools/llvm-readobj/elf-pt-gnu-property.test
new file mode 100644
index 000000000000..f47341115b5c
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/elf-pt-gnu-property.test
@@ -0,0 +1,17 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-readelf --program-headers %t | FileCheck %s --check-prefix=GNU
+# RUN: llvm-readobj --program-headers %t | FileCheck %s --check-prefix=LLVM
+
+# GNU: {{ }}GNU_PROPERTY{{ }}
+
+# LLVM: ProgramHeader {
+# LLVM-NEXT: Type: PT_GNU_PROPERTY (0x6474E553)
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_AARCH64
+ProgramHeaders:
+ - Type: PT_GNU_PROPERTY
diff --git a/llvm/test/tools/yaml2obj/ELF/program-header.yaml b/llvm/test/tools/yaml2obj/ELF/program-header.yaml
index dbffafc465fa..c66b71cc7905 100644
--- a/llvm/test/tools/yaml2obj/ELF/program-header.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/program-header.yaml
@@ -40,6 +40,7 @@ ProgramHeaders:
- Type: PT_GNU_EH_FRAME
- Type: PT_GNU_STACK
- Type: PT_GNU_RELRO
+ - Type: PT_GNU_PROPERTY
#CHECK: ProgramHeaders [
#CHECK-NEXT: ProgramHeader {
@@ -76,6 +77,9 @@ ProgramHeaders:
#CHECK-NEXT: ProgramHeader {
#CHECK-NEXT: Type: PT_GNU_RELRO (0x6474E552)
#CHECK: }
+#CHECK-NEXT: ProgramHeader {
+#CHECK-NEXT: Type: PT_GNU_PROPERTY (0x6474E553)
+#CHECK: }
#CHECK-NEXT:]
## Check we do not allow referencing sections that do not exist.
diff --git a/llvm/tools/llvm-objdump/ELFDump.cpp b/llvm/tools/llvm-objdump/ELFDump.cpp
index 7ef16c187638..abfe08346bbd 100644
--- a/llvm/tools/llvm-objdump/ELFDump.cpp
+++ b/llvm/tools/llvm-objdump/ELFDump.cpp
@@ -204,6 +204,9 @@ template <class ELFT> void printProgramHeaders(const ELFFile<ELFT> *o) {
case ELF::PT_GNU_RELRO:
outs() << " RELRO ";
break;
+ case ELF::PT_GNU_PROPERTY:
+ outs() << " PROPERTY ";
+ break;
case ELF::PT_GNU_STACK:
outs() << " STACK ";
break;
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 8a9fd33c5168..122bc45084ad 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -1446,6 +1446,7 @@ static const char *getElfSegmentType(unsigned Arch, unsigned Type) {
LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_STACK);
LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_RELRO);
+ LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_PROPERTY);
LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_RANDOMIZE);
LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_WXNEEDED);
@@ -1470,6 +1471,7 @@ static std::string getElfPtType(unsigned Arch, unsigned Type) {
LLVM_READOBJ_PHDR_ENUM(ELF, PT_SUNW_UNWIND)
LLVM_READOBJ_PHDR_ENUM(ELF, PT_GNU_STACK)
LLVM_READOBJ_PHDR_ENUM(ELF, PT_GNU_RELRO)
+ LLVM_READOBJ_PHDR_ENUM(ELF, PT_GNU_PROPERTY)
default:
// All machine specific PT_* types
switch (Arch) {
More information about the llvm-commits
mailing list