Help with the riscv-linux compiler

642 views
Skip to first unread message

Rafael

unread,
Mar 19, 2018, 5:11:59 PM3/19/18
to riscv-boom
Hi all,

So, I've recently generated the linux cross-compiler from the latest commit in the BOOM repository.
In order to build the compiler, I did not just run the ./scripts/build-tools.sh script as recommended. Instead, I fallowed the instructions in boom-template/rocket-chip/riscv-tools/riscv-gnu-toolchain/README.md file (the Installation (Linux) section). In order to build it, I run make linux. It took about one hour and a half to generate the tools.

The problem is that when I compile any application in the top of pk (let's say I run riscv64-unknown-linux-gnu-gcc hello.c -o hello.out), I cannot run it on spike, therefore it won't work with BOOM. When I try spike pk hello.out I get the message "../pk/elf.c:46: assertion failed: !(eh.e_flags & EF_RISCV_RVC)". I assume a got the wrong version of the binary? (even though I got it from the BOOM repository, by cloning the BOOM template). 

Thank you a lot in advance.
 

Christopher Celio

unread,
Mar 19, 2018, 5:56:06 PM3/19/18
to riscv-boom
That looks like a RVC-related error. So some thing(s) got built and is generating (or trying to execute) the wrong ISA.

The scripts/build-tools.sh should build a riscv-isa-sim/spike that will -- by default -- only execute RV64G ("aka, spike --isa=RV64IMAFD").  You can try and change the --isa string passed to spike to see if that affects whether your hello.out runs or not. "spike" with no arguments will print a help message that tells you what it is expecting as the default. You can also use "riscv...gcc --help=target -Q" to see what its defaults are too.


Let me know what works and doesn't so I can add a script for building a Linux/glibc compiler.


-Chris

Rafael

unread,
Mar 20, 2018, 11:36:12 AM3/20/18
to riscv-boom
So the output of riscv...gcc --help=target -Q tells me that the supported architecture is rv64imafdc, but I guess that does't mean the compiler will only support the compressed RISC-V, right?

Even if I compile the application with riscv64-unknown-linux-gnu-gcc -march=rv64imafd hello.c, I cannot run the binary output on spike (even using the --isa=RV64IMAFD) flag.

The complete compiler info is:

The following options are target specific:
  -mabi=                              lp64d
  -march=                             rv64imafdc
  -mbionic                            [disabled]
  -mbranch-cost=N                     0
  -mcmodel=                           medlow
  -mdiv                               [disabled]
  -mexplicit-relocs                   [disabled]
  -mfdiv                              [disabled]
  -mglibc                             [enabled]
  -mmusl                              [disabled]
  -mplt                               [enabled]
  -msave-restore                      [disabled]
  -msmall-data-limit=N                8
  -mstrict-align                      [disabled]
  -mtune=PROCESSOR                   
  -muclibc                            [disabled]The following options are target specific:
  -mabi=                              lp64d
  -march=                             rv64imafdc
  -mbionic                            [disabled]
  -mbranch-cost=N                     0
  -mcmodel=                           medlow
  -mdiv                               [disabled]
  -mexplicit-relocs                   [disabled]
  -mfdiv                              [disabled]
  -mglibc                             [enabled]
  -mmusl                              [disabled]
  -mplt                               [enabled]
  -msave-restore                      [disabled]
  -msmall-data-limit=N                8
  -mstrict-align                      [disabled]
  -mtune=PROCESSOR                   
  -muclibc                            [disabled]

  Supported ABIs (for use with the -mabi= option):
    ilp32 ilp32d ilp32f lp64 lp64d lp64f

  Supported ABIs (for use with the -mabi= option):
    ilp32 ilp32d ilp32f lp64 lp64d lp64f

Christopher Celio

unread,
Mar 20, 2018, 2:36:18 PM3/20/18
to riscv-boom
The problem is if you built your riscv-gnu-toolchain without configuring the build with ("--with-arch=rv64imafd") then you'll end up with a standard library (newlib/glibc) that has compressed. And also your riscv-pk would be compiled with compressed too.  So " riscv64-unknown-linux-gnu-gcc -march=rv64imafd hello.c" isn't enough.

-Chris

Rafael

unread,
Mar 20, 2018, 2:51:53 PM3/20/18
to riscv-boom
So I've just rebuilt the tools by configuring  with ("--with-arch=rv64imafd"). It still doesn't work prob. cuz I haven't rebuild the riscv-pk, as you mentioned.
Should I ALSO build the pk with riscv64-unknown-linux-gnu-gcc? Or can I just use riscv64-unknown-elf-gcc?

I mean, should I change the CC= CXX= build_project riscv-pk --prefix=$RISCV --host=riscv64-unknown-elf line in the riscv-tools/build.sh script? I have both the linux and newlib toolchain installed in different directories (which I just found out to be a bad idea, as I'll have to change the RISCV env. variable), so I just don't want to mess things up before I'm sure about the procedures.

Christopher Celio

unread,
Mar 20, 2018, 2:58:25 PM3/20/18
to riscv-boom
My process in the past has been to use the scripts/build-tools.sh which will generate a riscv-tools/build-rv64g.sh script which will then compile a full complement of spike/riscv-pk/newlib+riscv-unknown-elf-gcc for RV64G. Then I manually go into riscv-gnu-toolchain/build and perform a glibc/linux build. I'll try and put together a script for this when I get a chance.

If you try to use riscv-linux-gcc to compile riscv-pk, I'm not sure what will happen! If I recall correctly, riscv64-unknown-elf-gcc will compile a -static binary, use newlib (so a simpler/smaller set of syscalls), and possibly put the binary at a different starting address. None of that may matter for riscv-pk since it's Makefile will override the standard build flags (-static -nostdlib, etc.) ... or maybe it will be subtly different and not work!


-Chris

Rafael

unread,
Mar 20, 2018, 4:23:19 PM3/20/18
to riscv-boom
A have changed the /scripts/build-tools.sh. I've updated the host parameter to look like --host=riscv64-unknown-linux-gnu for the pk,  and deleted the copy of that script in riscv-tools before starting the build process (as it is only crated in case it doesn't exist).

I can build both spike and the proxy kernel (with the riscv64-unknown-linux-gnu-gcc compiler supporting the imafd extension (no compression)) , but still a get the same error. The object dump of the pk has a line written "file format elf64-littleriscv", I assume the pk is being compiled with RVC? Notice, that I can compile bare metal application with that compiler an run it on spike, so the problem is the proxy kernel. I guess I'll have to rebuild the whole thing from scratch (including the gnu compiler).

Anyway, thanks for your help. 'll report any progress I get.
Reply all
Reply to author
Forward
0 new messages