Closed RRArinc closed 2 months ago
Where did you get or how did you configure and build the toolchain that you're using?
What is the riscv32-unknown-elf-gcc
command line that you're using to compile the code above?
I grabbed the latest RV32 bare-metal toolchain and compiled and linked a version of the code above without any issues:
wget https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2024.08.06/riscv32-elf-ubuntu-22.04-gcc-nightly-2024.08.06-nightly.tar.gz
tar xzvf riscv32-elf-ubuntu-22.04-gcc-nightly-2024.08.06-nightly.tar.gz
cd riscv/bin
vi test.c
# test.c
#include <math.h>
int main()
{
double num = 110.00;
double result = 0.0;
result = round(num);
}
./riscv32-unknown-elf-gcc test.c -lm
file a.out
a.out: ELF 32-bit LSB executable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), statically linked, not stripped
./riscv32-unknown-elf-objdump -dS a.out
...
00010144 <main>:
10144: 1101 addi sp,sp,-32
10146: ce06 sw ra,28(sp)
10148: cc22 sw s0,24(sp)
1014a: 1000 addi s0,sp,32
1014c: 67c5 lui a5,0x11
1014e: 6887b787 fld fa5,1672(a5) # 11688 <__errno+0xa>
10152: fef43427 fsd fa5,-24(s0)
10156: d20007d3 fcvt.d.w fa5,zero
1015a: fef43027 fsd fa5,-32(s0)
1015e: fe843507 fld fa0,-24(s0)
10162: 2809 jal 10174 <round>
10164: fea43027 fsd fa0,-32(s0)
10168: 4781 li a5,0
1016a: 853e mv a0,a5
1016c: 40f2 lw ra,28(sp)
1016e: 4462 lw s0,24(sp)
10170: 6105 addi sp,sp,32
10172: 8082 ret
...
Hi, Yeah u r right i am able compile the code using riscv32-unknown-elf-gcc.
My question I have linker script and Make file. When compiled with riscv32-unknown-elf-gcc code compiles.
But if i use riscv32-unknow-elf-ld to link the linker script (*.ld) and starup.S file. I ran into below error
riscv32-unknown-elf-ld: /home/rr/rv32gcc-toolchain/riscv32-unknown-elf/lib/rv32i/ilp32//libm.a(libm_a-s_round.o): in function round': s_round.c:(.text.round+0xb8): undefined reference to __adddf3' make: *** [Makefile:40: bin/output] Error 1
It appears to be something softfloat issue it says in function s_round.c undefined reference to __addf3
I also check which libm.s is used by riscv32-unknown-elf-gcc and provided the same lib path to riscv32-unknown-elf-ld, and got the above error.
So question is it compiles well with riscv32-unknown-elf-gcc but fails with riscv32-unknown-elf-ld.
what could be the root cause.
what could be the root cause.
Impossible to say when you don't provide the reproducible test case and clear instructions on how to reproduce it.
And vague/unclear statements like this don't really help to clarify matters:
It appears to be something softfloat issue it says in function s_round.c undefined reference to __addf3
Hi, I was able to figure out the issue.
The linker was not able find the right soft-float libm.a
The path above was misleading in Makefile. After updating the absolute path in Makefile it started compiling the program.
Thank you very much.
Hi, I have sample code which uses library.
I have linker script and Make file. When compiled with riscv32-unknown-elf-gcc code compiles. But when compiled with riscv32-unknown-elf-ld ends up with error
riscv32-unknown-elf-ld: /home/rr/rv32gcc-toolchain/riscv32-unknown-elf/lib/rv32i/ilp32//libm.a(libm_a-s_round.o): in function
round': s_round.c:(.text.round+0xb8): undefined reference to
__adddf3' make: *** [Makefile:40: bin/output] Error 1Here riscv32-unknown-elf-ld is provided with libm.a reference to link, but still it fails.
source file is
include
void operation(void) { double num = 110.00; double result = 0.0;
}
Thanks