Merge "Check machine arch before detecting relocation type"
This commit is contained in:
@@ -18,18 +18,24 @@
|
|||||||
|
|
||||||
#include <cxxabi.h>
|
#include <cxxabi.h>
|
||||||
|
|
||||||
using llvm::ELF::ELFDATA2MSB;
|
using llvm::ELF::EM_386;
|
||||||
|
using llvm::ELF::EM_X86_64;
|
||||||
using llvm::ELF::EM_ARM;
|
using llvm::ELF::EM_ARM;
|
||||||
|
using llvm::ELF::EM_AARCH64;
|
||||||
using llvm::ELF::EM_MIPS;
|
using llvm::ELF::EM_MIPS;
|
||||||
using llvm::ELF::R_AARCH64_ABS64;
|
|
||||||
using llvm::ELF::R_AARCH64_RELATIVE;
|
using llvm::ELF::R_386_32;
|
||||||
using llvm::ELF::R_ARM_ABS32;
|
using llvm::ELF::R_386_RELATIVE;
|
||||||
using llvm::ELF::R_ARM_RELATIVE;
|
|
||||||
using llvm::ELF::R_X86_64_64;
|
using llvm::ELF::R_X86_64_64;
|
||||||
using llvm::ELF::R_X86_64_RELATIVE;
|
using llvm::ELF::R_X86_64_RELATIVE;
|
||||||
|
using llvm::ELF::R_ARM_ABS32;
|
||||||
|
using llvm::ELF::R_ARM_RELATIVE;
|
||||||
|
using llvm::ELF::R_AARCH64_ABS64;
|
||||||
|
using llvm::ELF::R_AARCH64_RELATIVE;
|
||||||
using llvm::ELF::R_MIPS_64;
|
using llvm::ELF::R_MIPS_64;
|
||||||
using llvm::ELF::R_MIPS_REL32;
|
using llvm::ELF::R_MIPS_REL32;
|
||||||
using llvm::ELF::R_MIPS_NONE;
|
using llvm::ELF::R_MIPS_NONE;
|
||||||
|
|
||||||
using llvm::ELF::SHT_PROGBITS;
|
using llvm::ELF::SHT_PROGBITS;
|
||||||
using llvm::ELF::SHT_REL;
|
using llvm::ELF::SHT_REL;
|
||||||
using llvm::ELF::SHT_RELA;
|
using llvm::ELF::SHT_RELA;
|
||||||
@@ -60,7 +66,6 @@ static std::string demangle(const std::string &MangledName) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedObject::~SharedObject() {}
|
|
||||||
|
|
||||||
template <typename ELFT>
|
template <typename ELFT>
|
||||||
static std::unique_ptr<SharedObject> createELFSharedObject(
|
static std::unique_ptr<SharedObject> createELFSharedObject(
|
||||||
@@ -68,7 +73,7 @@ static std::unique_ptr<SharedObject> createELFSharedObject(
|
|||||||
return make_unique<ELFSharedObject<ELFT>>(Objfile);
|
return make_unique<ELFSharedObject<ELFT>>(Objfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::unique_ptr<SharedObject>createELFObjFile(const ObjectFile *Obj) {
|
static std::unique_ptr<SharedObject> createELFObjFile(const ObjectFile *Obj) {
|
||||||
if (const ELF32LEObjectFile *Objfile = dyn_cast<ELF32LEObjectFile>(Obj))
|
if (const ELF32LEObjectFile *Objfile = dyn_cast<ELF32LEObjectFile>(Obj))
|
||||||
return createELFSharedObject(Objfile);
|
return createELFSharedObject(Objfile);
|
||||||
if (const ELF32BEObjectFile *Objfile = dyn_cast<ELF32BEObjectFile>(Obj))
|
if (const ELF32BEObjectFile *Objfile = dyn_cast<ELF32BEObjectFile>(Obj))
|
||||||
@@ -81,6 +86,8 @@ static std::unique_ptr<SharedObject>createELFObjFile(const ObjectFile *Obj) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SharedObject::~SharedObject() {}
|
||||||
|
|
||||||
std::unique_ptr<SharedObject> SharedObject::create(const ObjectFile *Obj) {
|
std::unique_ptr<SharedObject> SharedObject::create(const ObjectFile *Obj) {
|
||||||
std::unique_ptr<SharedObject> res(createELFObjFile(Obj));
|
std::unique_ptr<SharedObject> res(createELFObjFile(Obj));
|
||||||
if (res && res->getVTables()) {
|
if (res && res->getVTables()) {
|
||||||
@@ -246,27 +253,38 @@ void ELFSharedObject<ELFT>::relocateSym(
|
|||||||
relativeRelocation(Relocation, Section, Vtablep);
|
relativeRelocation(Relocation, Section, Vtablep);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch(Relocation.getType()) {
|
bool IsAbsoluteRelocation = false;
|
||||||
case R_AARCH64_RELATIVE:
|
bool IsRelativeRelocation = false;
|
||||||
case R_X86_64_RELATIVE:
|
uint32_t RelocationType = Relocation.getType();
|
||||||
case R_ARM_RELATIVE:
|
switch (ElfHeader->e_machine) {
|
||||||
{
|
case EM_ARM:
|
||||||
|
IsAbsoluteRelocation = RelocationType == R_ARM_ABS32;
|
||||||
|
IsRelativeRelocation = RelocationType == R_ARM_RELATIVE;
|
||||||
|
break;
|
||||||
|
case EM_AARCH64:
|
||||||
|
IsAbsoluteRelocation = RelocationType == R_AARCH64_ABS64;
|
||||||
|
IsRelativeRelocation = RelocationType == R_AARCH64_RELATIVE;
|
||||||
|
break;
|
||||||
|
case EM_386:
|
||||||
|
IsAbsoluteRelocation = RelocationType == R_386_32;
|
||||||
|
IsRelativeRelocation = RelocationType == R_386_RELATIVE;
|
||||||
|
break;
|
||||||
|
case EM_X86_64:
|
||||||
|
IsAbsoluteRelocation = RelocationType == R_X86_64_64;
|
||||||
|
IsRelativeRelocation = RelocationType == R_X86_64_RELATIVE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
// The return value is ignored since failure to relocate
|
// The return value is ignored since failure to relocate
|
||||||
// does not mean a fatal error. It might be that the dynsym /
|
// does not mean a fatal error. It might be that the dynsym /
|
||||||
// symbol-table does not have enough information to get the
|
// symbol-table does not have enough information to get the
|
||||||
// symbol name. Like-wise for absolute relocations.
|
// symbol name. Like-wise for absolute relocations.
|
||||||
relativeRelocation(Relocation, Section, Vtablep);
|
if (IsAbsoluteRelocation) {
|
||||||
break;
|
|
||||||
}
|
|
||||||
case R_AARCH64_ABS64:
|
|
||||||
case R_X86_64_64:
|
|
||||||
case R_ARM_ABS32:
|
|
||||||
{
|
|
||||||
absoluteRelocation(Relocation, Vtablep);
|
absoluteRelocation(Relocation, Vtablep);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
default:
|
if (IsRelativeRelocation) {
|
||||||
break;
|
relativeRelocation(Relocation, Section, Vtablep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user