Skip to content

Commit

Permalink
llvm-readobj: pretty-print special COFF section names
Browse files Browse the repository at this point in the history
Print IMAGE_SYM_DEBUG and the like instead of (-2).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218172 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
majnemer committed Sep 20, 2014
1 parent 87f7e75 commit c7210b3
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 30 deletions.
6 changes: 3 additions & 3 deletions test/MC/ARM/coff-file.s
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@
// CHECK-SCN: Symbols [
// CHECK-SCN: Symbol {
// CHECK-SCN: Name: .file
// CHECK-SCN: Section: (-2)
// CHECK-SCN: Section: IMAGE_SYM_DEBUG (-2)
// CHECK-SCN: StorageClass: File
// CHECK-SCN: AuxFileRecord {
// CHECK-SCN: FileName: null-padded.asm
// CHECK-SCN: }
// CHECK-SCN: }
// CHECK-SCN: Symbol {
// CHECK-SCN: Name: .file
// CHECK-SCN: Section: (-2)
// CHECK-SCN: Section: IMAGE_SYM_DEBUG (-2)
// CHECK-SCN: StorageClass: File
// CHECK-SCN: AuxFileRecord {
// CHECK-SCN: FileName: eighteen-chars.asm
// CHECK-SCN: }
// CHECK-SCN: }
// CHECK-SCN: Symbol {
// CHECK-SCN: Name: .file
// CHECK-SCN: Section: (-2)
// CHECK-SCN: Section: IMAGE_SYM_DEBUG (-2)
// CHECK-SCN: StorageClass: File
// CHECK-SCN: AuxFileRecord {
// CHECK-SCN: FileName: multiple-auxiliary-entries.asm
Expand Down
8 changes: 4 additions & 4 deletions test/MC/COFF/alias.s
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ weak_aliased_to_external = external2
// CHECK-NEXT: Symbol {
// CHECK: Name: global_aliased_to_external
// CHECK-NEXT: Value: 0
// CHECK-NEXT: Section: (0)
// CHECK-NEXT: Section: IMAGE_SYM_UNDEFINED (0)
// CHECK-NEXT: BaseType: Null (0x0)
// CHECK-NEXT: ComplexType: Null (0x0)
// CHECK-NEXT: StorageClass: External (0x2)
Expand All @@ -57,7 +57,7 @@ weak_aliased_to_external = external2
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: external1
// CHECK-NEXT: Value: 0
// CHECK-NEXT: Section: (0)
// CHECK-NEXT: Section: IMAGE_SYM_UNDEFINED (0)
// CHECK-NEXT: BaseType: Null (0x0)
// CHECK-NEXT: ComplexType: Null (0x0)
// CHECK-NEXT: StorageClass: External (0x2)
Expand All @@ -84,7 +84,7 @@ weak_aliased_to_external = external2
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: weak_aliased_to_external
// CHECK-NEXT: Value: 0
// CHECK-NEXT: Section: (0)
// CHECK-NEXT: Section: IMAGE_SYM_UNDEFINED (0)
// CHECK-NEXT: BaseType: Null (0x0)
// CHECK-NEXT: ComplexType: Null (0x0)
// CHECK-NEXT: StorageClass: WeakExternal (0x69)
Expand All @@ -97,7 +97,7 @@ weak_aliased_to_external = external2
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: external2
// CHECK-NEXT: Value: 0
// CHECK-NEXT: Section: (0)
// CHECK-NEXT: Section: IMAGE_SYM_UNDEFINED (0)
// CHECK-NEXT: BaseType: Null (0x0)
// CHECK-NEXT: ComplexType: Null (0x0)
// CHECK-NEXT: StorageClass: External (0x2)
Expand Down
2 changes: 1 addition & 1 deletion test/MC/COFF/basic-coff-64.s
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ _main: # @main
// CHECK: Symbol {
// CHECK: Name: _printf
// CHECK: Value: 0
// CHECK: Section: (0)
// CHECK: Section: IMAGE_SYM_UNDEFINED (0)
// CHECK: BaseType: Null
// CHECK: ComplexType: Null
// CHECK: StorageClass: External
Expand Down
2 changes: 1 addition & 1 deletion test/MC/COFF/basic-coff.s
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ L_.str: # @.str
// CHECK: Symbol {
// CHECK: Name: _printf
// CHECK: Value: 0
// CHECK: Section: (0)
// CHECK: Section: IMAGE_SYM_UNDEFINED (0)
// CHECK: BaseType: Null
// CHECK: ComplexType: Null
// CHECK: StorageClass: External
Expand Down
2 changes: 1 addition & 1 deletion test/MC/COFF/comm.s
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// CHECK: Symbol {
// CHECK: Name: _b
// CHECK-NEXT: Value: 4
// CHECK-NEXT: Section: (0)
// CHECK-NEXT: Section: IMAGE_SYM_UNDEFINED (0)
// CHECK-NEXT: BaseType: Null
// CHECK-NEXT: ComplexType: Null
// CHECK-NEXT: StorageClass: External
Expand Down
2 changes: 1 addition & 1 deletion test/MC/COFF/feat00.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// CHECK: Symbol {
// CHECK: Name: @feat.00
// CHECK: Value: 123
// CHECK: Section: (-1)
// CHECK: Section: IMAGE_SYM_ABSOLUTE (-1)
// CHECK: BaseType: Null (0x0)
// CHECK: ComplexType: Null (0x0)
// CHECK: StorageClass: External (0x2)
Expand Down
6 changes: 3 additions & 3 deletions test/MC/COFF/file.s
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@
// CHECK-SCN: Symbols [
// CHECK-SCN: Symbol {
// CHECK-SCN: Name: .file
// CHECK-SCN: Section: (-2)
// CHECK-SCN: Section: IMAGE_SYM_DEBUG (-2)
// CHECK-SCN: StorageClass: File
// CHECK-SCN: AuxFileRecord {
// CHECK-SCN: FileName: null-padded.asm
// CHECK-SCN: }
// CHECK-SCN: }
// CHECK-SCN: Symbol {
// CHECK-SCN: Name: .file
// CHECK-SCN: Section: (-2)
// CHECK-SCN: Section: IMAGE_SYM_DEBUG (-2)
// CHECK-SCN: StorageClass: File
// CHECK-SCN: AuxFileRecord {
// CHECK-SCN: FileName: eighteen-chars.asm
// CHECK-SCN: }
// CHECK-SCN: }
// CHECK-SCN: Symbol {
// CHECK-SCN: Name: .file
// CHECK-SCN: Section: (-2)
// CHECK-SCN: Section: IMAGE_SYM_DEBUG (-2)
// CHECK-SCN: StorageClass: File
// CHECK-SCN: AuxFileRecord {
// CHECK-SCN: FileName: multiple-auxiliary-entries.asm
Expand Down
4 changes: 2 additions & 2 deletions test/MC/COFF/symbol-fragment-offset-64.s
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ _main: # @main
// CHECK: Symbol {
// CHECK: Name: _printf
// CHECK: Value: 0
// CHECK: Section: (0)
// CHECK: Section: IMAGE_SYM_UNDEFINED (0)
// CHECK: BaseType: Null
// CHECK: ComplexType: Null
// CHECK: StorageClass: External
Expand All @@ -157,7 +157,7 @@ _main: # @main
// CHECK: Symbol {
// CHECK: Name: _puts
// CHECK: Value: 0
// CHECK: Section: (0)
// CHECK: Section: IMAGE_SYM_UNDEFINED (0)
// CHECK: BaseType: Null
// CHECK: ComplexType: Null
// CHECK: StorageClass: External
Expand Down
4 changes: 2 additions & 2 deletions test/MC/COFF/symbol-fragment-offset.s
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ L_.str2:
// CHECK: Symbol {
// CHECK: Name: _printf
// CHECK: Value: 0
// CHECK: Section: (0)
// CHECK: Section: IMAGE_SYM_UNDEFINED (0)
// CHECK: BaseType: Null
// CHECK: ComplexType: Null
// CHECK: StorageClass: External
Expand All @@ -157,7 +157,7 @@ L_.str2:
// CHECK: Symbol {
// CHECK: Name: _puts
// CHECK: Value: 0
// CHECK: Section: (0)
// CHECK: Section: IMAGE_SYM_UNDEFINED (0)
// CHECK: BaseType: Null
// CHECK: ComplexType: Null
// CHECK: StorageClass: External
Expand Down
6 changes: 3 additions & 3 deletions test/MC/COFF/weak.s
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ LBB0_2: # %return
// CHECK: Symbol {
// CHECK: Name: _test_weak
// CHECK-NEXT: Value: 0
// CHECK-NEXT: Section: (0)
// CHECK-NEXT: Section: IMAGE_SYM_UNDEFINED (0)
// CHECK-NEXT: BaseType: Null
// CHECK-NEXT: ComplexType: Null
// CHECK-NEXT: StorageClass: WeakExternal
Expand All @@ -51,7 +51,7 @@ LBB0_2: # %return
// CHECK: Symbol {
// CHECK: Name: .weak._test_weak.default
// CHECK-NEXT: Value: 0
// CHECK-NEXT: Section: (-1)
// CHECK-NEXT: Section: IMAGE_SYM_ABSOLUTE (-1)
// CHECK-NEXT: BaseType: Null
// CHECK-NEXT: ComplexType: Null
// CHECK-NEXT: StorageClass: External
Expand All @@ -61,7 +61,7 @@ LBB0_2: # %return
// CHECK: Symbol {
// CHECK: Name: _test_weak_alias
// CHECK-NEXT: Value: 0
// CHECK-NEXT: Section: (0)
// CHECK-NEXT: Section: IMAGE_SYM_UNDEFINED (0)
// CHECK-NEXT: BaseType: Null
// CHECK-NEXT: ComplexType: Null
// CHECK-NEXT: StorageClass: WeakExternal
Expand Down
2 changes: 1 addition & 1 deletion test/tools/llvm-readobj/bigobj.test
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ CHECK-NEXT: Symbols [
CHECK-NEXT: Symbol {
CHECK-NEXT: Name: .file
CHECK-NEXT: Value: 0
CHECK-NEXT: Section: (-2)
CHECK-NEXT: Section: IMAGE_SYM_DEBUG (-2)
CHECK-NEXT: BaseType: Null (0x0)
CHECK-NEXT: ComplexType: Null (0x0)
CHECK-NEXT: StorageClass: File (0x67)
Expand Down
2 changes: 1 addition & 1 deletion test/tools/llvm-readobj/coff-file-sections-reading.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CHECK: Symbols [
CHECK: Symbol {
CHECK: Name: .file
CHECK: Value: 0
CHECK: Section: (-2)
CHECK: Section: IMAGE_SYM_DEBUG (-2)
CHECK: BaseType: Null (0x0)
CHECK: ComplexType: Null (0x0)
CHECK: StorageClass: File (0x67)
Expand Down
4 changes: 2 additions & 2 deletions test/tools/llvm-readobj/cxx-cli-aux.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CHECK: Symbols [
CHECK: Symbol {
CHECK: Name: ?PerAppDomain@@$$Q3HA
CHECK-NEXT: Value: 4
CHECK-NEXT: Section: (-1)
CHECK-NEXT: Section: IMAGE_SYM_ABSOLUTE (-1)
CHECK-NEXT: BaseType: Null (0x0)
CHECK-NEXT: ComplexType: Null (0x0)
CHECK-NEXT: StorageClass: External (0x2)
Expand All @@ -27,7 +27,7 @@ CHECK-NEXT: }
CHECK: Symbol {
CHECK: Name: 04000001
CHECK-NEXT: Value: 4
CHECK-NEXT: Section: (-1)
CHECK-NEXT: Section: IMAGE_SYM_ABSOLUTE (-1)
CHECK-NEXT: BaseType: Null (0x0)
CHECK-NEXT: ComplexType: Null (0x0)
CHECK-NEXT: StorageClass: CLRToken (0x6B)
Expand Down
4 changes: 2 additions & 2 deletions test/tools/llvm-readobj/symbols.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ COFF: Symbols [
COFF-NEXT: Symbol {
COFF-NEXT: Name: @comp.id
COFF-NEXT: Value: 14766605
COFF-NEXT: Section: (-1)
COFF-NEXT: Section: IMAGE_SYM_ABSOLUTE (-1)
COFF-NEXT: BaseType: Null (0x0)
COFF-NEXT: ComplexType: Null (0x0)
COFF-NEXT: StorageClass: Static (0x3)
Expand All @@ -16,7 +16,7 @@ COFF-NEXT: }
COFF-NEXT: Symbol {
COFF-NEXT: Name: @feat.00
COFF-NEXT: Value: 2147484049
COFF-NEXT: Section: (-1)
COFF-NEXT: Section: IMAGE_SYM_ABSOLUTE (-1)
COFF-NEXT: BaseType: Null (0x0)
COFF-NEXT: ComplexType: Null (0x0)
COFF-NEXT: StorageClass: Static (0x3)
Expand Down
22 changes: 19 additions & 3 deletions tools/llvm-readobj/COFFDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,24 @@ void COFFDumper::printSymbols() {

void COFFDumper::printDynamicSymbols() { ListScope Group(W, "DynamicSymbols"); }

static StringRef getSectionName(const llvm::object::COFFObjectFile *Obj,
COFFSymbolRef Symbol,
const coff_section *Section) {
if (Section) {
StringRef SectionName;
Obj->getSectionName(Section, SectionName);
return SectionName;
}
int32_t SectionNumber = Symbol.getSectionNumber();
if (SectionNumber == llvm::COFF::IMAGE_SYM_DEBUG)
return "IMAGE_SYM_DEBUG";
if (SectionNumber == llvm::COFF::IMAGE_SYM_ABSOLUTE)
return "IMAGE_SYM_ABSOLUTE";
if (SectionNumber == llvm::COFF::IMAGE_SYM_UNDEFINED)
return "IMAGE_SYM_UNDEFINED";
return "";
}

void COFFDumper::printSymbol(const SymbolRef &Sym) {
DictScope D(W, "Symbol");

Expand All @@ -730,9 +748,7 @@ void COFFDumper::printSymbol(const SymbolRef &Sym) {
if (Obj->getSymbolName(Symbol, SymbolName))
SymbolName = "";

StringRef SectionName = "";
if (Section)
Obj->getSectionName(Section, SectionName);
StringRef SectionName = getSectionName(Obj, Symbol, Section);

W.printString("Name", SymbolName);
W.printNumber("Value", Symbol.getValue());
Expand Down

0 comments on commit c7210b3

Please sign in to comment.