Skip to content

RISC-V: Add support for 2-byte c.ebreak, as 4-byte breakpoint sometimes causes OOB

Mateusz requested to merge bieganski/ltrace:riscv-compressed-support into main

The issue was already reported to glibc, but as maintainers rightly said, the scope of the issue is not limited to dynamic linker, and should be rather fixed on the ltrace side.

The original ticket can be found here.

I implemented the suggested solution - We decode original instruction, see whether it is compressed or not and either insert 2 or 4 byte long breakpoint.

How was this tested?

it was tested against version compiled in the same way on a main branch. Both binaries were cross-compiled to rv64gc architecture. The test case was ltrace /bin/nm /bin/nm, that is causing a SIGILL on a main branch and works fine with commit introduced by that MR. The SIGILL was happening in ld.so, in _dl_debug_state function (that is empty, and is containing only 2-byte compressed c.ret instruction. Rigth after _dl_debug_state there is a _dl_debug_update function, with first instruction overwritten by a 4-byte breakpoint, causing any jump to that function raising Illegal Instruction.

Edited by Mateusz

Merge request reports