diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h --- a/llvm/include/llvm/BinaryFormat/ELF.h +++ b/llvm/include/llvm/BinaryFormat/ELF.h @@ -1371,6 +1371,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. diff --git a/llvm/test/tools/llvm-readobj/ELF/program-headers.test b/llvm/test/tools/llvm-readobj/ELF/program-headers.test --- a/llvm/test/tools/llvm-readobj/ELF/program-headers.test +++ b/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,15 @@ # 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. diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/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.consume_front("PT_MIPS_")) return Seg.str(); + // E.g. "PT_RISCV_ATTRIBUTES" + if (Seg.consume_front("PT_RISCV_")) + return Seg.str(); + // E.g. "PT_LOAD" -> "LOAD". assert(Seg.startswith("PT_")); return Seg.drop_front(3).str();