[PATCH] llvm-readobj: COFF/ELF-specific low-level output

Nico Rieck nico.rieck at gmail.com
Fri Feb 15 15:01:30 PST 2013


This patch implements low-level object file format specific output for COFF and ELF with support for:
- File headers
- Section headers + data
- Relocations
- Symbols
- Unwind data (only COFF/Win64)
(Support for MachO is incomplete.)

Initially written as a separate private tool (mainly to support Win64 exception handling tests), llvm-readobj seems to be the right tool to merge this code in. I briefly talked with Micheal Spencer about it, and because the output format wasn't set in stone, this patch throws away the original condensed output for something that I feel is more practical for FileCheck-based tests.

The output format follows a few rules:
- Values are almost always output one per line (as elf-dump/coff-dump already do). - Many values are translated to something readable (like enum names), with the raw value in parentheses.
- Hex numbers are output in uppercase, prefixed with "0x".
- Flags are sorted alphabetically.
- Lists and groups are always delimited.

Example output:
---------- snip ----------
Sections [
  Section {
    Index: 1
    Name: .text (5)
    Type: SHT_PROGBITS (0x1)
    Flags [ (0x6)
      SHF_ALLOC (0x2)
      SHF_EXECINSTR (0x4)
    ]
    Address: 0x0
    Offset: 0x40
    Size: 33
    Link: 0
    Info: 0
    AddressAlignment: 16
    EntrySize: 0
    Relocations [
      0x6 R_386_32 .rodata.str1.1 0x0
      0xB R_386_PC32 puts 0x0
      0x12 R_386_32 .rodata.str1.1 0x0
      0x17 R_386_PC32 puts 0x0
    ]
    SectionData (
      0000: 83EC04C7 04240000 0000E8FC FFFFFFC7  |.....$..........|
      0010: 04240600 0000E8FC FFFFFF31 C083C404  |.$.........1....|
      0020: C3                                   |.|
    )
  }
]
---------- snip ----------

Relocations and symbols can be output standalone or together with the section header as displayed in the example.
This feature set supports all tests in test/MC/COFF and test/MC/ELF (and I suspect all additional tests using elf-dump), making elf-dump and coff-dump deprecated.
To test it, I updated the checks for all MC COFF/ELF tests, without touching the tests themselves (this greatly simplified relocation tests). If there's demand, and this patch is accepted, I can include these test changes in a follow-up patch.

Implementation notes:
I had to include a few small changes in llvm::object:
- Expose Elf_Ehdr (similar to coff_file_header)
- Implement ELFObjectFile<T>::sectionContainsSymbol
- Add a new COFF COMDAT flag
- Add const variants for a few methods in UnwindInfo (Win64EH)


http://llvm-reviews.chandlerc.com/D416

Files:
  include/llvm/Object/ELF.h
  include/llvm/Support/COFF.h
  include/llvm/Support/Win64EH.h
  tools/llvm-readobj/CMakeLists.txt
  tools/llvm-readobj/COFFDumper.cpp
  tools/llvm-readobj/ELFDumper.cpp
  tools/llvm-readobj/Error.cpp
  tools/llvm-readobj/Error.h
  tools/llvm-readobj/MachODumper.cpp
  tools/llvm-readobj/ObjDumper.cpp
  tools/llvm-readobj/ObjDumper.h
  tools/llvm-readobj/StreamWriter.cpp
  tools/llvm-readobj/StreamWriter.h
  tools/llvm-readobj/llvm-readobj.cpp
  tools/llvm-readobj/llvm-readobj.h
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D416.1.patch
Type: text/x-patch
Size: 111571 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130215/fc36c994/attachment.bin>


More information about the llvm-commits mailing list