capstone icon indicating copy to clipboard operation
capstone copied to clipboard

arm: Sign of immediate is unclear

Open akihikodaki opened this issue 2 years ago • 1 comments

This issue was found during the discussion at: https://github.com/capstone-engine/capstone/pull/771#issuecomment-1594586622

Some instructions interpret immediates as signed while the others interpret them as unsigned. However, the imm member of cs_arm_op is typed as signed, which causes two problems:

  • PC-relative addresses overflow when storing if the address is more than INT32_MAX as they are computed as unsigned.
  • The code reading the imm member of cs_arm_op may incorrectly think it is signed when it should be treated as unsigned.

It will be nice if we can change how to store and load immediate values in cs_arm_op depending on instructions.

akihikodaki avatar Jun 22 '23 08:06 akihikodaki

Just as a note. LLVM saves immediate values in general as int64_t. We can think about doing just that. So we mimic LLVM as close as possible.

Rot127 avatar Jun 22 '23 10:06 Rot127