[llvm-commits] [llvm] r167852 - /llvm/trunk/include/llvm/Object/ELF.h
Shankar Easwaran
shankare at codeaurora.org
Tue Nov 13 10:26:22 PST 2012
Author: shankare
Date: Tue Nov 13 12:26:22 2012
New Revision: 167852
URL: http://llvm.org/viewvc/llvm-project?rev=167852&view=rev
Log:
Adding convenience function to ELF Header
Modified:
llvm/trunk/include/llvm/Object/ELF.h
Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=167852&r1=167851&r2=167852&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Tue Nov 13 12:26:22 2012
@@ -609,6 +609,7 @@
const Elf_Dyn *getDyn(DataRefImpl DynData) const;
error_code getSymbolVersion(SymbolRef Symb, StringRef &Version,
bool &IsDefault) const;
+ uint64_t getSymbolIndex(const Elf_Sym *sym) const;
protected:
virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
@@ -2094,6 +2095,21 @@
}
}
+// Get the symbol table index in the symtab section given a symbol
+template<support::endianness target_endianness, bool is64Bits>
+uint64_t ELFObjectFile<target_endianness, is64Bits>
+ ::getSymbolIndex(const Elf_Sym *Sym) const {
+ assert(SymbolTableSections.size() == 1 && "Only one symbol table supported!");
+ const Elf_Shdr *SymTab = *SymbolTableSections.begin();
+ uintptr_t SymLoc = uintptr_t(Sym);
+ uintptr_t SymTabLoc = uintptr_t(base() + SymTab->sh_offset);
+ assert(SymLoc > SymTabLoc && "Symbol not in symbol table!");
+ uint64_t SymOffset = SymLoc - SymTabLoc;
+ assert(SymOffset % SymTab->sh_entsize == 0 &&
+ "Symbol not multiple of symbol size!");
+ return SymOffset / SymTab->sh_entsize;
+}
+
template<support::endianness target_endianness, bool is64Bits>
symbol_iterator ELFObjectFile<target_endianness, is64Bits>
::begin_symbols() const {
More information about the llvm-commits
mailing list