Hello,
I have cross compiled LLVM & Clang (version 10.0.0) to run on RISC-V virtual machine, although it is successfully done generating object file for RISC-V, while running those object file i am getting segmentation fault because of crt0.o file, how can we write custom riscv crt0.S file if any one knows please guide me in the right direction!
crt0.S comes from glibc. If you are trying to write your own, then you are doing something wrong. And the file name is actually called crt1.o. If you are trying to use crt0.o instead of crt1.o you are doing something wrong. You haven’t given any info explaining how you got to this point, how you built the native clang compiler, etc. Busybear is a small buildroot system, not really intended to run compilers. On sw-dev you mentioned using libgloss, which is also wrong. I think you have made so many mistakes getting to this point that I can’t help you unless you explain everything you have done step by step, in sufficient detail so that others can reproduce what you have done, and are willing to start over from scratch. And even then I might not be able to help. Linux compilers are complicated. It takes a fair amount of knowledge about how linux compilers work to be able to successfully cross compile them.
You would be better off running a real distro like fedora or debian. On fedora, you can just dnf install clang. You don’t have to build it unless you want to. And if you do want to build it, you can use known working compilers (clang or gcc) to build it natively.
Also, on a real distro, you can use gdb to debug your code.
My goal is to build a native llvm & clang which runs on RISC-V linux so now i have done cross-compiling LLVM & Clang from Official llvm.org using riscv-gnu-toolchain
Now i got the risc-v target binaries like this:
RISCV2.0/bin$ file clang-10
clang-10: ELF 64-bit LSB executable, UCB RISC-V, version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux-riscv64-lp64d.so.1, for GNU/Linux 4.15.0, not stripped
these binaries will only run on RISC-V linux so I copied these binaries into RISC-V linux and tried to compile a sample program:
sample.c
int main()
{return 0;}
It is compiling successfully when i use clang glibc’s crt0.o (i have cross-compiled glibc to riscv-unknown-linux target)
but i am getting memory error as i mentioned at the start!