I'm trying to link two risc-v elf files together with ld.lld
, but ld.lld
is giving me the following error:
ld.lld: error: undefined symbol: __divdi3
I suppose that I need to link my files with some helper functions, but after looking for it in my clang lib folder (/usr/local/Cellar/llvm/15.0.6/lib/clang/15.0.6/lib
), but in the directory, there is only a folder for darwin, as you can see here:
.
└── darwin
├── libclang_rt.asan_osx_dynamic.dylib
├── libclang_rt.cc_kext.a
├── libclang_rt.fuzzer_interceptors_osx.a
[more]
├── libclang_rt.xray-profiling_osx.a
└── libclang_rt.xray_osx.a
So does anyone know how should I fix this link error/get the rv64i helper functions?
Thanks!
Edit: Here are the commands that I used:
/usr/local/Cellar/llvm/15.0.6/bin/clang --target=riscv64 -march=rv64i -fno-builtin -nostdlib -ffreestanding -Wall -Wextra -Wwrite-strings -Wstrict-prototypes -pedantic -c -o build/main.o bios/main.c
riscv64-unknown-elf-as -march=rv64i -o build/start.o src/start.S
/usr/local/Cellar/llvm/15.0.6/bin/ld.lld -T link.ld -O2 -nostdlib --oformat=binary -o output.bin build/main.o build/start.o
You can get a copy of the source of the functions in libgcc here: https://github.com/gcc-mirror/gcc/tree/releases/gcc-12/libgcc/config/riscv Just copy them and place them in your source and they will compile for whatever arch your compiling for
The function __divdi3
is in the div.c file