[PATCH] D128493: [llvm-readobj][RISCV] Supporting dump PT_RISCV_ATTRIBUTES
luxufan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 23 22:28:00 PDT 2022
StephenFan created this revision.
StephenFan added reviewers: MaskRay, kito-cheng.
Herald added subscribers: sunshaoce, VincentWu, luke957, vkmr, evandro, luismarques, sameer.abuasal, s.egerton, Jim, benna, psnobl, rupprecht, PkmX, rogfer01, shiva0217, simoncook, arichardson, emaste.
Herald added a reviewer: jhenderson.
Herald added a project: All.
StephenFan requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, eopXD.
Herald added a project: LLVM.
For target specific program headers, we generally drop the `PT_xxxx_`
prefix. This patch also adopts this approach.
But it is weird that riscv gnu toolchain's readelf dumps `PT_RISCV_ATTRIBUTES`
as `RISCV_ATTRIBUT`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D128493
Files:
llvm/include/llvm/BinaryFormat/ELF.h
llvm/test/tools/llvm-readobj/ELF/program-headers.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -1390,6 +1390,8 @@
LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_ABIFLAGS);
}
break;
+ case ELF::EM_RISCV:
+ switch (Type) { LLVM_READOBJ_ENUM_CASE(ELF, PT_RISCV_ATTRIBUTES); }
}
switch (Type) {
@@ -1430,6 +1432,10 @@
if (Seg.startswith("PT_MIPS_"))
return Seg.drop_front(8).str();
+ // E.g. "PT_RISCV_ATTRIBUTES"
+ if (Seg.startswith("PT_RISCV_"))
+ return Seg.drop_front(9).str();
+
// E.g. "PT_LOAD" -> "LOAD".
assert(Seg.startswith("PT_"));
return Seg.drop_front(3).str();
Index: llvm/test/tools/llvm-readobj/ELF/program-headers.test
===================================================================
--- llvm/test/tools/llvm-readobj/ELF/program-headers.test
+++ llvm/test/tools/llvm-readobj/ELF/program-headers.test
@@ -554,8 +554,8 @@
VAddr: 0x1000
FirstSec: .foo.begin
LastSec: .foo.end
-## Case 21: the PT_MIPS_ABIFLAGS segment.
- - Type: 0x70000003 ## PT_MIPS_ABIFLAGS
+## Case 21: the PT_MIPS_ABIFLAGS/PT_RISCV_ATTRIBUTES segment.
+ - Type: 0x70000003 ## PT_MIPS_ABIFLAGS/PT_RISCV_ATTRIBUTES
VAddr: 0x1000
FirstSec: .foo.begin
LastSec: .foo.end
@@ -600,6 +600,16 @@
# MIPS-LLVM: ProgramHeader {
# MIPS-LLVM-NEXT: Type: PT_MIPS_ABIFLAGS (0x70000003)
+## CHECK how we dump RISCV specific program headers.
+# RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_RISCV %s -o %triscv.elf
+# RUN: llvm-readelf --program-headers %triscv.elf | FileCheck %s --check-prefix=RISCV-GNU
+# RUN: llvm-readobj --program-headers %triscv.elf | FileCheck %s --check-prefix=RISCV-LLVM
+
+# RISCV-GNU: ATTRIBUTES 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
+# RISCV-LLVM: ProgramHeader {
+# RISCV-LLVM: Type: PT_RISCV_ATTRIBUTES (0x70000003)
+
+
## Check that llvm-readelf reports a warning when a program interpreter
## name is non-null-terminated or when PT_INTERP has an offset that
## goes past the end of the file.
Index: llvm/include/llvm/BinaryFormat/ELF.h
===================================================================
--- llvm/include/llvm/BinaryFormat/ELF.h
+++ llvm/include/llvm/BinaryFormat/ELF.h
@@ -1368,6 +1368,9 @@
PT_MIPS_RTPROC = 0x70000001, // Runtime procedure table.
PT_MIPS_OPTIONS = 0x70000002, // Options segment.
PT_MIPS_ABIFLAGS = 0x70000003, // Abiflags segment.
+
+ // RISCV program header types.
+ PT_RISCV_ATTRIBUTES = 0x70000003,
};
// Segment flag bits.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128493.439621.patch
Type: text/x-patch
Size: 2644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220624/19a78075/attachment.bin>
More information about the llvm-commits
mailing list