compiler-explorer / compiler-explorer

Run compilers interactively from your web browser and interact with the assembly
https://godbolt.org/
BSD 2-Clause "Simplified" License
15.59k stars 1.66k forks source link

[BUG]: RISC-V GCC > 12.1.0 missing ilp32 #6648

Open cnlohr opened 5 days ago

cnlohr commented 5 days ago

Describe the bug

When compiling for non-D targets of RISC-V GCC on version on godbolt of newer than 12.1.0, the compiler is missing ilp32 ABIs, required for most microcontrollers.

This is likely because GCC may not be being built with full RISC-V support.

Steps to reproduce

  1. Visit goldbolt.org
  2. Select RISC-V (32-bits) gcc 13.3.0
  3. Select C language
  4. Use the following command-line: -g -Os -march=rv32imac -mabi=ilp32
  5. Get the following error:
In file included from /opt/compiler-explorer/riscv32/gcc-13.3.0/riscv32-unknown-linux-gnu/riscv32-unknown-linux-gnu/sysroot/usr/include/features.h:515,
                 from /opt/compiler-explorer/riscv32/gcc-13.3.0/riscv32-unknown-linux-gnu/riscv32-unknown-linux-gnu/sysroot/usr/include/bits/libc-header-start.h:33,
                 from /opt/compiler-explorer/riscv32/gcc-13.3.0/riscv32-unknown-linux-gnu/riscv32-unknown-linux-gnu/sysroot/usr/include/stdio.h:27,
                 from <source>:4:
/opt/compiler-explorer/riscv32/gcc-13.3.0/riscv32-unknown-linux-gnu/riscv32-unknown-linux-gnu/sysroot/usr/include/gnu/stubs.h:8:11: fatal error: gnu/stubs-ilp32.h: No such file or directory
    8 | # include <gnu/stubs-ilp32.h>
      |           ^~~~~~~~~~~~~~~~~~~
compilation terminated.
Compiler returned: 1

Expected behavior

Expected program to compile normally, as it does on older GCC versions.

Reproduction link

https://godbolt.org/z/G6jrWW6W3

Screenshots

Not applicable

Operating System

N/A

Browser version

N/A

dkm commented 5 days ago

Any idea what flags is missing when configuring gcc? I'll have a look, but any hint is (very) welcome :)

cnlohr commented 4 days ago

I have not personally built it with this, but a collegue has provided the following (They use Nix but I am guessing you don't. Should be fine).

https://github.com/cleverca22/nixpkgs/blob/riscv-uclibc/lib/systems/examples.nix#L141

    gcc.abi = "ilp32";

which nix then turns into:

"--with-abi=${p.abi}"

so just build gcc with --with-abi=ilp32

dkm commented 2 days ago

Ok, thanks. I'll try to have a look in the coming weeks (don't expect anything from me until august I think).