forked from OSchip/llvm-project
[Mips] Do not hard-code the paired relocation type
Request `getPairRelocation()` function to get paired relocation type. That allows us to look up another pairs like R_MICROMIPS_HI16/LO16 in the future. llvm-svn: 221539
This commit is contained in:
parent
9f31349268
commit
e77029cc5b
|
@ -180,9 +180,10 @@ private:
|
||||||
rit->getType(isMips64EL()), rit->getSymbol(isMips64EL())));
|
rit->getType(isMips64EL()), rit->getSymbol(isMips64EL())));
|
||||||
|
|
||||||
auto addend = readAddend(*rit, secContent);
|
auto addend = readAddend(*rit, secContent);
|
||||||
if (needsMatchingRelocation(*rit)) {
|
auto pairRelType = getPairRelocation(*rit);
|
||||||
|
if (pairRelType != llvm::ELF::R_MIPS_NONE) {
|
||||||
addend <<= 16;
|
addend <<= 16;
|
||||||
auto mit = findMatchingRelocation(rit, eit);
|
auto mit = findMatchingRelocation(pairRelType, rit, eit);
|
||||||
if (mit != eit)
|
if (mit != eit)
|
||||||
addend += int16_t(readAddend(*mit, secContent));
|
addend += int16_t(readAddend(*mit, secContent));
|
||||||
else
|
else
|
||||||
|
@ -219,21 +220,24 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool needsMatchingRelocation(const Elf_Rel &rel) {
|
uint32_t getPairRelocation(const Elf_Rel &rel) {
|
||||||
auto rType = rel.getType(isMips64EL());
|
switch (rel.getType(isMips64EL())) {
|
||||||
if (rType == llvm::ELF::R_MIPS_HI16)
|
case llvm::ELF::R_MIPS_HI16:
|
||||||
return true;
|
return llvm::ELF::R_MIPS_LO16;
|
||||||
if (rType == llvm::ELF::R_MIPS_GOT16) {
|
case llvm::ELF::R_MIPS_GOT16: {
|
||||||
const Elf_Sym *symbol =
|
const Elf_Sym *symbol =
|
||||||
this->_objFile->getSymbol(rel.getSymbol(isMips64EL()));
|
this->_objFile->getSymbol(rel.getSymbol(isMips64EL()));
|
||||||
return symbol->getBinding() == llvm::ELF::STB_LOCAL;
|
if (symbol->getBinding() == llvm::ELF::STB_LOCAL)
|
||||||
|
return llvm::ELF::R_MIPS_LO16;
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
|
return llvm::ELF::R_MIPS_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Elf_Rel_Iter findMatchingRelocation(Elf_Rel_Iter rit, Elf_Rel_Iter eit) {
|
Elf_Rel_Iter findMatchingRelocation(uint32_t pairRelType, Elf_Rel_Iter rit,
|
||||||
|
Elf_Rel_Iter eit) {
|
||||||
return std::find_if(rit, eit, [&](const Elf_Rel &rel) {
|
return std::find_if(rit, eit, [&](const Elf_Rel &rel) {
|
||||||
return rel.getType(isMips64EL()) == llvm::ELF::R_MIPS_LO16 &&
|
return rel.getType(isMips64EL()) == pairRelType &&
|
||||||
rel.getSymbol(isMips64EL()) == rit->getSymbol(isMips64EL());
|
rel.getSymbol(isMips64EL()) == rit->getSymbol(isMips64EL());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue