This patch adds a driver for the baremetal RISC-V target (i.e. riscv32-unknown-elf). For reference, D39963 added basic target info and added support for riscv32-linux-unknown-elf.
Patch by: asb (Alex Bradbury)
Differential D46822
[RISCV] Add driver for riscv32-unknown-elf baremetal target asb on May 14 2018, 2:36 AM. Authored by
Details This patch adds a driver for the baremetal RISC-V target (i.e. riscv32-unknown-elf). For reference, D39963 added basic target info and added support for riscv32-linux-unknown-elf. Patch by: asb (Alex Bradbury)
Diff Detail
Event TimelineComment Actions Could you include some documentation for how to construct a baremetal environment like the one this code expects? It's not clear what exactly you expect to be installed where. Comment Actions Thanks for taking a look Eli. Building gcc+binutils+newlib will spit out a directory tree with the expected setup. e.g. a while ago I wrote a blog post trying to show how to build upstream RISC-V gcc+binutils+newlib in the simplest way possible. You need a multistage build for C++ support and other features, but those instructions are enough to get a baremetal cross compiler. The directory layout is the same as if you use the build script in the riscv-gnu-toolchain repo, doing ./configure --prefix=/my/target/path --with-arch=rv32i --with-abi=ilp32; make -j$(nproc). This is a more advanced multi-stage build. Would you like to see more information on this added to the commit message, as comments in the code, or elsewhere? e.g. this is the directory listing of the build output if you follow the linked blog instructions: https://pastebin.com/8HeCMpxF Comment Actions LGTM.
Comment Actions Please don't commit patches on behalf of someone else if the author hasn't specifically requested it. There might be some issue which the author forgot to note on the review. Comment Actions It seems the ability to link objects has been broken by this change. As an example from our nightly tests: Executing on host: riscv32-unknown-elf-clang /data/jenkins/workspace/riscv32-llvm-gcc/gcc-tests/gcc/testsuite/gcc.c-torture/execute/20080502-1.c -march=rv32gc -mabi=ilp32 -O1 -w -lm -o ./20080502-1.exe (timeout = 600) spawn -ignore SIGHUP riscv32-unknown-elf-clang /data/jenkins/workspace/riscv32-llvm-gcc/gcc-tests/gcc/testsuite/gcc.c-torture/execute/20080502-1.c -march=rv32gc -mabi=ilp32 -O1 -w -lm -o ./20080502-1.exe /data/jenkins/workspace/riscv32-llvm-gcc/install/bin/riscv32-unknown-elf-ld: cannot find crt0.o: No such file or directory clang-8: error: ld command failed with exit code 1 (use -v to see invocation) compiler exited with status 1 FAIL: gcc.c-torture/execute/20080502-1.c -O1 (test for excess errors) Running with -v shows the link command as: "/data/jenkins/workspace/riscv32-llvm-gcc/install/bin/riscv32-unknown-elf-ld" crt0.o /data/jenkins/workspace/riscv32-llvm-gcc/install/bin/../lib/gcc/riscv32-unknown-elf/8.1.0/crtbegin.o -L/lib -L/data/jenkins/workspace/riscv32-llvm-gcc/install/bin/../lib/gcc/riscv32-unknown-elf/8.1.0 /tmp/20080502-1-2b0022.o -lm --start-group -lc -lgloss --end-group -lgcc /data/jenkins/workspace/riscv32-llvm-gcc/install/bin/../lib/gcc/riscv32-unknown-elf/8.1.0/crtend.o -o ./20080502-1.exe What's noticeable is crt0.o is specified just as a file, and we're trying to link in my host /lib/ (-L/lib)? If I manually specify a sysroot (via --sysroot=$INSTALLDIR/riscv32-unknown-elf), then my link succeeds, adding the path to crt0.o, and the correct /lib: "/data/jenkins/workspace/riscv32-llvm-gcc/install/bin/riscv32-unknown-elf-ld" --sysroot=/data/jenkins/workspace/riscv32-llvm-gcc/install/riscv32-unknown-elf /data/jenkins/workspace/riscv32-llvm-gcc/install/riscv32-unknown-elf/lib/crt0.o /data/jenkins/workspace/riscv32-llvm-gcc/install/bin/../lib/gcc/riscv32-unknown-elf/8.1.0/crtbegin.o -L/data/jenkins/workspace/riscv32-llvm-gcc/install/riscv32-unknown-elf/lib -L/data/jenkins/workspace/riscv32-llvm-gcc/install/bin/../lib/gcc/riscv32-unknown-elf/8.1.0 /tmp/20080502-1-d53be0.o -lm --start-group -lc -lgloss --end-group -lgcc /data/jenkins/workspace/riscv32-llvm-gcc/install/bin/../lib/gcc/riscv32-unknown-elf/8.1.0/crtend.o -o ./20080502-1.exe I think there's some missing calculate the correct sysroot directory logic missing, unless linking clang to riscv32-unknown-elf-clang is no longer sufficient for everything to work now? |
Alphabetically riscv32-unknown-elf should be the first in the list of triples.