ucb-bar / esp-llvm

UCB-BAR fork of LLVM! NOT UPSTREAM RISCV LLVM
Other
123 stars 55 forks source link

hello.c compilation error #39

Open nitish2112 opened 7 years ago

nitish2112 commented 7 years ago

I am having this issue while compiling hello.c. I tried the solution mentioned in the other issue as well. Please see the compilation results below:

PS: I noticed that I did not have riscv-elf folder in my /opt/riscv folder which has all the the standard libraries. What is wrong with the installation. I followed the steps here: https://riscv.org/software-tools/low-level-virtual-machine-llvm/

Compilation Results: % clang -target riscv64 -mriscv=RV64IAMFD -S hello.c -o hello.S

gives: In file included from hello.c:1: In file included from /usr/include/stdio.h:27: /usr/include/features.h:367:12: fatal error: 'sys/cdefs.h' file not found

include

^ 1 error generated.

% clang -target riscv -mriscv=RV64IAMFD -nostdinc -I/opt/riscv/riscv-elf/include -I/opt/riscv/lib/clang/3.9.0/include -S hello.c -o hello.S

gives: hello.c:1:10: fatal error: 'stdio.h' file not found

include

^ 1 error generated.

and % clang -target riscv64 -mriscv=RV64IAMFD -nostdinc -I/opt/riscv/riscv-elf/include -I/opt/riscv/lib/clang/3.9.0/include -S hello.c -o hello.S

gives: hello.c:1:10: fatal error: 'stdio.h' file not found

include

^ 1 error generated.

hirooih commented 7 years ago

I know this project is not active, but I'd like to share a result of my experiment.

The option --sysroot=XXX changes the system root (normally /usr), and ${target}-clang let clang look for ${target}-as/ld/gcc.

See the following links for more details; http://clang.llvm.org/docs/CrossCompilation.html http://clang-developers.42468.n3.nabble.com/ccc-gcc-name-equivalent-to-call-as-and-ld-directly-td3076391.html

Thus if you installed riscv-tools under /opt/riscv, you can compile files only by clang as follows.

$ RISCV=/opt/riscv
$ mkdir $RISCV/r64
$ ln -s ../riscv64-unknown-elf $RISCV/r64/usr
$ ln -s clang $RISCV/bin/riscv64-unknown-elf-clang

Now I can do;

$ riscv64-unknown-elf-clang --sysroot=/opt/riscv/r64 hello.c
$ spike pk a.out
Hello world!
$ 

On the other hand, clang in this repository looks for risc-unknown-elf- instead of risc32-unknown-elf- for RV32I.

Here is my fixes for this issue.

riscv-clang.patch.txt riscv-llvm.patch.txt

With this fix now I can run dhrystone on my Sifive Hifive board. Note that you need a symbolic link for this.

$ cd .../freedom-e-sdk/toolchain/bin
$ ln -s $RISCV/bin/clang riscv32-unknown-elf-clang