Which arch and abi?
I'm trying to reproduce the .s files on macOS, using brew install riscv-tools (and without Docker). This requires manually specifying the arch and abi.
I think I got pretty close with:
riscv64-unknown-elf-gcc -march=rv32im -mabi=ilp32 -S multiply_loop.c
(probably don't meed the m extension?)
But there's still a small diff:
diff --git a/examples/multiply_loop.s b/examples/multiply_loop.s
index 29eb694..6059416 100644
--- a/examples/multiply_loop.s
+++ b/examples/multiply_loop.s
@@ -9,7 +9,8 @@
.type runcontract, @function
runcontract:
addi sp,sp,-48
- sw s0,44(sp)
+ sw ra,44(sp)
+ sw s0,40(sp)
addi s0,sp,48
sw a0,-36(s0)
sw zero,-20(s0)
@@ -27,8 +28,10 @@ runcontract:
ble a4,a5,.L3
lw a5,-36(s0)
mv a0,a5
- lw s0,44(sp)
+ lw ra,44(sp)
+ lw s0,40(sp)
addi sp,sp,48
jr ra
.size runcontract, .-runcontract
- .ident "GCC: () 13.2.0"
+ .ident "GCC: (g04696df09) 14.2.0"
+ .section .note.GNU-stack,"",@progbits
Maybe that's a result of gcc 14?
But I guess in a "real world" scenario this would lead to incompatible taptrees?
It reminds me of how back in the day (still?) you could upload a piece of Solidity code to Etherscan and if you specified the exact compiler version, it could verify that the binary smart contract matched the source.
Can make it even shorter by compiling with -O, which figures out that you can just do a single left shift (slli a0,a0,8).
Yes, you have to agree exactly on the resulting binary (ELF) in order to get compatible taptrees. My guess for why we get a diff is because of slightly different GCC versions and arch/abi as you are saying.
I used riscv32-unknown-elf-gcc compiled with --with-arch=rv32ia --with-abi=ilp32 as seen here: https://github.com/halseth/docker-riscv/commit/48adf83a61780d39887ffcbf9a47d99ed4b79c0e
Maybe check what you get using that specified? 😄
agree exactly on the resulting binary (ELF) in order to get compatible taptrees
Sounds like the perfect use case for a Guix build.
I'll give your config a try.
-march=rv32ia -mabi=ilp32 makes no difference. So it's probably the newer GCC version.