|
@@ -325,7 +325,7 @@ class ELFObjectFile : public ObjectFile {
|
|
protected:
|
|
protected:
|
|
virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
|
|
virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
|
|
virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
|
|
virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
|
|
- virtual error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res) const;
|
|
|
|
|
|
+ virtual error_code getSymbolOffset(DataRefImpl Symb, uint64_t &Res) const;
|
|
virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const;
|
|
virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const;
|
|
virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const;
|
|
virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const;
|
|
virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
|
|
virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
|
|
@@ -355,8 +355,6 @@ protected:
|
|
RelocationRef &Res) const;
|
|
RelocationRef &Res) const;
|
|
virtual error_code getRelocationAddress(DataRefImpl Rel,
|
|
virtual error_code getRelocationAddress(DataRefImpl Rel,
|
|
uint64_t &Res) const;
|
|
uint64_t &Res) const;
|
|
- virtual error_code getRelocationOffset(DataRefImpl Rel,
|
|
|
|
- uint64_t &Res) const;
|
|
|
|
virtual error_code getRelocationSymbol(DataRefImpl Rel,
|
|
virtual error_code getRelocationSymbol(DataRefImpl Rel,
|
|
SymbolRef &Res) const;
|
|
SymbolRef &Res) const;
|
|
virtual error_code getRelocationType(DataRefImpl Rel,
|
|
virtual error_code getRelocationType(DataRefImpl Rel,
|
|
@@ -464,7 +462,7 @@ ELFObjectFile<target_endianness, is64Bits>
|
|
|
|
|
|
template<support::endianness target_endianness, bool is64Bits>
|
|
template<support::endianness target_endianness, bool is64Bits>
|
|
error_code ELFObjectFile<target_endianness, is64Bits>
|
|
error_code ELFObjectFile<target_endianness, is64Bits>
|
|
- ::getSymbolFileOffset(DataRefImpl Symb,
|
|
|
|
|
|
+ ::getSymbolOffset(DataRefImpl Symb,
|
|
uint64_t &Result) const {
|
|
uint64_t &Result) const {
|
|
validateSymbol(Symb);
|
|
validateSymbol(Symb);
|
|
const Elf_Sym *symb = getSymbol(Symb);
|
|
const Elf_Sym *symb = getSymbol(Symb);
|
|
@@ -488,8 +486,7 @@ error_code ELFObjectFile<target_endianness, is64Bits>
|
|
case ELF::STT_FUNC:
|
|
case ELF::STT_FUNC:
|
|
case ELF::STT_OBJECT:
|
|
case ELF::STT_OBJECT:
|
|
case ELF::STT_NOTYPE:
|
|
case ELF::STT_NOTYPE:
|
|
- Result = symb->st_value +
|
|
|
|
- (Section ? Section->sh_offset - Section->sh_addr : 0);
|
|
|
|
|
|
+ Result = symb->st_value;
|
|
return object_error::success;
|
|
return object_error::success;
|
|
default:
|
|
default:
|
|
Result = UnknownAddressOrSize;
|
|
Result = UnknownAddressOrSize;
|
|
@@ -505,25 +502,28 @@ error_code ELFObjectFile<target_endianness, is64Bits>
|
|
const Elf_Sym *symb = getSymbol(Symb);
|
|
const Elf_Sym *symb = getSymbol(Symb);
|
|
const Elf_Shdr *Section;
|
|
const Elf_Shdr *Section;
|
|
switch (getSymbolTableIndex(symb)) {
|
|
switch (getSymbolTableIndex(symb)) {
|
|
- case ELF::SHN_COMMON:
|
|
|
|
|
|
+ case ELF::SHN_COMMON: // Fall through.
|
|
// Undefined symbols have no address yet.
|
|
// Undefined symbols have no address yet.
|
|
case ELF::SHN_UNDEF:
|
|
case ELF::SHN_UNDEF:
|
|
Result = UnknownAddressOrSize;
|
|
Result = UnknownAddressOrSize;
|
|
return object_error::success;
|
|
return object_error::success;
|
|
case ELF::SHN_ABS:
|
|
case ELF::SHN_ABS:
|
|
- Result = symb->st_value;
|
|
|
|
|
|
+ Result = reinterpret_cast<uintptr_t>(base()+symb->st_value);
|
|
return object_error::success;
|
|
return object_error::success;
|
|
default: Section = getSection(symb);
|
|
default: Section = getSection(symb);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ const uint8_t* addr = base();
|
|
|
|
+ if (Section)
|
|
|
|
+ addr += Section->sh_offset;
|
|
switch (symb->getType()) {
|
|
switch (symb->getType()) {
|
|
case ELF::STT_SECTION:
|
|
case ELF::STT_SECTION:
|
|
- Result = Section ? Section->sh_addr : UnknownAddressOrSize;
|
|
|
|
|
|
+ Result = reinterpret_cast<uintptr_t>(addr);
|
|
return object_error::success;
|
|
return object_error::success;
|
|
- case ELF::STT_FUNC:
|
|
|
|
- case ELF::STT_OBJECT:
|
|
|
|
|
|
+ case ELF::STT_FUNC: // Fall through.
|
|
|
|
+ case ELF::STT_OBJECT: // Fall through.
|
|
case ELF::STT_NOTYPE:
|
|
case ELF::STT_NOTYPE:
|
|
- Result = symb->st_value;
|
|
|
|
|
|
+ addr += symb->st_value;
|
|
|
|
+ Result = reinterpret_cast<uintptr_t>(addr);
|
|
return object_error::success;
|
|
return object_error::success;
|
|
default:
|
|
default:
|
|
Result = UnknownAddressOrSize;
|
|
Result = UnknownAddressOrSize;
|
|
@@ -920,29 +920,6 @@ error_code ELFObjectFile<target_endianness, is64Bits>
|
|
return object_error::success;
|
|
return object_error::success;
|
|
}
|
|
}
|
|
|
|
|
|
-template<support::endianness target_endianness, bool is64Bits>
|
|
|
|
-error_code ELFObjectFile<target_endianness, is64Bits>
|
|
|
|
- ::getRelocationOffset(DataRefImpl Rel,
|
|
|
|
- uint64_t &Result) const {
|
|
|
|
- uint64_t offset;
|
|
|
|
- const Elf_Shdr *sec = getSection(Rel.w.b);
|
|
|
|
- switch (sec->sh_type) {
|
|
|
|
- default :
|
|
|
|
- report_fatal_error("Invalid section type in Rel!");
|
|
|
|
- case ELF::SHT_REL : {
|
|
|
|
- offset = getRel(Rel)->r_offset;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- case ELF::SHT_RELA : {
|
|
|
|
- offset = getRela(Rel)->r_offset;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Result = offset - sec->sh_addr;
|
|
|
|
- return object_error::success;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
template<support::endianness target_endianness, bool is64Bits>
|
|
template<support::endianness target_endianness, bool is64Bits>
|
|
error_code ELFObjectFile<target_endianness, is64Bits>
|
|
error_code ELFObjectFile<target_endianness, is64Bits>
|
|
::getRelocationType(DataRefImpl Rel,
|
|
::getRelocationType(DataRefImpl Rel,
|