Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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 e.g. 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 :)
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.