[PATCH] D55298: [llvm-readelf] Add -e/--headers support to readobj/elf

Sid Manning via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 6 08:12:12 PST 2018


sidneym updated this revision to Diff 176979.
sidneym added a comment.

Updated the patch to include full context.

Added the contents of the header blocks to the test.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55298/new/

https://reviews.llvm.org/D55298

Files:
  test/tools/llvm-readobj/headers.test
  tools/llvm-readobj/llvm-readobj.cpp


Index: tools/llvm-readobj/llvm-readobj.cpp
===================================================================
--- tools/llvm-readobj/llvm-readobj.cpp
+++ tools/llvm-readobj/llvm-readobj.cpp
@@ -57,6 +57,14 @@
                    "--section-groups and --elf-hash-histogram."));
   cl::alias AllShort("a", cl::desc("Alias for --all"), cl::aliasopt(All));
 
+  // --headers -e
+  cl::opt<bool>
+      Headers("headers",
+          cl::desc("Equivalent to setting: --file-headers, --program-headers, "
+                   "--section-headers"));
+  cl::alias HeadersShort("e", cl::desc("Alias for --headers"),
+     cl::aliasopt(Headers));
+
   // -wide, -W
   cl::opt<bool>
       WideOutput("wide", cl::desc("Ignored for compatibility with GNU readelf"),
@@ -666,6 +674,12 @@
     opts::HashHistogram = true;
   }
 
+  if (opts::Headers) {
+    opts::FileHeaders = true;
+    opts::ProgramHeaders = true;
+    opts::SectionHeaders = true;
+  }
+
   // Default to stdin if no filename is specified.
   if (opts::InputFilenames.size() == 0)
     opts::InputFilenames.push_back("-");
Index: test/tools/llvm-readobj/headers.test
===================================================================
--- /dev/null
+++ test/tools/llvm-readobj/headers.test
@@ -0,0 +1,45 @@
+RUN: llvm-readelf -e %p/Inputs/trivial.obj.elf-i386 | FileCheck %s
+RUN: llvm-readelf --headers %p/Inputs/trivial.obj.elf-i386 | FileCheck %s
+RUN: llvm-readelf --headers %p/Inputs/trivial.obj.elf-i386 \
+RUN:   | FileCheck %s -check-prefix HEADERS
+
+CHECK: ELF Header:
+CHECK-NEXT:  Magic:   7f 45 4c 46 01 01 01 03 00 00 00 00 00 00 00 00
+CHECK-NEXT:  Class:                             ELF32
+CHECK-NEXT:  Data:                              2's complement, little endian
+CHECK-NEXT:  Version:                           1 (current)
+CHECK-NEXT:  OS/ABI:                            UNIX - GNU
+CHECK-NEXT:  ABI Version:                       0
+CHECK-NEXT:  Type:                              REL (Relocatable file)
+CHECK-NEXT:  Machine:                           Intel 80386
+CHECK-NEXT:  Version:                           0x1
+CHECK-NEXT:  Entry point address:               0x0
+CHECK-NEXT:  Start of program headers:          0 (bytes into file)
+CHECK-NEXT:  Start of section headers:          200 (bytes into file)
+CHECK-NEXT:  Flags:                             0x0
+CHECK-NEXT:  Size of this header:               52 (bytes)
+CHECK-NEXT:  Size of program headers:            0 (bytes)
+CHECK-NEXT:  Number of program headers:          0
+CHECK-NEXT:  Size of section headers:           40 (bytes)
+CHECK-NEXT:  Number of section headers:         10
+CHECK-NEXT:  Section header string table index: 7
+
+CHECK: Section Headers:
+CHECK-NEXT:  [Nr] Name              Type            Address  Off    Size   ES Flg Lk Inf Al
+CHECK-NEXT:  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
+CHECK-NEXT:  [ 1] .text             PROGBITS        00000000 000040 00002a 00  AX  0   0 16
+CHECK-NEXT:  [ 2] .rel.text         REL             00000000 000360 000020 08      8   1  4
+CHECK-NEXT:  [ 3] .data             PROGBITS        00000000 00006c 000000 00  WA  0   0  4
+CHECK-NEXT:  [ 4] .bss              NOBITS          00000000 00006c 000000 00  WA  0   0  4
+CHECK-NEXT:  [ 5] .rodata.str1.1    PROGBITS        00000000 00006c 00000d 01 AMS  0   0  1
+CHECK-NEXT:  [ 6] .note.GNU-stack   PROGBITS        00000000 000079 000000 00      0   0  1
+CHECK-NEXT:  [ 7] .shstrtab         STRTAB          00000000 000079 00004f 00      0   0  1
+CHECK-NEXT:  [ 8] .symtab           SYMTAB          00000000 000258 0000c0 10      9   8  4
+CHECK-NEXT:  [ 9] .strtab           STRTAB          00000000 000318 000045 00      0   0  1
+
+
+CHECK: Program Headers:
+CHECK-NEXT:  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
+
+HEADERS-NOT: Relocation section
+HEADERS-NOT: Symbol table


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55298.176979.patch
Type: text/x-patch
Size: 3906 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181206/f2a1a251/attachment.bin>


More information about the llvm-commits mailing list