Illegal instruction (core dumped)
Illegal instruction is always a bad compile, probably trying to use SHA when the CPU doesn't support it.
Always use -march=native unless it's a new CPU and an old compiler. Your version of GCC is current so it should work for RPi4,
maybe even RPi5. -march=armv8 should also work for RPi4 but it may not be optimum.