Linux RISCV64 Support

I have been working on patches for compiling Swift 5.6 for RISCV64 with Buildroot. First I compiled the patched compiler (swift, llvm-project and swift-core-tools-support) and then use Buildroot with patched compiler to cross compiler the Swift Stdlib. I have gotten to the point where I can successfully compile libdispatch, the Swift StdLib and runtime's .c, .cpp and .swift files for RISCV64, but the linking stage for the StdLib fails.

https://bugs.swift.org/browse/SR-16005

ld.lld: error: stdlib/public/core/LINUX/riscv64/Swift.o: cannot link object files with different floating-point ABI
ld.lld: error: Swift.o![|16x16](https://bugs.swift.org/images/icons/emoticons/sad.png).text+0x0): relocation R_RISCV_ALIGN requires unimplemented linker relaxation; recompile with -mno-relax

I have tried a lot of Swift compiler flags based on Every Option and Flag /swift (1.2) Accepts Ever · GitHub and passing them via -DSWIFT_STDLIB_EXTRA_SWIFT_COMPILE_FLAGS to cmake for cross compiling the StdLib but none seem to work.

8 Likes

I was able to build for RISCV64 with Soft Float enabled.

Swift patches

Buildroot

1 Like
2 Likes

Amazing work!, @ColemanCDA. This has so much potential!

As a matter of fact, I just recently started to get into microcontrollers. In particular I'm supposed to write the firmware for an ESP32-C3 (RISCV32) based device and would love to use Swift rather than C and C++.

How similar are RISCV32 and RISCV64? What would it take to enhance your patch to also support RISCV32?