From 74e7d26090be48fb99b2c69e48ec66b5007390f3 Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Thu, 3 Jan 2019 08:08:23 +0000 Subject: [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 llvm-svn: 350288 --- llvm/lib/Object/COFFObjectFile.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'llvm/lib/Object/COFFObjectFile.cpp') diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp index e17f0e2783e..fc1deeba339 100644 --- a/llvm/lib/Object/COFFObjectFile.cpp +++ b/llvm/lib/Object/COFFObjectFile.cpp @@ -1065,6 +1065,16 @@ COFFObjectFile::getSymbolAuxData(COFFSymbolRef Symbol) const { return makeArrayRef(Aux, Symbol.getNumberOfAuxSymbols() * SymbolSize); } +uint32_t COFFObjectFile::getSymbolIndex(COFFSymbolRef Symbol) const { + uintptr_t Offset = + reinterpret_cast(Symbol.getRawPtr()) - getSymbolTable(); + assert(Offset % getSymbolTableEntrySize() == 0 && + "Symbol did not point to the beginning of a symbol"); + size_t Index = Offset / getSymbolTableEntrySize(); + assert(Index < getNumberOfSymbols()); + return Index; +} + std::error_code COFFObjectFile::getSectionName(const coff_section *Sec, StringRef &Res) const { StringRef Name; -- cgit v1.2.3