Skip to content

Commit 9cad53c

Browse files
committedApr 3, 2013
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! llvm-svn: 178679
1 parent 2d4b3a6 commit 9cad53c

34 files changed

+3928
-521
lines changed
 

‎llvm/include/llvm/Object/ELF.h

+7
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ class ELFObjectFile : public ObjectFile {
790790
uint64_t getNumSections() const;
791791
uint64_t getStringTableIndex() const;
792792
ELF::Elf64_Word getSymbolTableIndex(const Elf_Sym *symb) const;
793+
const Elf_Ehdr *getElfHeader() const;
793794
const Elf_Shdr *getSection(const Elf_Sym *symb) const;
794795
const Elf_Shdr *getElfSection(section_iterator &It) const;
795796
const Elf_Sym *getElfSymbol(symbol_iterator &It) const;
@@ -968,6 +969,12 @@ ELFObjectFile<ELFT>::getSection(const Elf_Sym *symb) const {
968969
return getSection(symb->st_shndx);
969970
}
970971

972+
template<class ELFT>
973+
const typename ELFObjectFile<ELFT>::Elf_Ehdr *
974+
ELFObjectFile<ELFT>::getElfHeader() const {
975+
return Header;
976+
}
977+
971978
template<class ELFT>
972979
const typename ELFObjectFile<ELFT>::Elf_Shdr *
973980
ELFObjectFile<ELFT>::getElfSection(section_iterator &It) const {

‎llvm/include/llvm/Support/COFF.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ namespace COFF {
321321
IMAGE_COMDAT_SELECT_SAME_SIZE,
322322
IMAGE_COMDAT_SELECT_EXACT_MATCH,
323323
IMAGE_COMDAT_SELECT_ASSOCIATIVE,
324-
IMAGE_COMDAT_SELECT_LARGEST
324+
IMAGE_COMDAT_SELECT_LARGEST,
325+
IMAGE_COMDAT_SELECT_NEWEST
325326
};
326327

327328
// Auxiliary Symbol Formats

‎llvm/include/llvm/Support/Win64EH.h

+14-4
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,17 @@ struct UnwindInfo {
106106
return reinterpret_cast<void *>(&UnwindCodes[(NumCodes+1) & ~1]);
107107
}
108108

109-
/// \brief Return image-relativ offset of language-specific exception handler.
110-
uint32_t getLanguageSpecificHandlerOffset() {
111-
return *reinterpret_cast<uint32_t *>(getLanguageSpecificData());
109+
/// \brief Return pointer to language specific data part of UnwindInfo.
110+
const void *getLanguageSpecificData() const {
111+
return reinterpret_cast<const void *>(&UnwindCodes[(NumCodes+1) & ~1]);
112+
}
113+
114+
/// \brief Return image-relative offset of language-specific exception handler.
115+
uint32_t getLanguageSpecificHandlerOffset() const {
116+
return *reinterpret_cast<const uint32_t *>(getLanguageSpecificData());
112117
}
113118

114-
/// \brief Set image-relativ offset of language-specific exception handler.
119+
/// \brief Set image-relative offset of language-specific exception handler.
115120
void setLanguageSpecificHandlerOffset(uint32_t offset) {
116121
*reinterpret_cast<uint32_t *>(getLanguageSpecificData()) = offset;
117122
}
@@ -126,6 +131,11 @@ struct UnwindInfo {
126131
RuntimeFunction *getChainedFunctionEntry() {
127132
return reinterpret_cast<RuntimeFunction *>(getLanguageSpecificData());
128133
}
134+
135+
/// \brief Return pointer to chained unwind info.
136+
const RuntimeFunction *getChainedFunctionEntry() const {
137+
return reinterpret_cast<const RuntimeFunction *>(getLanguageSpecificData());
138+
}
129139
};
130140

131141

‎llvm/test/MC/ELF/many-sections-2.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
2-
// RUN: llvm-readobj %t | FileCheck %s
2+
// RUN: llvm-readobj -s %t | FileCheck %s
33

44
// CHECK: symtab_shndx
55

+40-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,46 @@
1-
RUN: llvm-readobj %p/Inputs/elf-versioning-test.i386 \
1+
RUN: llvm-readobj -dt %p/Inputs/elf-versioning-test.i386 \
22
RUN: | FileCheck %s -check-prefix ELF
3-
RUN: llvm-readobj %p/Inputs/elf-versioning-test.i386 \
3+
RUN: llvm-readobj -dt %p/Inputs/elf-versioning-test.i386 \
44
RUN: | FileCheck %s -check-prefix ELF32
5-
RUN: llvm-readobj %p/Inputs/elf-versioning-test.x86_64 \
5+
RUN: llvm-readobj -dt %p/Inputs/elf-versioning-test.x86_64 \
66
RUN: | FileCheck %s -check-prefix ELF
7-
RUN: llvm-readobj %p/Inputs/elf-versioning-test.x86_64 \
7+
RUN: llvm-readobj -dt %p/Inputs/elf-versioning-test.x86_64 \
88
RUN: | FileCheck %s -check-prefix ELF64
99

10-
ELF: foo@@VER2 FUNC .text {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} global
11-
ELF: foo@VER1 FUNC .text {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} global
12-
ELF: unversioned_define FUNC .text {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} global
10+
ELF: DynamicSymbols [
11+
ELF: Symbol {
12+
ELF: Name: foo@@VER2
13+
ELF: Binding: Global
14+
ELF: Type: Function
15+
ELF: Section: .text
16+
ELF: }
17+
ELF: Symbol {
18+
ELF: Name: foo@VER1
19+
ELF: Binding: Global
20+
ELF: Type: Function
21+
ELF: Section: .text
22+
ELF: }
23+
ELF: Symbol {
24+
ELF: Name: unversioned_define
25+
ELF: Binding: Global
26+
ELF: Type: Function
27+
ELF: Section: .text
28+
ELF: }
29+
ELF: ]
1330

14-
ELF32: puts@GLIBC_2.0 FUNC {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} undef,global
15-
ELF64: puts@GLIBC_2.2.5 FUNC {{[0-9a-f]+}} {{[0-9a-f]+}} {{[0-9a-f]+}} undef,global
31+
ELF32: DynamicSymbols [
32+
ELF32: Symbol {
33+
ELF32: Name: puts@GLIBC_2.0
34+
ELF32: Binding: Global
35+
ELF32: Type: Function
36+
ELF32: Section: (0x0)
37+
ELF32: }
38+
ELF32: ]
39+
ELF64: DynamicSymbols [
40+
ELF64: Symbol {
41+
ELF64: Name: puts@GLIBC_2.2.5
42+
ELF64: Binding: Global
43+
ELF64: Type: Function
44+
ELF64: Section: (0x0)
45+
ELF64: }
46+
ELF64: ]

0 commit comments

Comments
 (0)
Please sign in to comment.