sickcodes / aur

Sick Codes AUR Packages
GNU General Public License v3.0
8 stars 4 forks source link

`riscv-gnu-toolchain` fails to compile simple test program (CMake Cross Compiler) #4

Open Quaker762 opened 2 years ago

Quaker762 commented 2 years ago

The toolchain has seemingly been configured incorrectly. Observe the following output from CMake:

[quaker@threadripper build]$ cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain/riscv_gcc.cmake ../

-- The C compiler identification is unknown
-- Check for working C compiler: /usr/bin/riscv32-unknown-elf-gcc
-- Check for working C compiler: /usr/bin/riscv32-unknown-elf-gcc - broken
CMake Error at /usr/share/cmake/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "/usr/bin/riscv32-unknown-elf-gcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/quaker/Programming/OSDev/qnix/build/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/bin/make -f Makefile cmTC_87000/fast && /usr/bin/make  -f CMakeFiles/cmTC_87000.dir/build.make CMakeFiles/cmTC_87000.dir/build
    make[1]: Entering directory '/home/quaker/Programming/OSDev/qnix/build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_87000.dir/testCCompiler.c.obj
    /usr/bin/riscv32-unknown-elf-gcc   -g3 -ggdb -v -march=rv32imad -mabi=ilp32 -g3 -ggdb -v -march=rv32imad -mabi=ilp32  -o CMakeFiles/cmTC_87000.dir/testCCompiler.c.obj -c /home/quaker/Programming/OSDev/qnix/build/CMakeFiles/CMakeTmp/testCCompiler.c
    Using built-in specs.
    COLLECT_GCC=/usr/bin/riscv32-unknown-elf-gcc
    Target: riscv32-unknown-elf
    Configured with: /home/runner/work/riscv-gnu-toolchain/riscv-gnu-toolchain/riscv-gcc/configure --target=riscv32-unknown-elf --prefix=/opt/riscv --disable-shared --disable-threads --enable-languages=c,c++ --with-system-zlib --enable-tls --with-newlib --with-sysroot=/opt/riscv/riscv32-unknown-elf --with-native-system-header-dir=/include --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libgomp --disable-nls --disable-tm-clone-registry --src=.././riscv-gcc --disable-multilib --with-abi=ilp32d --with-arch=rv32gc --with-tune=rocket 'CFLAGS_FOR_TARGET=-Os   -mcmodel=medlow' 'CXXFLAGS_FOR_TARGET=-Os   -mcmodel=medlow'
    Thread model: single
    Supported LTO compression algorithms: zlib
    gcc version 11.1.0 (GCC) 
    COLLECT_GCC_OPTIONS='-g3' '-ggdb' '-v' '-march=rv32imad' '-mabi=ilp32' '-g3' '-ggdb' '-v' '-march=rv32imad' '-mabi=ilp32' '-o' 'CMakeFiles/cmTC_87000.dir/testCCompiler.c.obj' '-c' '-mtune=rocket' '-march=rv32imafd' '-march=rv32imafd' '-dumpdir' 'CMakeFiles/cmTC_87000.dir/'
     /usr/bin/../libexec/gcc/riscv32-unknown-elf/11.1.0/cc1 -quiet -v -v -iprefix /usr/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/ -dD /home/quaker/Programming/OSDev/qnix/build/CMakeFiles/CMakeTmp/testCCompiler.c -quiet -dumpdir CMakeFiles/cmTC_87000.dir/ -dumpbase testCCompiler.c.c -dumpbase-ext .c -march=rv32imad -mabi=ilp32 -march=rv32imad -mabi=ilp32 -mtune=rocket -march=rv32imafd -march=rv32imafd -g3 -ggdb -g3 -ggdb -version -o /tmp/cc06PTI7.s
    GNU C17 (GCC) version 11.1.0 (riscv32-unknown-elf)
        compiled by GNU C version 9.3.0, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version none
    warning: GMP header version 6.2.0 differs from library version 6.2.1.
    warning: MPFR header version 4.0.2 differs from library version 4.1.0-p13.
    warning: MPC header version 1.1.0 differs from library version 1.2.1.
    GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    ignoring nonexistent directory "/usr/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/include"
    ignoring duplicate directory "/usr/bin/../lib/gcc/../../lib/gcc/riscv32-unknown-elf/11.1.0/include"
    ignoring nonexistent directory "/opt/riscv/riscv32-unknown-elf/usr/local/include"
    ignoring duplicate directory "/usr/bin/../lib/gcc/../../lib/gcc/riscv32-unknown-elf/11.1.0/include-fixed"
    ignoring nonexistent directory "/usr/bin/../lib/gcc/../../lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/include"
    ignoring nonexistent directory "/opt/riscv/riscv32-unknown-elf/include"
    #include "..." search starts here:
    #include <...> search starts here:
     /usr/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/include
     /usr/bin/../lib/gcc/riscv32-unknown-elf/11.1.0/include-fixed
    End of search list.
    GNU C17 (GCC) version 11.1.0 (riscv32-unknown-elf)
        compiled by GNU C version 9.3.0, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version none
    warning: GMP header version 6.2.0 differs from library version 6.2.1.
    warning: MPFR header version 4.0.2 differs from library version 4.1.0-p13.
    warning: MPC header version 1.1.0 differs from library version 1.2.1.
    GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    Compiler executable checksum: 7308359611291ffe4021af7fc60c4c7d
    COLLECT_GCC_OPTIONS='-g3' '-ggdb' '-v' '-march=rv32imad' '-mabi=ilp32' '-g3' '-ggdb' '-v' '-march=rv32imad' '-mabi=ilp32' '-o' 'CMakeFiles/cmTC_87000.dir/testCCompiler.c.obj' '-c' '-mtune=rocket' '-march=rv32imafd' '-march=rv32imafd' '-dumpdir' 'CMakeFiles/cmTC_87000.dir/'
     as -v -v --gdwarf-5 --traditional-format -march=rv32imad -march=rv32imad -march=rv32imafd -march=rv32imafd -mabi=ilp32 -mabi=ilp32 -o CMakeFiles/cmTC_87000.dir/testCCompiler.c.obj /tmp/cc06PTI7.s
    GNU assembler version 2.38 (x86_64-pc-linux-gnu) using BFD version (GNU Binutils) 2.38
    Assembler messages:
    Fatal error: invalid -march= option: `rv32imad'
    make[1]: *** [CMakeFiles/cmTC_87000.dir/build.make:78: CMakeFiles/cmTC_87000.dir/testCCompiler.c.obj] Error 1
    make[1]: Leaving directory '/home/quaker/Programming/OSDev/qnix/build/CMakeFiles/CMakeTmp'
    make: *** [Makefile:127: cmTC_87000/fast] Error 2

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:5 (project)

It seems the compiler is invoking the host's as, which is insanity.

The command riscv32-unknown-elf-gcc --target-help also fails:

[quaker@threadripper build]$ riscv32-unknown-elf-gcc --target-help
The following options are target specific:
  -mabi=                      Specify integer and floating-point calling convention.
  -malign-data=               Use the given data alignment.
  -march=                     Generate code for given RISC-V ISA (e.g. RV64IM).  ISA strings must be lower-case.
  -mbig-endian                Assume target CPU is configured as big endian.
  -mbranch-cost=N             Set the cost of branches to roughly N instructions.
  -mcmodel=                   Specify the code model.
  -mcpu=PROCESSOR             Use architecture of and optimize the output for PROCESSOR.
  -mdiv                       Use hardware instructions for integer division.
  -mexplicit-relocs           Use %reloc() operators, rather than assembly macros, to load addresses.
  -mfdiv                      Use hardware floating-point divide and square root instructions.
  -misa-spec=                 Set the version of RISC-V ISA spec.
  -mlittle-endian             Assume target CPU is configured as little endian.
  -mplt                       When generating -fpic code, allow the use of PLTs. Ignored for fno-pic.
  -mpreferred-stack-boundary= Attempt to keep stack aligned to this power of 2.
  -mrelax                     Take advantage of linker relaxations to reduce the number of instructions required to materialize symbol addresses.
  -mriscv-attribute           Emit RISC-V ELF attribute.
  -msave-restore              Use smaller but slower prologue and epilogue code.
  -mshorten-memrefs           Convert BASE + LARGE_OFFSET addresses to NEW_BASE + SMALL_OFFSET to allow more memory accesses to be generated as compressed instructions.  Currently targets 32-bit integer load/stores.
  -msmall-data-limit=N        Put global and static data smaller than <number> bytes into a special section (on some targets).
  -mstack-protector-guard-offset= Use the given offset for addressing the stack-protector guard.
  -mstack-protector-guard-reg= Use the given base register for addressing the stack-protector guard.
  -mstack-protector-guard=    Use given stack-protector guard.
  -mstrict-align              Do not generate unaligned memory accesses.
  -mtune=PROCESSOR            Optimize the output for PROCESSOR.

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

  Known code models (for use with the -mcmodel= option):
    medany medlow

  Supported ISA specs (for use with the -misa-spec= option):
    2.2 20190608 20191213

  Known data alignment choices (for use with the -malign-data= option):
    natural xlen

  Valid arguments to -mstack-protector-guard=:
    global tls

Assembler options
=================

Use "-Wa,OPTION" to pass "OPTION" to the assembler.

Assembler messages:
Fatal error: invalid -march= option: `rv32imafdc'
realqhc commented 2 years ago

You could try my pr above, it attempts to fix this problem.

gzzyyxh commented 7 months ago

Reconfigure the riscv repo to support imac_zicsr extension and you will solve this problem.