[llvm] 41726f8 - [llvm-readobj] - Print "Unknown" when a program header is unknown.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 25 03:05:57 PDT 2020
Author: Georgii Rymar
Date: 2020-08-25T13:05:17+03:00
New Revision: 41726f8d5b24bc449b48d1d9e09523ee266cc5e4
URL: https://github.com/llvm/llvm-project/commit/41726f8d5b24bc449b48d1d9e09523ee266cc5e4
DIFF: https://github.com/llvm/llvm-project/commit/41726f8d5b24bc449b48d1d9e09523ee266cc5e4.diff
LOG: [llvm-readobj] - Print "Unknown" when a program header is unknown.
Currently, when a program header type is unknown, we dont print anything:
```
ProgramHeader {
Type: (0x60000000)
```
With this patch the output will be:
```
ProgramHeader {
Type: Unknown (0x60000000)
```
It was discussed in D85526 and consistent with what we print for
'--sections' already, e.g.:
```
Section {
Name: .sec
Type: Unknown (0x7FFFFFFF)
}
```
Differential revision: https://reviews.llvm.org/D86213
Added:
Modified:
lld/test/ELF/linkerscript/non-alloc-segment.s
lld/test/ELF/linkerscript/phdrs.s
llvm/test/tools/llvm-readobj/ELF/program-headers.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/lld/test/ELF/linkerscript/non-alloc-segment.s b/lld/test/ELF/linkerscript/non-alloc-segment.s
index 143cac1e2b12..f19ded3f17fd 100644
--- a/lld/test/ELF/linkerscript/non-alloc-segment.s
+++ b/lld/test/ELF/linkerscript/non-alloc-segment.s
@@ -29,7 +29,7 @@
# CHECK-NEXT: 00 .text
# CHECK-NEXT: 01 .foo
-# PHDR: Type: (0x12345678)
+# PHDR: Type: Unknown (0x12345678)
# PHDR-NEXT: Offset: 0x1004
# PHDR-NEXT: VirtualAddress
# PHDR-NEXT: PhysicalAddress
diff --git a/lld/test/ELF/linkerscript/phdrs.s b/lld/test/ELF/linkerscript/phdrs.s
index 2e9fcf23bf71..3e645f7919b7 100644
--- a/lld/test/ELF/linkerscript/phdrs.s
+++ b/lld/test/ELF/linkerscript/phdrs.s
@@ -99,7 +99,7 @@
# INT-PHDRS: ProgramHeaders [
# INT-PHDRS: ProgramHeader {
-# INT-PHDRS: Type: (0x11223344)
+# INT-PHDRS: Type: Unknown (0x11223344)
# INT-PHDRS-NEXT: Offset: 0xB0
# INT-PHDRS-NEXT: VirtualAddress: 0xB0
# INT-PHDRS-NEXT: PhysicalAddress: 0xB0
diff --git a/llvm/test/tools/llvm-readobj/ELF/program-headers.test b/llvm/test/tools/llvm-readobj/ELF/program-headers.test
index 74623b67edad..17fbaa8ce1d4 100644
--- a/llvm/test/tools/llvm-readobj/ELF/program-headers.test
+++ b/llvm/test/tools/llvm-readobj/ELF/program-headers.test
@@ -222,7 +222,7 @@
# ELF-LLVM-NEXT: Alignment: 1
# ELF-LLVM-NEXT: }
# ELF-LLVM-NEXT: ProgramHeader {
-# ELF-LLVM-NEXT: Type: (0x60000000)
+# ELF-LLVM-NEXT: Type: Unknown (0x60000000)
# ELF32-LLVM-NEXT: Offset: 0x314
# ELF64-LLVM-NEXT: Offset: 0x548
# ELF-LLVM-NEXT: VirtualAddress: 0x1000
@@ -330,7 +330,7 @@
# ELF-LLVM-NEXT: Alignment: 1
# ELF-LLVM-NEXT: }
# ELF-LLVM-NEXT: ProgramHeader {
-# ELF-LLVM-NEXT: Type: (0x6FFFFFFF)
+# ELF-LLVM-NEXT: Type: Unknown (0x6FFFFFFF)
# ELF32-LLVM-NEXT: Offset: 0x314
# ELF64-LLVM-NEXT: Offset: 0x548
# ELF-LLVM-NEXT: VirtualAddress: 0x1000
@@ -342,7 +342,7 @@
# ELF-LLVM-NEXT: Alignment: 1
# ELF-LLVM-NEXT: }
# ELF-LLVM-NEXT: ProgramHeader {
-# ELF-LLVM-NEXT: Type: (0x70000000)
+# ELF-LLVM-NEXT: Type: Unknown (0x70000000)
# ELF32-LLVM-NEXT: Offset: 0x314
# ELF64-LLVM-NEXT: Offset: 0x548
# ELF-LLVM-NEXT: VirtualAddress: 0x1000
@@ -354,7 +354,7 @@
# ELF-LLVM-NEXT: Alignment: 1
# ELF-LLVM-NEXT: }
# ELF-LLVM-NEXT: ProgramHeader {
-# ELF-LLVM-NEXT: Type: (0x70000001)
+# ELF-LLVM-NEXT: Type: Unknown (0x70000001)
# ELF32-LLVM-NEXT: Offset: 0x314
# ELF64-LLVM-NEXT: Offset: 0x548
# ELF-LLVM-NEXT: VirtualAddress: 0x1000
@@ -366,7 +366,7 @@
# ELF-LLVM-NEXT: Alignment: 1
# ELF-LLVM-NEXT: }
# ELF-LLVM-NEXT: ProgramHeader {
-# ELF-LLVM-NEXT: Type: (0x70000002)
+# ELF-LLVM-NEXT: Type: Unknown (0x70000002)
# ELF32-LLVM-NEXT: Offset: 0x314
# ELF64-LLVM-NEXT: Offset: 0x548
# ELF-LLVM-NEXT: VirtualAddress: 0x1000
@@ -378,7 +378,7 @@
# ELF-LLVM-NEXT: Alignment: 1
# ELF-LLVM-NEXT: }
# ELF-LLVM-NEXT: ProgramHeader {
-# ELF-LLVM-NEXT: Type: (0x70000003)
+# ELF-LLVM-NEXT: Type: Unknown (0x70000003)
# ELF32-LLVM-NEXT: Offset: 0x314
# ELF64-LLVM-NEXT: Offset: 0x548
# ELF-LLVM-NEXT: VirtualAddress: 0x1000
@@ -390,7 +390,7 @@
# ELF-LLVM-NEXT: Alignment: 1
# ELF-LLVM-NEXT: }
# ELF-LLVM-NEXT: ProgramHeader {
-# ELF-LLVM-NEXT: Type: (0x7FFFFFFF)
+# ELF-LLVM-NEXT: Type: Unknown (0x7FFFFFFF)
# ELF32-LLVM-NEXT: Offset: 0x314
# ELF64-LLVM-NEXT: Offset: 0x548
# ELF-LLVM-NEXT: VirtualAddress: 0x1000
@@ -596,11 +596,11 @@ ProgramHeaders:
# ARM-GNU-NEXT: <unknown>: 0x70000002 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
# ARM-LLVM: ProgramHeader {
-# ARM-LLVM: Type: (0x70000000)
+# ARM-LLVM: Type: Unknown (0x70000000)
# ARM-LLVM: ProgramHeader {
# ARM-LLVM-NEXT: Type: PT_ARM_EXIDX (0x70000001)
# ARM-LLVM: ProgramHeader {
-# ARM-LLVM-NEXT: Type: (0x70000002)
+# ARM-LLVM-NEXT: Type: Unknown (0x70000002)
## Check how we dump MIPS specific program headers.
# RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_MIPS %s -o %tmips.elf
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 748cd77bd71d..7b6781e70dc1 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -6524,9 +6524,10 @@ void LLVMStyle<ELFT>::printProgramHeaders(const ELFO *Obj) {
for (const Elf_Phdr &Phdr : *PhdrsOrErr) {
DictScope P(W, "ProgramHeader");
- W.printHex("Type",
- segmentTypeToString(Obj->getHeader()->e_machine, Phdr.p_type),
- Phdr.p_type);
+ StringRef Type =
+ segmentTypeToString(Obj->getHeader()->e_machine, Phdr.p_type);
+
+ W.printHex("Type", Type.empty() ? "Unknown" : Type, Phdr.p_type);
W.printHex("Offset", Phdr.p_offset);
W.printHex("VirtualAddress", Phdr.p_vaddr);
W.printHex("PhysicalAddress", Phdr.p_paddr);
More information about the llvm-commits
mailing list