summaryrefslogtreecommitdiff
path: root/test/tools
diff options
context:
space:
mode:
authorEric Christopher <echristo@gmail.com>2013-04-03 18:31:38 +0000
committerEric Christopher <echristo@gmail.com>2013-04-03 18:31:38 +0000
commit76e70f340c09ba759ad96d8dfe416b64f24bc287 (patch)
treeac6cbe6235f9bf391026db87c52a0d617d35c9ba /test/tools
parent99ff2ba240979249b61514c1536bbe23be84ecc7 (diff)
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) 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. Patch by Nico Rieck! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178679 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tools')
-rw-r--r--test/tools/llvm-readobj/Inputs/trivial.ll19
-rw-r--r--test/tools/llvm-readobj/Inputs/trivial.obj.coff-i386bin0 -> 314 bytes
-rw-r--r--test/tools/llvm-readobj/Inputs/trivial.obj.coff-x86-64bin0 -> 319 bytes
-rw-r--r--test/tools/llvm-readobj/Inputs/trivial.obj.elf-i386bin0 -> 896 bytes
-rw-r--r--test/tools/llvm-readobj/Inputs/trivial.obj.elf-x86-64bin0 -> 1256 bytes
-rw-r--r--test/tools/llvm-readobj/Inputs/trivial.obj.macho-i386bin0 -> 472 bytes
-rw-r--r--test/tools/llvm-readobj/Inputs/trivial.obj.macho-x86-64bin0 -> 532 bytes
-rw-r--r--test/tools/llvm-readobj/file-headers.test100
-rw-r--r--test/tools/llvm-readobj/lit.local.cfg1
-rw-r--r--test/tools/llvm-readobj/relocations.test32
-rw-r--r--test/tools/llvm-readobj/sections-ext.test175
-rw-r--r--test/tools/llvm-readobj/sections.test113
-rw-r--r--test/tools/llvm-readobj/symbols.test44
13 files changed, 484 insertions, 0 deletions
diff --git a/test/tools/llvm-readobj/Inputs/trivial.ll b/test/tools/llvm-readobj/Inputs/trivial.ll
new file mode 100644
index 0000000000..2cd7ec89e2
--- /dev/null
+++ b/test/tools/llvm-readobj/Inputs/trivial.ll
@@ -0,0 +1,19 @@
+; llc -mtriple=i386-pc-win32 trivial.ll -filetype=obj -o trivial-object-test.coff-i386
+; llc -mtriple=x86_64-pc-win32 trivial.ll -filetype=obj -o trivial-object-test.coff-x86-64
+; llc -mtriple=i386-linux-gnu trivial.ll -filetype=obj -o trivial-object-test.elf-i386 -relocation-model=pic
+; llc -mtriple=x86_64-linux-gnu trivial.ll -filetype=obj -o trivial-object-test.elf-x86-64 -relocation-model=pic
+; llc -mtriple=i386-apple-darwin10 trivial.ll -filetype=obj -o trivial-object-test.macho-i386 -relocation-model=pic
+; llc -mtriple=x86_64-apple-darwin10 trivial.ll -filetype=obj -o trivial-object-test.macho-x86-64 -relocation-model=pic
+
+@.str = private unnamed_addr constant [13 x i8] c"Hello World\0A\00", align 1
+
+define i32 @main() nounwind {
+entry:
+ %call = tail call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @.str, i32 0, i32 0)) nounwind
+ tail call void bitcast (void (...)* @SomeOtherFunction to void ()*)() nounwind
+ ret i32 0
+}
+
+declare i32 @puts(i8* nocapture) nounwind
+
+declare void @SomeOtherFunction(...)
diff --git a/test/tools/llvm-readobj/Inputs/trivial.obj.coff-i386 b/test/tools/llvm-readobj/Inputs/trivial.obj.coff-i386
new file mode 100644
index 0000000000..282e5699a7
--- /dev/null
+++ b/test/tools/llvm-readobj/Inputs/trivial.obj.coff-i386
Binary files differ
diff --git a/test/tools/llvm-readobj/Inputs/trivial.obj.coff-x86-64 b/test/tools/llvm-readobj/Inputs/trivial.obj.coff-x86-64
new file mode 100644
index 0000000000..8a7060e610
--- /dev/null
+++ b/test/tools/llvm-readobj/Inputs/trivial.obj.coff-x86-64
Binary files differ
diff --git a/test/tools/llvm-readobj/Inputs/trivial.obj.elf-i386 b/test/tools/llvm-readobj/Inputs/trivial.obj.elf-i386
new file mode 100644
index 0000000000..f85e40d626
--- /dev/null
+++ b/test/tools/llvm-readobj/Inputs/trivial.obj.elf-i386
Binary files differ
diff --git a/test/tools/llvm-readobj/Inputs/trivial.obj.elf-x86-64 b/test/tools/llvm-readobj/Inputs/trivial.obj.elf-x86-64
new file mode 100644
index 0000000000..95285c1f23
--- /dev/null
+++ b/test/tools/llvm-readobj/Inputs/trivial.obj.elf-x86-64
Binary files differ
diff --git a/test/tools/llvm-readobj/Inputs/trivial.obj.macho-i386 b/test/tools/llvm-readobj/Inputs/trivial.obj.macho-i386
new file mode 100644
index 0000000000..5048171ccb
--- /dev/null
+++ b/test/tools/llvm-readobj/Inputs/trivial.obj.macho-i386
Binary files differ
diff --git a/test/tools/llvm-readobj/Inputs/trivial.obj.macho-x86-64 b/test/tools/llvm-readobj/Inputs/trivial.obj.macho-x86-64
new file mode 100644
index 0000000000..bcdfc8aa69
--- /dev/null
+++ b/test/tools/llvm-readobj/Inputs/trivial.obj.macho-x86-64
Binary files differ
diff --git a/test/tools/llvm-readobj/file-headers.test b/test/tools/llvm-readobj/file-headers.test
new file mode 100644
index 0000000000..226eb93423
--- /dev/null
+++ b/test/tools/llvm-readobj/file-headers.test
@@ -0,0 +1,100 @@
+RUN: llvm-readobj -h %p/Inputs/trivial.obj.coff-i386 \
+RUN: | FileCheck %s -check-prefix COFF32
+RUN: llvm-readobj -h %p/Inputs/trivial.obj.coff-x86-64 \
+RUN: | FileCheck %s -check-prefix COFF64
+RUN: llvm-readobj -h %p/Inputs/trivial.obj.elf-i386 \
+RUN: | FileCheck %s -check-prefix ELF32
+RUN: llvm-readobj -h %p/Inputs/trivial.obj.elf-x86-64 \
+RUN: | FileCheck %s -check-prefix ELF64
+
+COFF32: File: {{(.*[/\\])?}}trivial.obj.coff-i386
+COFF32-NEXT: Format: COFF-i386
+COFF32-NEXT: Arch: i386
+COFF32-NEXT: AddressSize: 32bit
+COFF32-NEXT: ImageFileHeader {
+COFF32-NEXT: Machine: IMAGE_FILE_MACHINE_I386 (0x14C)
+COFF32-NEXT: SectionCount: 2
+COFF32-NEXT: TimeDateStamp: 2013-03-20 17:56:46 (0x5149F85E)
+COFF32-NEXT: PointerToSymbolTable: 0xA5
+COFF32-NEXT: SymbolCount: 7
+COFF32-NEXT: OptionalHeaderSize: 0
+COFF32-NEXT: Characteristics [ (0x0)
+COFF32-NEXT: ]
+COFF32-NEXT: }
+
+COFF64: File: {{(.*[/\\])?}}trivial.obj.coff-x86-64
+COFF64-NEXT: Format: COFF-x86-64
+COFF64-NEXT: Arch: x86_64
+COFF64-NEXT: AddressSize: 64bit
+COFF64-NEXT: ImageFileHeader {
+COFF64-NEXT: Machine: IMAGE_FILE_MACHINE_AMD64 (0x8664)
+COFF64-NEXT: SectionCount: 2
+COFF64-NEXT: TimeDateStamp: 2013-03-20 17:56:46 (0x5149F85E)
+COFF64-NEXT: PointerToSymbolTable: 0xAB
+COFF64-NEXT: SymbolCount: 7
+COFF64-NEXT: OptionalHeaderSize: 0
+COFF64-NEXT: Characteristics [ (0x0)
+COFF64-NEXT: ]
+COFF64-NEXT: }
+
+ELF32: File: {{(.*[/\\])?}}trivial.obj.elf-i386
+ELF32-NEXT: Format: ELF32-i386
+ELF32-NEXT: Arch: i386
+ELF32-NEXT: AddressSize: 32bit
+ELF32-NEXT: LoadName:
+ELF32-NEXT: ElfHeader {
+ELF32-NEXT: Ident {
+ELF32-NEXT: Magic: (7F 45 4C 46)
+ELF32-NEXT: Class: 32-bit (0x1)
+ELF32-NEXT: DataEncoding: LittleEndian (0x1)
+ELF32-NEXT: FileVersion: 1
+ELF32-NEXT: OS/ABI: GNU/Linux (0x3)
+ELF32-NEXT: ABIVersion: 0
+ELF32-NEXT: Unused: (00 00 00 00 00 00 00)
+ELF32-NEXT: }
+ELF32-NEXT: Type: Relocatable (0x1)
+ELF32-NEXT: Machine: EM_386 (0x3)
+ELF32-NEXT: Version: 1
+ELF32-NEXT: Entry: 0x0
+ELF32-NEXT: ProgramHeaderOffset: 0x0
+ELF32-NEXT: SectionHeaderOffset: 0xC8
+ELF32-NEXT: Flags [ (0x0)
+ELF32-NEXT: ]
+ELF32-NEXT: HeaderSize: 52
+ELF32-NEXT: ProgramHeaderEntrySize: 0
+ELF32-NEXT: ProgramHeaderCount: 0
+ELF32-NEXT: SectionHeaderEntrySize: 40
+ELF32-NEXT: SectionHeaderCount: 10
+ELF32-NEXT: StringTableSectionIndex: 7
+ELF32-NEXT: }
+
+ELF64: File: {{(.*[/\\])?}}trivial.obj.elf-x86-64
+ELF64-NEXT: Format: ELF64-x86-64
+ELF64-NEXT: Arch: x86_64
+ELF64-NEXT: AddressSize: 64bit
+ELF64-NEXT: LoadName:
+ELF64-NEXT: ElfHeader {
+ELF64-NEXT: Ident {
+ELF64-NEXT: Magic: (7F 45 4C 46)
+ELF64-NEXT: Class: 64-bit (0x2)
+ELF64-NEXT: DataEncoding: LittleEndian (0x1)
+ELF64-NEXT: FileVersion: 1
+ELF64-NEXT: OS/ABI: GNU/Linux (0x3)
+ELF64-NEXT: ABIVersion: 0
+ELF64-NEXT: Unused: (00 00 00 00 00 00 00)
+ELF64-NEXT: }
+ELF64-NEXT: Type: Relocatable (0x1)
+ELF64-NEXT: Machine: EM_X86_64 (0x3E)
+ELF64-NEXT: Version: 1
+ELF64-NEXT: Entry: 0x0
+ELF64-NEXT: ProgramHeaderOffset: 0x0
+ELF64-NEXT: SectionHeaderOffset: 0xB8
+ELF64-NEXT: Flags [ (0x0)
+ELF64-NEXT: ]
+ELF64-NEXT: HeaderSize: 64
+ELF64-NEXT: ProgramHeaderEntrySize: 0
+ELF64-NEXT: ProgramHeaderCount: 0
+ELF64-NEXT: SectionHeaderEntrySize: 64
+ELF64-NEXT: SectionHeaderCount: 10
+ELF64-NEXT: StringTableSectionIndex: 7
+ELF64-NEXT: }
diff --git a/test/tools/llvm-readobj/lit.local.cfg b/test/tools/llvm-readobj/lit.local.cfg
new file mode 100644
index 0000000000..df9b335dd1
--- /dev/null
+++ b/test/tools/llvm-readobj/lit.local.cfg
@@ -0,0 +1 @@
+config.suffixes = ['.test']
diff --git a/test/tools/llvm-readobj/relocations.test b/test/tools/llvm-readobj/relocations.test
new file mode 100644
index 0000000000..0608565373
--- /dev/null
+++ b/test/tools/llvm-readobj/relocations.test
@@ -0,0 +1,32 @@
+RUN: llvm-readobj -r %p/Inputs/trivial.obj.coff-i386 \
+RUN: | FileCheck %s -check-prefix COFF
+RUN: llvm-readobj -r %p/Inputs/trivial.obj.elf-i386 \
+RUN: | FileCheck %s -check-prefix ELF
+RUN: llvm-readobj -r %p/Inputs/trivial.obj.macho-i386 \
+RUN: | FileCheck %s -check-prefix MACHO
+
+COFF: Relocations [
+COFF-NEXT: Section (1) .text {
+COFF-NEXT: 0x4 IMAGE_REL_I386_DIR32 .data
+COFF-NEXT: 0x9 IMAGE_REL_I386_REL32 _puts
+COFF-NEXT: 0xE IMAGE_REL_I386_REL32 _SomeOtherFunction
+COFF-NEXT: }
+COFF-NEXT: ]
+
+ELF: Relocations [
+ELF-NEXT: Section (1) .text {
+ELF-NEXT: 0xC R_386_GOTPC _GLOBAL_OFFSET_TABLE_ 0x0
+ELF-NEXT: 0x12 R_386_GOTOFF .L.str 0x0
+ELF-NEXT: 0x1A R_386_PLT32 puts 0x0
+ELF-NEXT: 0x1F R_386_PLT32 SomeOtherFunction 0x0
+ELF-NEXT: }
+ELF-NEXT: ]
+
+MACHO: Relocations [
+MACHO-NEXT: Section __text {
+MACHO-NEXT: 0x18 GENERIC_RELOC_VANILLA _SomeOtherFunction 0x0
+MACHO-NEXT: 0x13 GENERIC_RELOC_VANILLA _puts 0x0
+MACHO-NEXT: 0xB GENERIC_RELOC_LOCAL_SECTDIFF _main 0x{{[0-9A-F]+}}
+MACHO-NEXT: 0x0 GENERIC_RELOC_PAIR _main 0x{{[0-9A-F]+}}
+MACHO-NEXT: }
+MACHO-NEXT: ]
diff --git a/test/tools/llvm-readobj/sections-ext.test b/test/tools/llvm-readobj/sections-ext.test
new file mode 100644
index 0000000000..a972c9ab51
--- /dev/null
+++ b/test/tools/llvm-readobj/sections-ext.test
@@ -0,0 +1,175 @@
+RUN: llvm-readobj -s -st -sr -sd %p/Inputs/trivial.obj.coff-i386 \
+RUN: | FileCheck %s -check-prefix COFF
+RUN: llvm-readobj -s -st -sr -sd %p/Inputs/trivial.obj.elf-i386 \
+RUN: | FileCheck %s -check-prefix ELF
+RUN: llvm-readobj -s -st -sr -sd %p/Inputs/trivial.obj.macho-i386 \
+RUN: | FileCheck %s -check-prefix MACHO
+
+COFF: Sections [
+COFF-NEXT: Section {
+COFF-NEXT: Number: 1
+COFF-NEXT: Name: .text (2E 74 65 78 74 00 00 00)
+COFF-NEXT: VirtualSize: 0x0
+COFF-NEXT: VirtualAddress: 0x0
+COFF-NEXT: RawDataSize: 22
+COFF-NEXT: PointerToRawData: 0x64
+COFF-NEXT: PointerToRelocations: 0x7A
+COFF-NEXT: PointerToLineNumbers: 0x0
+COFF-NEXT: RelocationCount: 3
+COFF-NEXT: LineNumberCount: 0
+COFF-NEXT: Characteristics [ (0x60500020)
+COFF-NEXT: IMAGE_SCN_ALIGN_16BYTES (0x500000)
+COFF-NEXT: IMAGE_SCN_CNT_CODE (0x20)
+COFF-NEXT: IMAGE_SCN_MEM_EXECUTE (0x20000000)
+COFF-NEXT: IMAGE_SCN_MEM_READ (0x40000000)
+COFF-NEXT: ]
+COFF-NEXT: Relocations [
+COFF-NEXT: 0x4 IMAGE_REL_I386_DIR32 .data
+COFF-NEXT: 0x9 IMAGE_REL_I386_REL32 _puts
+COFF-NEXT: 0xE IMAGE_REL_I386_REL32 _SomeOtherFunction
+COFF-NEXT: ]
+COFF-NEXT: Symbols [
+COFF-NEXT: Symbol {
+COFF-NEXT: Name: .text
+COFF-NEXT: Value: 0
+COFF-NEXT: Section: .text (1)
+COFF-NEXT: BaseType: Null (0x0)
+COFF-NEXT: ComplexType: Null (0x0)
+COFF-NEXT: StorageClass: Static (0x3)
+COFF-NEXT: AuxSymbolCount: 1
+COFF-NEXT: AuxSectionDef {
+COFF-NEXT: Length: 22
+COFF-NEXT: RelocationCount: 3
+COFF-NEXT: LineNumberCount: 0
+COFF-NEXT: Checksum: 0x0
+COFF-NEXT: Number: 1
+COFF-NEXT: Selection: 0x0
+COFF-NEXT: Unused: (00 00 00)
+COFF-NEXT: }
+COFF-NEXT: }
+COFF-NEXT: Symbol {
+COFF-NEXT: Name: _main
+COFF-NEXT: Value: 0
+COFF-NEXT: Section: .text (1)
+COFF-NEXT: BaseType: Null (0x0)
+COFF-NEXT: ComplexType: Function (0x2)
+COFF-NEXT: StorageClass: External (0x2)
+COFF-NEXT: AuxSymbolCount: 0
+COFF-NEXT: }
+COFF-NEXT: ]
+COFF-NEXT: SectionData (
+COFF-NEXT: 0000: 50C70424 00000000 E8000000 00E80000 |P..$............|
+COFF-NEXT: 0010: 000031C0 5AC3 |..1.Z.|
+COFF-NEXT: )
+COFF-NEXT: }
+
+ELF: Sections [
+ELF-NEXT: Section {
+ELF-NEXT: Index: 0
+ELF-NEXT: Name: (0)
+ELF-NEXT: Type: SHT_NULL (0x0)
+ELF-NEXT: Flags [ (0x0)
+ELF-NEXT: ]
+ELF-NEXT: Address: 0x0
+ELF-NEXT: Offset: 0x0
+ELF-NEXT: Size: 0
+ELF-NEXT: Link: 0
+ELF-NEXT: Info: 0
+ELF-NEXT: AddressAlignment: 0
+ELF-NEXT: EntrySize: 0
+ELF-NEXT: Relocations [
+ELF-NEXT: ]
+ELF-NEXT: Symbols [
+ELF-NEXT: ]
+ELF-NEXT: SectionData (
+ELF-NEXT: )
+ELF-NEXT: }
+ELF-NEXT: Section {
+ELF-NEXT: Index: 1
+ELF-NEXT: Name: .text (5)
+ELF-NEXT: Type: SHT_PROGBITS (0x1)
+ELF-NEXT: Flags [ (0x6)
+ELF-NEXT: SHF_ALLOC (0x2)
+ELF-NEXT: SHF_EXECINSTR (0x4)
+ELF-NEXT: ]
+ELF-NEXT: Address: 0x0
+ELF-NEXT: Offset: 0x40
+ELF-NEXT: Size: 42
+ELF-NEXT: Link: 0
+ELF-NEXT: Info: 0
+ELF-NEXT: AddressAlignment: 16
+ELF-NEXT: EntrySize: 0
+ELF-NEXT: Relocations [
+ELF-NEXT: 0xC R_386_GOTPC _GLOBAL_OFFSET_TABLE_ 0x0
+ELF-NEXT: 0x12 R_386_GOTOFF .L.str 0x0
+ELF-NEXT: 0x1A R_386_PLT32 puts 0x0
+ELF-NEXT: 0x1F R_386_PLT32 SomeOtherFunction 0x0
+ELF-NEXT: ]
+ELF-NEXT: Symbols [
+ELF-NEXT: Symbol {
+ELF-NEXT: Name: .text (0)
+ELF-NEXT: Value: 0x0
+ELF-NEXT: Size: 0
+ELF-NEXT: Binding: Local (0x0)
+ELF-NEXT: Type: Section (0x3)
+ELF-NEXT: Other: 0
+ELF-NEXT: Section: .text (0x1)
+ELF-NEXT: }
+ELF-NEXT: Symbol {
+ELF-NEXT: Name: main (12)
+ELF-NEXT: Value: 0x0
+ELF-NEXT: Size: 42
+ELF-NEXT: Binding: Global (0x1)
+ELF-NEXT: Type: Function (0x2)
+ELF-NEXT: Other: 0
+ELF-NEXT: Section: .text (0x1)
+ELF-NEXT: }
+ELF-NEXT: ]
+ELF-NEXT: SectionData (
+ELF-NEXT: 0000: 5383EC08 E8000000 005B81C3 03000000 |S........[......|
+ELF-NEXT: 0010: 8D830000 00008904 24E8FCFF FFFFE8FC |........$.......|
+ELF-NEXT: 0020: FFFFFF31 C083C408 5BC3 |...1....[.|
+ELF-NEXT: )
+ELF-NEXT: }
+
+MACHO: Sections [
+MACHO-NEXT: Section {
+MACHO-NEXT: Index: 0
+MACHO-NEXT: Name: __text (5F 5F 74 65 78 74 00 00 00 00 00 00 00 00 00 00)
+MACHO-NEXT: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
+MACHO-NEXT: Address: 0x0
+MACHO-NEXT: Size: 0x22
+MACHO-NEXT: Offset: 324
+MACHO-NEXT: Alignment: 4
+MACHO-NEXT: RelocationOffset: 0x174
+MACHO-NEXT: RelocationCount: 4
+MACHO-NEXT: Type: 0x0
+MACHO-NEXT: Attributes [ (0x800004)
+MACHO-NEXT: PureInstructions (0x800000)
+MACHO-NEXT: SomeInstructions (0x4)
+MACHO-NEXT: ]
+MACHO-NEXT: Reserved1: 0x0
+MACHO-NEXT: Reserved2: 0x0
+MACHO-NEXT: Relocations [
+MACHO-NEXT: 0x18 GENERIC_RELOC_VANILLA _SomeOtherFunction 0x0
+MACHO-NEXT: 0x13 GENERIC_RELOC_VANILLA _puts 0x0
+MACHO-NEXT: 0xB GENERIC_RELOC_LOCAL_SECTDIFF _main 0x{{[0-9A-F]+}}
+MACHO-NEXT: 0x0 GENERIC_RELOC_PAIR _main 0x{{[0-9A-F]+}}
+MACHO-NEXT: ]
+MACHO-NEXT: Symbols [
+MACHO-NEXT: Symbol {
+MACHO-NEXT: Name: _main (1)
+MACHO-NEXT: Type: 0xF
+MACHO-NEXT: Section: __text (0x1)
+MACHO-NEXT: RefType: UndefinedNonLazy (0x0)
+MACHO-NEXT: Flags [ (0x0)
+MACHO-NEXT: ]
+MACHO-NEXT: Value: 0x0
+MACHO-NEXT: }
+MACHO-NEXT: ]
+MACHO-NEXT: SectionData (
+MACHO-NEXT: 0000: 83EC0CE8 00000000 588D801A 00000089 |........X.......|
+MACHO-NEXT: 0010: 0424E8E9 FFFFFFE8 E4FFFFFF 31C083C4 |.$..........1...|
+MACHO-NEXT: 0020: 0CC3 |..|
+MACHO-NEXT: )
+MACHO-NEXT: }
diff --git a/test/tools/llvm-readobj/sections.test b/test/tools/llvm-readobj/sections.test
new file mode 100644
index 0000000000..84154d759c
--- /dev/null
+++ b/test/tools/llvm-readobj/sections.test
@@ -0,0 +1,113 @@
+RUN: llvm-readobj -s %p/Inputs/trivial.obj.coff-i386 \
+RUN: | FileCheck %s -check-prefix COFF
+RUN: llvm-readobj -s %p/Inputs/trivial.obj.elf-i386 \
+RUN: | FileCheck %s -check-prefix ELF
+RUN: llvm-readobj -s %p/Inputs/trivial.obj.macho-i386 \
+RUN: | FileCheck %s -check-prefix MACHO
+
+COFF: Sections [
+COFF-NEXT: Section {
+COFF-NEXT: Number: 1
+COFF-NEXT: Name: .text (2E 74 65 78 74 00 00 00)
+COFF-NEXT: VirtualSize: 0x0
+COFF-NEXT: VirtualAddress: 0x0
+COFF-NEXT: RawDataSize: 22
+COFF-NEXT: PointerToRawData: 0x64
+COFF-NEXT: PointerToRelocations: 0x7A
+COFF-NEXT: PointerToLineNumbers: 0x0
+COFF-NEXT: RelocationCount: 3
+COFF-NEXT: LineNumberCount: 0
+COFF-NEXT: Characteristics [ (0x60500020)
+COFF-NEXT: IMAGE_SCN_ALIGN_16BYTES (0x500000)
+COFF-NEXT: IMAGE_SCN_CNT_CODE (0x20)
+COFF-NEXT: IMAGE_SCN_MEM_EXECUTE (0x20000000)
+COFF-NEXT: IMAGE_SCN_MEM_READ (0x40000000)
+COFF-NEXT: ]
+COFF-NEXT: }
+COFF-NEXT: Section {
+COFF-NEXT: Number: 2
+COFF-NEXT: Name: .data (2E 64 61 74 61 00 00 00)
+COFF-NEXT: VirtualSize: 0x0
+COFF-NEXT: VirtualAddress: 0x0
+COFF-NEXT: RawDataSize: 13
+COFF-NEXT: PointerToRawData: 0x98
+COFF-NEXT: PointerToRelocations: 0x0
+COFF-NEXT: PointerToLineNumbers: 0x0
+COFF-NEXT: RelocationCount: 0
+COFF-NEXT: LineNumberCount: 0
+COFF-NEXT: Characteristics [ (0xC0300040)
+COFF-NEXT: IMAGE_SCN_ALIGN_4BYTES (0x300000)
+COFF-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40)
+COFF-NEXT: IMAGE_SCN_MEM_READ (0x40000000)
+COFF-NEXT: IMAGE_SCN_MEM_WRITE (0x80000000)
+COFF-NEXT: ]
+COFF-NEXT: }
+COFF-NEXT: ]
+
+ELF: Sections [
+ELF-NEXT: Section {
+ELF-NEXT: Index: 0
+ELF-NEXT: Name: (0)
+ELF-NEXT: Type: SHT_NULL (0x0)
+ELF-NEXT: Flags [ (0x0)
+ELF-NEXT: ]
+ELF-NEXT: Address: 0x0
+ELF-NEXT: Offset: 0x0
+ELF-NEXT: Size: 0
+ELF-NEXT: Link: 0
+ELF-NEXT: Info: 0
+ELF-NEXT: AddressAlignment: 0
+ELF-NEXT: EntrySize: 0
+ELF-NEXT: }
+ELF-NEXT: Section {
+ELF-NEXT: Index: 1
+ELF-NEXT: Name: .text (5)
+ELF-NEXT: Type: SHT_PROGBITS (0x1)
+ELF-NEXT: Flags [ (0x6)
+ELF-NEXT: SHF_ALLOC (0x2)
+ELF-NEXT: SHF_EXECINSTR (0x4)
+ELF-NEXT: ]
+ELF-NEXT: Address: 0x0
+ELF-NEXT: Offset: 0x40
+ELF-NEXT: Size: 42
+ELF-NEXT: Link: 0
+ELF-NEXT: Info: 0
+ELF-NEXT: AddressAlignment: 16
+ELF-NEXT: EntrySize: 0
+ELF-NEXT: }
+
+MACHO: Sections [
+MACHO-NEXT: Section {
+MACHO-NEXT: Index: 0
+MACHO-NEXT: Name: __text (5F 5F 74 65 78 74 00 00 00 00 00 00 00 00 00 00)
+MACHO-NEXT: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
+MACHO-NEXT: Address: 0x0
+MACHO-NEXT: Size: 0x22
+MACHO-NEXT: Offset: 324
+MACHO-NEXT: Alignment: 4
+MACHO-NEXT: RelocationOffset: 0x174
+MACHO-NEXT: RelocationCount: 4
+MACHO-NEXT: Type: 0x0
+MACHO-NEXT: Attributes [ (0x800004)
+MACHO-NEXT: PureInstructions (0x800000)
+MACHO-NEXT: SomeInstructions (0x4)
+MACHO-NEXT: ]
+MACHO-NEXT: Reserved1: 0x0
+MACHO-NEXT: Reserved2: 0x0
+MACHO-NEXT: }
+MACHO-NEXT: Section {
+MACHO-NEXT: Index: 1
+MACHO-NEXT: Name: __cstring (5F 5F 63 73 74 72 69 6E 67 00 00 00 00 00 00 00)
+MACHO-NEXT: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
+MACHO-NEXT: Address: 0x22
+MACHO-NEXT: Size: 0xD
+MACHO-NEXT: Offset: 358
+MACHO-NEXT: Alignment: 0
+MACHO-NEXT: RelocationOffset: 0x0
+MACHO-NEXT: RelocationCount: 0
+MACHO-NEXT: Type: ExtReloc (0x2)
+MACHO-NEXT: Attributes [ (0x0)
+MACHO-NEXT: ]
+MACHO-NEXT: Reserved1: 0x0
+MACHO-NEXT: Reserved2: 0x0
+MACHO-NEXT: }
diff --git a/test/tools/llvm-readobj/symbols.test b/test/tools/llvm-readobj/symbols.test
new file mode 100644
index 0000000000..d33bd8ed2c
--- /dev/null
+++ b/test/tools/llvm-readobj/symbols.test
@@ -0,0 +1,44 @@
+RUN: llvm-readobj -t %p/Inputs/trivial.obj.coff-i386 \
+RUN: | FileCheck %s -check-prefix COFF
+RUN: llvm-readobj -t %p/Inputs/trivial.obj.elf-i386 \
+RUN: | FileCheck %s -check-prefix ELF
+
+COFF: Symbols [
+COFF-NEXT: Symbol {
+COFF-NEXT: Name: .text
+COFF-NEXT: Value: 0
+COFF-NEXT: Section: .text (1)
+COFF-NEXT: BaseType: Null (0x0)
+COFF-NEXT: ComplexType: Null (0x0)
+COFF-NEXT: StorageClass: Static (0x3)
+COFF-NEXT: AuxSymbolCount: 1
+COFF-NEXT: AuxSectionDef {
+COFF-NEXT: Length: 22
+COFF-NEXT: RelocationCount: 3
+COFF-NEXT: LineNumberCount: 0
+COFF-NEXT: Checksum: 0x0
+COFF-NEXT: Number: 1
+COFF-NEXT: Selection: 0x0
+COFF-NEXT: Unused: (00 00 00)
+COFF-NEXT: }
+COFF-NEXT: }
+
+ELF: Symbols [
+ELF-NEXT: Symbol {
+ELF-NEXT: Name: trivial.ll (1)
+ELF-NEXT: Value: 0x0
+ELF-NEXT: Size: 0
+ELF-NEXT: Binding: Local (0x0)
+ELF-NEXT: Type: File (0x4)
+ELF-NEXT: Other: 0
+ELF-NEXT: Section: (0xFFF1)
+ELF-NEXT: }
+ELF-NEXT: Symbol {
+ELF-NEXT: Name: .L.str (39)
+ELF-NEXT: Value: 0x0
+ELF-NEXT: Size: 13
+ELF-NEXT: Binding: Local (0x0)
+ELF-NEXT: Type: Object (0x1)
+ELF-NEXT: Other: 0
+ELF-NEXT: Section: .rodata.str1.1 (0x5)
+ELF-NEXT: }