[llvm] 43c5fff - Revert "[JITLink] Add fixup value range check"
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 4 08:04:41 PST 2022
Author: luxufan
Date: 2022-01-05T00:04:09+08:00
New Revision: 43c5fffcef5c1022c189a13c41dbdd2d653d59dd
URL: https://github.com/llvm/llvm-project/commit/43c5fffcef5c1022c189a13c41dbdd2d653d59dd
DIFF: https://github.com/llvm/llvm-project/commit/43c5fffcef5c1022c189a13c41dbdd2d653d59dd.diff
LOG: Revert "[JITLink] Add fixup value range check"
This reverts commit 17af06ba8005d6d14b0ac79ece01ecb028de9f90.
Added:
Modified:
llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
index 94b659c02092a..26ec79ea50cf9 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
@@ -161,15 +161,6 @@ static uint32_t extractBits(uint32_t Num, unsigned Low, unsigned Size) {
return (Num & (((1ULL << (Size + 1)) - 1) << Low)) >> Low;
}
-static inline bool isInRangeForImmS32(int64_t Value) {
- return (Value >= std::numeric_limits<int32_t>::min() &&
- Value <= std::numeric_limits<int32_t>::max());
-}
-
-static inline bool isInRangeForImmU32(uint64_t Value) {
- return Value <= std::numeric_limits<uint32_t>::max();
-}
-
class ELFJITLinker_riscv : public JITLinker<ELFJITLinker_riscv> {
friend class JITLinker<ELFJITLinker_riscv>;
@@ -198,18 +189,14 @@ class ELFJITLinker_riscv : public JITLinker<ELFJITLinker_riscv> {
break;
}
case R_RISCV_HI20: {
- uint64_t Value = E.getTarget().getAddress() + E.getAddend();
- if (LLVM_UNLIKELY(!isInRangeForImmU32(Value)))
- return makeTargetOutOfRangeError(G, B, E);
+ int64_t Value = E.getTarget().getAddress() + E.getAddend();
int32_t Hi = (Value + 0x800) & 0xFFFFF000;
uint32_t RawInstr = *(little32_t *)FixupPtr;
*(little32_t *)FixupPtr = (RawInstr & 0xFFF) | static_cast<uint32_t>(Hi);
break;
}
case R_RISCV_LO12_I: {
- uint64_t Value = E.getTarget().getAddress() + E.getAddend();
- if (LLVM_UNLIKELY(!isInRangeForImmU32(Value)))
- return makeTargetOutOfRangeError(G, B, E);
+ int64_t Value = E.getTarget().getAddress() + E.getAddend();
int32_t Lo = Value & 0xFFF;
uint32_t RawInstr = *(little32_t *)FixupPtr;
*(little32_t *)FixupPtr =
@@ -218,8 +205,6 @@ class ELFJITLinker_riscv : public JITLinker<ELFJITLinker_riscv> {
}
case R_RISCV_CALL: {
int64_t Value = E.getTarget().getAddress() + E.getAddend() - FixupAddress;
- if (LLVM_UNLIKELY(!isInRangeForImmS32(Value)))
- return makeTargetOutOfRangeError(G, B, E);
int32_t Hi = (Value + 0x800) & 0xFFFFF000;
int32_t Lo = Value & 0xFFF;
uint32_t RawInstrAuipc = *(little32_t *)FixupPtr;
@@ -231,8 +216,6 @@ class ELFJITLinker_riscv : public JITLinker<ELFJITLinker_riscv> {
}
case R_RISCV_PCREL_HI20: {
int64_t Value = E.getTarget().getAddress() + E.getAddend() - FixupAddress;
- if (LLVM_UNLIKELY(!isInRangeForImmS32(Value)))
- return makeTargetOutOfRangeError(G, B, E);
int32_t Hi = (Value + 0x800) & 0xFFFFF000;
uint32_t RawInstr = *(little32_t *)FixupPtr;
*(little32_t *)FixupPtr = (RawInstr & 0xFFF) | static_cast<uint32_t>(Hi);
@@ -244,8 +227,6 @@ class ELFJITLinker_riscv : public JITLinker<ELFJITLinker_riscv> {
return RelHI20.takeError();
int64_t Value = RelHI20->getTarget().getAddress() +
RelHI20->getAddend() - E.getTarget().getAddress();
- if (LLVM_UNLIKELY(!isInRangeForImmS32(Value)))
- return makeTargetOutOfRangeError(G, B, E);
int64_t Lo = Value & 0xFFF;
uint32_t RawInstr = *(little32_t *)FixupPtr;
*(little32_t *)FixupPtr =
@@ -256,8 +237,6 @@ class ELFJITLinker_riscv : public JITLinker<ELFJITLinker_riscv> {
auto RelHI20 = getRISCVPCRelHi20(E);
int64_t Value = RelHI20->getTarget().getAddress() +
RelHI20->getAddend() - E.getTarget().getAddress();
- if (LLVM_UNLIKELY(!isInRangeForImmS32(Value)))
- return makeTargetOutOfRangeError(G, B, E);
int64_t Lo = Value & 0xFFF;
uint32_t Imm31_25 = extractBits(Lo, 5, 7) << 25;
uint32_t Imm11_7 = extractBits(Lo, 0, 5) << 7;
diff --git a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
index 32897e32bc9f1..539da2b1e81dc 100644
--- a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
+++ b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_pc_indirect.s
@@ -4,11 +4,11 @@
# RUN: llvm-mc -triple=riscv32 -position-independent -filetype=obj \
# RUN: -o %t/elf_riscv32_sm_pic_reloc.o %s
# RUN: llvm-jitlink -noexec \
-# RUN: -slab-allocate 100Kb -slab-address 0x1ff00000 -slab-page-size 4096 \
+# RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
# RUN: -define-abs external_func=0x1 -define-abs external_data=0x2 \
# RUN: -check %s %t/elf_riscv64_sm_pic_reloc.o
# RUN: llvm-jitlink -noexec \
-# RUN: -slab-allocate 100Kb -slab-address 0x1ff00000 -slab-page-size 4096 \
+# RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
# RUN: -define-abs external_func=0x1 -define-abs external_data=0x2 \
# RUN: -check %s %t/elf_riscv32_sm_pic_reloc.o
#
More information about the llvm-commits
mailing list