[llvm] r192093 - [Mips] Teach llvm-readobj to print MIPS-specific ELF program headers.
Simon Atanasyan
simon at atanasyan.com
Mon Oct 7 01:58:28 PDT 2013
Author: atanasyan
Date: Mon Oct 7 03:58:27 2013
New Revision: 192093
URL: http://llvm.org/viewvc/llvm-project?rev=192093&view=rev
Log:
[Mips] Teach llvm-readobj to print MIPS-specific ELF program headers.
The patch reviewed by Michael Spencer.
http://llvm-reviews.chandlerc.com/D1846
Added:
llvm/trunk/test/Object/Inputs/program-headers.mips (with props)
Modified:
llvm/trunk/test/tools/llvm-readobj/program-headers.test
llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
Added: llvm/trunk/test/Object/Inputs/program-headers.mips
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/program-headers.mips?rev=192093&view=auto
==============================================================================
Binary files llvm/trunk/test/Object/Inputs/program-headers.mips (added) and llvm/trunk/test/Object/Inputs/program-headers.mips Mon Oct 7 03:58:27 2013 differ
Propchange: llvm/trunk/test/Object/Inputs/program-headers.mips
------------------------------------------------------------------------------
svn:executable = *
Modified: llvm/trunk/test/tools/llvm-readobj/program-headers.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/program-headers.test?rev=192093&r1=192092&r2=192093&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/program-headers.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/program-headers.test Mon Oct 7 03:58:27 2013
@@ -2,6 +2,8 @@ RUN: llvm-readobj -program-headers %p/..
RUN: | FileCheck %s -check-prefix ELF-I386
RUN: llvm-readobj -program-headers %p/../../Object/Inputs/program-headers.elf-x86-64 \
RUN: | FileCheck %s -check-prefix ELF-X86-64
+RUN: llvm-readobj -program-headers %p/../../Object/Inputs/program-headers.mips \
+RUN: | FileCheck %s -check-prefix ELF-MIPS
ELF-I386: ProgramHeaders [
ELF-I386-NEXT: ProgramHeader {
@@ -72,3 +74,31 @@ ELF-X86-64-NEXT: ]
ELF-X86-64-NEXT: Alignment: 8
ELF-X86-64-NEXT: }
ELF-X86-64-NEXT: ]
+
+ELF-MIPS: ProgramHeaders [
+ELF-MIPS-NEXT: ProgramHeader {
+ELF-MIPS-NEXT: Type: PT_MIPS_REGINFO (0x70000000)
+ELF-MIPS-NEXT: Offset: 0x74
+ELF-MIPS-NEXT: VirtualAddress: 0x400074
+ELF-MIPS-NEXT: PhysicalAddress: 0x400074
+ELF-MIPS-NEXT: FileSize: 24
+ELF-MIPS-NEXT: MemSize: 24
+ELF-MIPS-NEXT: Flags [ (0x4)
+ELF-MIPS-NEXT: PF_R (0x4)
+ELF-MIPS-NEXT: ]
+ELF-MIPS-NEXT: Alignment: 4
+ELF-MIPS-NEXT: }
+ELF-MIPS-NEXT: ProgramHeader {
+ELF-MIPS-NEXT: Type: PT_LOAD (0x1)
+ELF-MIPS-NEXT: Offset: 0x0
+ELF-MIPS-NEXT: VirtualAddress: 0x400000
+ELF-MIPS-NEXT: PhysicalAddress: 0x400000
+ELF-MIPS-NEXT: FileSize: 160
+ELF-MIPS-NEXT: MemSize: 160
+ELF-MIPS-NEXT: Flags [ (0x5)
+ELF-MIPS-NEXT: PF_R (0x4)
+ELF-MIPS-NEXT: PF_X (0x1)
+ELF-MIPS-NEXT: ]
+ELF-MIPS-NEXT: Alignment: 65536
+ELF-MIPS-NEXT: }
+ELF-MIPS-NEXT: ]
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=192093&r1=192092&r2=192093&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Mon Oct 7 03:58:27 2013
@@ -391,26 +391,41 @@ static const EnumEntry<unsigned> ElfSect
LLVM_READOBJ_ENUM_ENT(ELF, SHF_MIPS_NOSTRIP )
};
-static const EnumEntry<unsigned> ElfSegmentTypes[] = {
- LLVM_READOBJ_ENUM_ENT(ELF, PT_NULL ),
- LLVM_READOBJ_ENUM_ENT(ELF, PT_LOAD ),
- LLVM_READOBJ_ENUM_ENT(ELF, PT_DYNAMIC),
- LLVM_READOBJ_ENUM_ENT(ELF, PT_INTERP ),
- LLVM_READOBJ_ENUM_ENT(ELF, PT_NOTE ),
- LLVM_READOBJ_ENUM_ENT(ELF, PT_SHLIB ),
- LLVM_READOBJ_ENUM_ENT(ELF, PT_PHDR ),
- LLVM_READOBJ_ENUM_ENT(ELF, PT_TLS ),
-
- LLVM_READOBJ_ENUM_ENT(ELF, PT_GNU_EH_FRAME),
- LLVM_READOBJ_ENUM_ENT(ELF, PT_SUNW_EH_FRAME),
- LLVM_READOBJ_ENUM_ENT(ELF, PT_SUNW_UNWIND),
-
- LLVM_READOBJ_ENUM_ENT(ELF, PT_GNU_STACK),
- LLVM_READOBJ_ENUM_ENT(ELF, PT_GNU_RELRO),
+static const char *getElfSegmentType(unsigned Arch, unsigned Type) {
+ // Check potentially overlapped processor-specific
+ // program header type.
+ switch (Arch) {
+ case ELF::EM_ARM:
+ switch (Type) {
+ LLVM_READOBJ_ENUM_CASE(ELF, PT_ARM_EXIDX);
+ }
+ case ELF::EM_MIPS:
+ case ELF::EM_MIPS_RS3_LE:
+ switch (Type) {
+ LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_REGINFO);
+ LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_RTPROC);
+ LLVM_READOBJ_ENUM_CASE(ELF, PT_MIPS_OPTIONS);
+ }
+ }
- LLVM_READOBJ_ENUM_ENT(ELF, PT_ARM_EXIDX),
- LLVM_READOBJ_ENUM_ENT(ELF, PT_ARM_UNWIND)
-};
+ switch (Type) {
+ LLVM_READOBJ_ENUM_CASE(ELF, PT_NULL );
+ LLVM_READOBJ_ENUM_CASE(ELF, PT_LOAD );
+ LLVM_READOBJ_ENUM_CASE(ELF, PT_DYNAMIC);
+ LLVM_READOBJ_ENUM_CASE(ELF, PT_INTERP );
+ LLVM_READOBJ_ENUM_CASE(ELF, PT_NOTE );
+ LLVM_READOBJ_ENUM_CASE(ELF, PT_SHLIB );
+ LLVM_READOBJ_ENUM_CASE(ELF, PT_PHDR );
+ LLVM_READOBJ_ENUM_CASE(ELF, PT_TLS );
+
+ LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_EH_FRAME);
+ LLVM_READOBJ_ENUM_CASE(ELF, PT_SUNW_UNWIND);
+
+ LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_STACK);
+ LLVM_READOBJ_ENUM_CASE(ELF, PT_GNU_RELRO);
+ default: return "";
+ }
+}
static const EnumEntry<unsigned> ElfSegmentFlags[] = {
LLVM_READOBJ_ENUM_ENT(ELF, PF_X),
@@ -790,7 +805,9 @@ void ELFDumper<ELFT>::printProgramHeader
PE = Obj->end_program_headers();
PI != PE; ++PI) {
DictScope P(W, "ProgramHeader");
- W.printEnum ("Type", PI->p_type, makeArrayRef(ElfSegmentTypes));
+ W.printHex ("Type",
+ getElfSegmentType(Obj->getHeader()->e_machine, PI->p_type),
+ PI->p_type);
W.printHex ("Offset", PI->p_offset);
W.printHex ("VirtualAddress", PI->p_vaddr);
W.printHex ("PhysicalAddress", PI->p_paddr);
More information about the llvm-commits
mailing list