pwntools icon indicating copy to clipboard operation
pwntools copied to clipboard

Assembly seems to be broken on riscv

Open TethysSvensson opened this issue 1 year ago • 2 comments

I've tried using the asm tool for riscv32 and riscv64 and it doesn't seem to work correctly.

Example:

$ asm -c riscv32 'nop'
[!] Could not find system include headers for riscv32-linux
0100
$ asm -c riscv32 'addi x0, x0, 0'
[!] Could not find system include headers for riscv32-linux
0100
$ asm -c riscv32 'addi x0, x0, 1'
[!] Could not find system include headers for riscv32-linux
13001000
$ asm -c riscv64 'nop'
[!] Could not find system include headers for riscv64-linux
0100
$ asm -c riscv64 'addi x0, x0, 0'
[!] Could not find system include headers for riscv64-linux
0100
$ asm -c riscv64 'addi x0, x0, 1'
[!] Could not find system include headers for riscv64-linux
13001000

Instructions in riscv cannot be only two bytes long.

TethysSvensson avatar Sep 05 '24 08:09 TethysSvensson

See #2419

Arusekk avatar Sep 05 '24 15:09 Arusekk

My bad, it seems like I don't know riscv very well at all.

Still, I don't think asm produce assembly that only works on processors with the C extension, unless explicitly enabled.

TethysSvensson avatar Sep 06 '24 05:09 TethysSvensson

Still, I don't think asm produce assembly that only works on processors with the C extension, unless explicitly enabled.

All existing riscv64 chips designed to run Linux have the C extension, and main Linux distributions (Debian, Ubuntu, Fedora, Arch Linux...) all use rv64gc as their baseline. I think including the C extension by default is reasonable.

Xeonacid avatar Oct 22 '24 13:10 Xeonacid

As far as I remember, I was not targeting a Linux system at the time.

TethysSvensson avatar Oct 23 '24 04:10 TethysSvensson