[llvm] f9b5f69 - [JITLink][ELF/x86-64] Range check 32-bit relocs.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 21 20:59:58 PST 2021
Author: Lang Hames
Date: 2021-01-22T15:59:19+11:00
New Revision: f9b5f6937ebed5dccabfc3c287f11d18b68a36f6
URL: https://github.com/llvm/llvm-project/commit/f9b5f6937ebed5dccabfc3c287f11d18b68a36f6
DIFF: https://github.com/llvm/llvm-project/commit/f9b5f6937ebed5dccabfc3c287f11d18b68a36f6.diff
LOG: [JITLink][ELF/x86-64] Range check 32-bit relocs.
Also switch to using little_<b> / ulittle_<b> types to write results for
consistency with MachO.
Added:
Modified:
llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
index 30366a82a043..244975f4a51a 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
@@ -670,6 +670,17 @@ class ELFJITLinker_x86_64 : public JITLinker<ELFJITLinker_x86_64> {
return getELFX86RelocationKindName(R);
}
+ static Error targetOutOfRangeError(const Block &B, const Edge &E) {
+ std::string ErrMsg;
+ {
+ raw_string_ostream ErrStream(ErrMsg);
+ ErrStream << "Relocation target out of range: ";
+ printEdge(ErrStream, B, E, getELFX86RelocationKindName(E.getKind()));
+ ErrStream << "\n";
+ }
+ return make_error<JITLinkError>(std::move(ErrMsg));
+ }
+
Error applyFixup(Block &B, const Edge &E, char *BlockWorkingMem) const {
using namespace ELF_x86_64_Edges;
using namespace llvm::support;
@@ -681,12 +692,15 @@ class ELFJITLinker_x86_64 : public JITLinker<ELFJITLinker_x86_64> {
case ELFX86RelocationKind::PCRel32:
case ELFX86RelocationKind::PCRel32GOTLoad: {
int64_t Value = E.getTarget().getAddress() + E.getAddend() - FixupAddress;
- endian::write32le(FixupPtr, Value);
+ if (Value < std::numeric_limits<int32_t>::min() ||
+ Value > std::numeric_limits<int32_t>::max())
+ return targetOutOfRangeError(B, E);
+ *(little32_t *)FixupPtr = Value;
break;
}
case ELFX86RelocationKind::Pointer64: {
int64_t Value = E.getTarget().getAddress() + E.getAddend();
- endian::write64le(FixupPtr, Value);
+ *(ulittle64_t *)FixupPtr = Value;
break;
}
}
More information about the llvm-commits
mailing list