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
__divdi3
is as a routine from the compiler supporting library. In case of gcc it is called libgcc
, in case of clang it's compiler-rt
. You need to have compiler-rt
built from the architecture in question (RISC-V) and make it available to compiler via eg sysroot or something similar (or link explicitly).
Alternatively, just do not use 64-bit division in your program, so the call will not be generated:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.