Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RISCV cross compile completely infeasible #19057

Open
soant opened this issue Nov 7, 2024 · 1 comment
Open

RISCV cross compile completely infeasible #19057

soant opened this issue Nov 7, 2024 · 1 comment
Labels
bug 🐞 Something isn't working support Request support or ask a question

Comments

@soant
Copy link

soant commented Nov 7, 2024

What happened?

Step 1:

I compiled the RISCV-GNU-TOOLCHAIN for riscv64-unknown-linux-gnu-gcc:

riscv64-unknown-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=riscv64-unknown-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/opt/riscv/libexec/gcc/riscv64-unknown-linux-gnu/13.2.0/lto-wrapper
Target: riscv64-unknown-linux-gnu
Configured with: /home/runner/work/riscv-gnu-toolchain/riscv-gnu-toolchain/gcc/configure --target=riscv64-unknown-linux-gnu --prefix=/opt/riscv --with-sysroot=/opt/riscv/sysroot --with-pkgversion= --with-system-zlib --enable-shared --enable-tls --enable-languages=c,c++,fortran --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libsanitizer --disable-nls --disable-bootstrap --src=.././gcc --disable-multilib --with-abi=lp64d --with-arch=rv64gc --with-tune=rocket --with-isa-spec=20191213 'CFLAGS_FOR_TARGET=-O2    -mcmodel=medlow' 'CXXFLAGS_FOR_TARGET=-O2    -mcmodel=medlow'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.2.0 () 

Step 2:

Build the LLVM for RISCV target using command:

cmake -G "Unix Makefiles" -DDEFAULT_SYSROOT="/opt/riscv/sysroot" -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=On -DLLVM_DEFAULT_TARGET_TRIPLE="riscv64-unknown-linux-gnu" -DLLVM_TARGETS_TO_BUILD="RISCV" -DLLVM_PARALLEL_LINK_JOBS=1 ../llvm

and compiled clang shows:

clang -v
clang version 20.0.0git (https://github.com/iree-org/llvm-project.git 864902e9b4d8bc6d3f0852d5c475e3dc97dd8335)
Target: riscv64-unknown-linux-gnu
Thread model: posix
InstalledDir: /code/iree/third_party/llvm-project/build/bin
Build config: +assertions

test test.c file using above compiled compiler with no problem:

clang test.c -S -O3 -o - --gcc-toolchain=/opt/riscv

Step 3:

Trying to compile the IREE using above compiler for RISCV host tools:

cmake -GNinja -B ../iree-build/ \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_FLAGS="--gcc-toolchain=/opt/riscv --sysroot=/opt/riscv/sysroot --target=riscv64 -march=rv64gc" \
-DCMAKE_CXX_FLAGS="--gcc-toolchain=/opt/riscv --sysroot=/opt/riscv/sysroot --target=riscv64 -march=rv64gc" \
-DCMAKE_INSTALL_PREFIX=../iree-build/install \
-DCMAKE_BUILD_TYPE=RelWithDebInfo .

generate error:

  The C compiler

    "/code/iree/third_party/llvm-project/build/bin/clang"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /code/iree-build/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/ninja cmTC_3e84d && [1/2] Building C object CMakeFiles/cmTC_3e84d.dir/testCCompiler.c.o
    [2/2] Linking C executable cmTC_3e84d
    FAILED: cmTC_3e84d 
    : && /home/barry/code/iree/third_party/llvm-project/build/bin/clang --gcc-toolchain=/opt/riscv --sysroot=/opt/riscv/sysroot --target=riscv64 -march=rv64gc -lstdc++ -lpthread -lm -ldl CMakeFiles/cmTC_3e84d.dir/testCCompiler.c.o -o cmTC_3e84d   && :
    /opt/riscv/lib/gcc/riscv64-unknown-linux-gnu/13.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: cannot find crt0.o: no that file or directory
    clang: error: ld command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.

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

crt0.o only generated for riscv64-unknown-elf type, I build for riscv64-unknown-linux-gnu, how does this happen?

@soant soant added the bug 🐞 Something isn't working label Nov 7, 2024
@ScottTodd ScottTodd added the support Request support or ask a question label Nov 7, 2024
@ScottTodd
Copy link
Member

We have some instructions you can follow at https://iree.dev/building-from-source/riscv/ and https://iree.dev/guides/deployment-configurations/bare-metal/.

For your step 3, I see a few areas to debug:

  • The CMake C/C++ compiler is set to clang, but gcc flags are being passed. The "The C compiler is not able to compile a simple test program." is a generic setup error message from the build system, before getting to anything IREE-specific
  • That CMake command will build the IREE runtime and compiler. You might be able to build the compiler for RISCV, but we generally recommend running the compiler on a host machine (desktop Linux/macOS/Windows x86 or aarch64) and deploying the runtime on a target machine (desktop, mobile, embedded, etc. with any architecture)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working support Request support or ask a question
Projects
None yet
Development

No branches or pull requests

2 participants