llvm.org GIT mirror llvm / 0239fd3
[llvm-readobj] [COFF] Print the symbol index for relocations There can be multiple local symbols with the same name (for e.g. comdat sections), and thus the symbol name itself isn't enough to disambiguate symbols. Differential Revision: https://reviews.llvm.org/D56140 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350288 91177308-0d34-0410-b5e6-96231b3b80d8 Martin Storsjo 8 months ago
6 changed file(s) with 26 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
10211021
10221022 ArrayRef getSymbolAuxData(COFFSymbolRef Symbol) const;
10231023
1024 uint32_t getSymbolIndex(COFFSymbolRef Symbol) const;
1025
10241026 size_t getSymbolTableEntrySize() const {
10251027 if (COFFHeader)
10261028 return sizeof(coff_symbol16);
10621062 #endif
10631063 }
10641064 return makeArrayRef(Aux, Symbol.getNumberOfAuxSymbols() * SymbolSize);
1065 }
1066
1067 uint32_t COFFObjectFile::getSymbolIndex(COFFSymbolRef Symbol) const {
1068 uintptr_t Offset =
1069 reinterpret_cast(Symbol.getRawPtr()) - getSymbolTable();
1070 assert(Offset % getSymbolTableEntrySize() == 0 &&
1071 "Symbol did not point to the beginning of a symbol");
1072 size_t Index = Offset / getSymbolTableEntrySize();
1073 assert(Index < getNumberOfSymbols());
1074 return Index;
10651075 }
10661076
10671077 std::error_code COFFObjectFile::getSectionName(const coff_section *Sec,
8686 // READOBJ-NEXT: Offset: 0x0
8787 // READOBJ-NEXT: Type: IMAGE_REL_AMD64_REL32 (4)
8888 // READOBJ-NEXT: Symbol: g3
89 // READOBJ-NEXT: SymbolIndex: 12
8990 // READOBJ-NEXT: }
9091 // READOBJ-NEXT: Relocation {
9192 // READOBJ-NEXT: Offset: 0x4
9293 // READOBJ-NEXT: Type: IMAGE_REL_AMD64_ADDR32NB (3)
9394 // READOBJ-NEXT: Symbol: g3
95 // READOBJ-NEXT: SymbolIndex: 12
9496 // READOBJ-NEXT: }
9597 // READOBJ-NEXT: Relocation {
9698 // READOBJ-NEXT: Offset: 0x20
9799 // READOBJ-NEXT: Type: IMAGE_REL_AMD64_REL32 (4)
98100 // READOBJ-NEXT: Symbol: g3
101 // READOBJ-NEXT: SymbolIndex: 12
99102 // READOBJ-NEXT: }
100103 // READOBJ-NEXT: Relocation {
101104 // READOBJ-NEXT: Offset: 0x28
102105 // READOBJ-NEXT: Type: IMAGE_REL_AMD64_REL32 (4)
103106 // READOBJ-NEXT: Symbol: foobar
107 // READOBJ-NEXT: SymbolIndex: 20
104108 // READOBJ-NEXT: }
105109 // READOBJ-NEXT: }
106110 // READOBJ-NEXT:]
1212 // COFF-I386-NEXT: Offset: 0xE
1313 // COFF-I386-NEXT: Type: IMAGE_REL_I386_DIR32 (6)
1414 // COFF-I386-NEXT: Symbol: L_.str
15 // COFF-I386-NEXT: SymbolIndex: 5
1516 // COFF-I386-NEXT: }
1617 // COFF-I386-NEXT: Relocation {
1718 // COFF-I386-NEXT: Offset: 0x13
1819 // COFF-I386-NEXT: Type: IMAGE_REL_I386_REL32 (20)
1920 // COFF-I386-NEXT: Symbol: _puts
21 // COFF-I386-NEXT: SymbolIndex: 6
2022 // COFF-I386-NEXT: }
2123 // COFF-I386-NEXT: Relocation {
2224 // COFF-I386-NEXT: Offset: 0x18
2325 // COFF-I386-NEXT: Type: IMAGE_REL_I386_REL32 (20)
2426 // COFF-I386-NEXT: Symbol: _SomeOtherFunction
27 // COFF-I386-NEXT: SymbolIndex: 7
2528 // COFF-I386-NEXT: }
2629 // COFF-I386-NEXT: }
2730 // COFF-I386-NEXT: ]
2020
2121 COFF: Relocations [
2222 COFF-NEXT: Section (1) .text {
23 COFF-NEXT: 0x4 IMAGE_REL_I386_DIR32 .data
24 COFF-NEXT: 0x9 IMAGE_REL_I386_REL32 _puts
25 COFF-NEXT: 0xE IMAGE_REL_I386_REL32 _SomeOtherFunction
23 COFF-NEXT: 0x4 IMAGE_REL_I386_DIR32 .data (4)
24 COFF-NEXT: 0x9 IMAGE_REL_I386_REL32 _puts (7)
25 COFF-NEXT: 0xE IMAGE_REL_I386_REL32 _SomeOtherFunction (8)
2626 COFF-NEXT: }
2727 COFF-NEXT: ]
2828
13641364 StringRef SymbolName;
13651365 Reloc.getTypeName(RelocName);
13661366 symbol_iterator Symbol = Reloc.getSymbol();
1367 int64_t SymbolIndex = -1;
13671368 if (Symbol != Obj->symbol_end()) {
13681369 Expected SymbolNameOrErr = Symbol->getName();
13691370 error(errorToErrorCode(SymbolNameOrErr.takeError()));
13701371 SymbolName = *SymbolNameOrErr;
1372 SymbolIndex = Obj->getSymbolIndex(Obj->getCOFFSymbol(*Symbol));
13711373 }
13721374
13731375 if (opts::ExpandRelocs) {
13751377 W.printHex("Offset", Offset);
13761378 W.printNumber("Type", RelocName, RelocType);
13771379 W.printString("Symbol", SymbolName.empty() ? "-" : SymbolName);
1380 W.printNumber("SymbolIndex", SymbolIndex);
13781381 } else {
13791382 raw_ostream& OS = W.startLine();
13801383 OS << W.hex(Offset)
13811384 << " " << RelocName
13821385 << " " << (SymbolName.empty() ? "-" : SymbolName)
1386 << " (" << SymbolIndex << ")"
13831387 << "\n";
13841388 }
13851389 }