[PATCH] D123877: [BPF] Emit fatal error if out of range for FK_PCRel_2 branch target
Yonghong Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 19 13:23:04 PDT 2022
yonghong-song updated this revision to Diff 423720.
yonghong-song retitled this revision from "[BPF] Add assert for the range of FK_PCRel_2 branch target" to "[BPF] Emit fatal error if out of range for FK_PCRel_2 branch target".
yonghong-song edited the summary of this revision.
yonghong-song added a comment.
- use report_fatal_error instead of assert.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D123877/new/
https://reviews.llvm.org/D123877
Files:
llvm/lib/Target/BPF/MCTargetDesc/BPFAsmBackend.cpp
Index: llvm/lib/Target/BPF/MCTargetDesc/BPFAsmBackend.cpp
===================================================================
--- llvm/lib/Target/BPF/MCTargetDesc/BPFAsmBackend.cpp
+++ llvm/lib/Target/BPF/MCTargetDesc/BPFAsmBackend.cpp
@@ -87,6 +87,11 @@
}
} else {
assert(Fixup.getKind() == FK_PCRel_2);
+
+ int64_t ByteOff = (int64_t)Value - 8;
+ if (ByteOff > INT16_MAX * 8 || ByteOff < INT16_MIN * 8)
+ report_fatal_error("Branch target out of insn range");
+
Value = (uint16_t)((Value - 8) / 8);
support::endian::write<uint16_t>(&Data[Fixup.getOffset() + 2], Value,
Endian);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123877.423720.patch
Type: text/x-patch
Size: 652 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220419/7fe6d713/attachment.bin>
More information about the llvm-commits
mailing list