2

I'm trying to compile to RiscV using clang and I see this answer as a useful starting point.

Started by checking if llvm supports RISCV, which it does

% llvm-objdump --version | grep riscv
    riscv32    - 32-bit RISC-V
    riscv64    - 64-bit RISC-V

So, I tried compiling in the same way but it fails:

$ clang --target=riscv64 -march=rv64gc rotate.s -c -o rotate.o

clang -cc1as: error: unknown target triple 'riscv64-unknown-unknown', please use -triple or -arch

Let's look for the target:

clang -print-targets     
  Registered Targets:
    aarch64    - AArch64 (little endian)
    aarch64_32 - AArch64 (little endian ILP32)
    aarch64_be - AArch64 (big endian)
    arm        - ARM
    arm64      - ARM64 (little endian)
    arm64_32   - ARM64 (little endian ILP32)
    armeb      - ARM (big endian)
    thumb      - Thumb
    thumbeb    - Thumb (big endian)
    x86        - 32-bit X86: Pentium-Pro and above
    x86-64     - 64-bit X86: EM64T and AMD64

So, I understand that RISCV is not registered as a target for clang. So, how do I add it?

Also, once I add the target, how do I get the right libc?

  • You'll need to [configure clang to be a cross-compiler](https://llvm.org/docs/HowToCrossCompileLLVM.html) and build it yourself -- the default clang binaries do not do so (at least not for risc-V) – Chris Dodd Feb 22 '22 at 21:14
  • Could you be more explicit on what steps I need to follow. Your link shows an example from x86_64 to ARM. But I can't figure out the equivalent for RISCV – Santiago Cuellar Feb 22 '22 at 21:25
  • Did you look here? : https://stackoverflow.com/questions/68580399/using-clang-to-compile-for-risc-v – Celuk Mar 22 '22 at 07:29

0 Answers0