I've used the following with gcc
(11.3.0) and clang
(17.0.0) on RISC-V hardware (underlying uarch
of sifive,u74-mc
with isa
of rv64imafdc
) to use uncompressed RISC-V instructions.
hello.S
:
.global main
.data
hello: .asciz "Hello, world!\n"
.text
main:
addi sp,sp,-8
sd ra,0(sp)
la a0,hello
call printf
li a0,0
ld ra,0(sp)
addi sp,sp,8
ret
gcc -march=rv64g -o hello hello.S
or clang -march=rv64g -o hello hello.S
. Verify that your code has uncompressed instructions:
objdump -d -M no-aliases hello
...
0000000000000668 <main>:
668: ff810113 addi sp,sp,-8
66c: 00113023 sd ra,0(sp)
670: 00002517 auipc a0,0x2
674: 9d053503 ld a0,-1584(a0) # 2040 <_GLOBAL_OFFSET_TABLE_+0x8>
678: f29ff0ef jal ra,5a0 <printf@plt>
67c: 00000513 addi a0,zero,0
680: 00013083 ld ra,0(sp)
684: 00810113 addi sp,sp,8
688: 00008067 jalr zero,0(ra)
Two things to note: the instructions are 32-bits wide, and they do not have c.
in front of them.
Finally note that the executable is linked with standard libraries, and those libraries may have been compiled with support of the c
extension. You can confirm this with -M no-aliases
to objdump -D
and instructions that look like c.beqz
, c.addi
, etc.