The riscv port does not have support for cgo - this should be added at some point in the future (hence this tracking bug).
Change https://golang.org/cl/215838 mentions this issue: cmd/dist: mark cgo as disabled on linux/riscv64
Is anyone actively working on this? We (Canonical) want it and may be able to spend some time on it (but maybe not very much).
@mwhudson - I'm not aware of anyone currently working on this. The bigger issue/blocker is the lack of external (or internal cgo) linking support. Once that is implemented cgo should be reasonably straight forward.
I have cgo working on linux/riscv64 - I'll attempt to get this cleaned up and ready for the next development cycle:
$ uname -a
Linux ubuntu 5.3.0-24-generic #26+riscv64.2-Ubuntu SMP Tue Jan 7 12:04:36 UTC 2020 riscv64 riscv64 riscv64 GNU/Linux
$ cat cgo.go
package main
import "runtime"
/*
#include <stdio.h>
void hello(char *goos, char *goarch) {
printf("Hi from cgo on %s/%s!\n", goos, goarch);
}
*/
import "C"
func main() {
goos := C.CString(runtime.GOOS)
goarch := C.CString(runtime.GOARCH)
C.hello(goos, goarch)
}
$ ~/src/go/bin/go build
$ ./cgo
Hi from cgo on linux/riscv64!
There is a branch here that adds cgo support for linux/riscv64 on Go 1.14.2.
I've been testing it on some projects for a while and both runc (Container Runtime) and SQLite module for Go build and work fine.
Runc only needed an adjust in the Makefile since it also uses buildmode=pie. I removed it and it built and worked perfectly.
Amazing work @4a6f656c :)
I think buildmode=pie support is just a matter of marking it as enabled in a few places: https://git.launchpad.net/~usd-import-team/ubuntu/+source/golang-1.14/commit/?h=applied/ubuntu/groovy-proposed&id=05db5462189beacd08bb3ac6bd2be2cf7e7fd9dd
@carlosedp - thanks, glad to hear it.
FWIW there is a commit on the top of https://github.com/4a6f656c/go/tree/riscv64-cgo that enables -buildmode=pie (essentially the same diff as @mwhudson references).
I've tested it by building runc with buildmode=pie and it works as expected.
Thanks @4a6f656c !
Hi @4a6f656c , any news on upstreaming CGO/PIE support for the next Go release? I believe the 1.16 freeze starts in november.
Thanks!
Hi @4a6f656c , any news on upstreaming CGO/PIE support for the next Go release? I believe the 1.16 freeze starts in november.
The first step is to get external linking support - a review for that is currently pending:
Change https://golang.org/cl/263477 mentions this issue: cmd/compile,cmd/internal/obj/riscv: move g register on riscv64
Change https://golang.org/cl/263478 mentions this issue: cmd/link,cmd/internal/obj/riscv: add TLS support for linux/riscv64
Change https://golang.org/cl/263598 mentions this issue: cmd/dist,cmd/go,runtime: add support for cgo on linux/riscv64
Change https://golang.org/cl/263601 mentions this issue: cmd/link: add loadelf support for riscv64
Just a note to thank you for completing and closing this issue.
I hit this exact RISC-V cgo issues on a repo that I was trying to compile https://github.com/ethereum/go-ethereum
It wouldn't compile in 1.15.5 due to
/usr/bin/ld: $WORK/b009/_x008.o: in function `x_cgo_thread_start':
/usr/lib/go-1.15/src/runtime/cgo/gcc_util.c:21: undefined reference to `_cgo_sys_thread_start'
collect2: error: ld returned 1 exit status
which was the same error message I could repro with @4a6f656c sample cgo.go file above.
I pulled the golang source, built master, and can confirm that cgo works fine on RISC-V and I was able to successfully compile the project. Thanks heaps for your hard work resolving this.
Change https://golang.org/cl/274478 mentions this issue: doc/go1.16: document riscv64 port changes
Most helpful comment
The first step is to get external linking support - a review for that is currently pending:
https://go-review.googlesource.com/c/go/+/243517