[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 14:42:05 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG954ba6045dd5: [BPF] Emit fatal error if out of range for FK_PCRel_2 branch target (authored by yonghong-song).

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.423742.patch
Type: text/x-patch
Size: 652 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220419/fa540570/attachment.bin>


More information about the llvm-commits mailing list