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

all: add cgo support to the riscv port #36641

Open
4a6f656c opened this issue Jan 19, 2020 · 15 comments
Open

all: add cgo support to the riscv port #36641

4a6f656c opened this issue Jan 19, 2020 · 15 comments

Comments

@4a6f656c
Copy link
Contributor

@4a6f656c 4a6f656c commented Jan 19, 2020

The riscv port does not have support for cgo - this should be added at some point in the future (hence this tracking bug).

@gopherbot
Copy link

@gopherbot gopherbot commented Jan 22, 2020

Change https://golang.org/cl/215838 mentions this issue: cmd/dist: mark cgo as disabled on linux/riscv64

gopherbot pushed a commit that referenced this issue Jan 22, 2020
cgo is not currently supported on this platform.

Updates #27532 and #36641

Change-Id: I4b35f887e869ebc5c156dd754b1c79897a8c5800
Reviewed-on: https://go-review.googlesource.com/c/go/+/215838
Reviewed-by: Cherry Zhang <cherryyz@google.com>
@mwhudson
Copy link
Contributor

@mwhudson mwhudson commented Apr 29, 2020

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).

@4a6f656c
Copy link
Contributor Author

@4a6f656c 4a6f656c commented Apr 30, 2020

@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.

lucaskanashiro added a commit to lucaskanashiro/debian-containerd that referenced this issue May 15, 2020
As this plugin needs cgo and riscv64 doesn't support. These changes are
based on this Debian commit:

https://salsa.debian.org/go-team/packages/containerd/-/commit/e3c6a7bb

This is the upstream bug report:

golang/go#36641
@4a6f656c
Copy link
Contributor Author

@4a6f656c 4a6f656c commented May 18, 2020

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!
@4a6f656c
Copy link
Contributor Author

@4a6f656c 4a6f656c commented May 30, 2020

There is a branch here that adds cgo support for linux/riscv64 on Go 1.14.2.

@carlosedp
Copy link

@carlosedp carlosedp commented Jun 12, 2020

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 :)

@mwhudson
Copy link
Contributor

@mwhudson mwhudson commented Jun 15, 2020

@4a6f656c
Copy link
Contributor Author

@4a6f656c 4a6f656c commented Jun 16, 2020

@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).

@carlosedp
Copy link

@carlosedp carlosedp commented Jun 16, 2020

I've tested it by building runc with buildmode=pie and it works as expected.
Thanks @4a6f656c !

@carlosedp
Copy link

@carlosedp carlosedp commented Aug 18, 2020

Hi @4a6f656c , any news on upstreaming CGO/PIE support for the next Go release? I believe the 1.16 freeze starts in november.

Thanks!

@4a6f656c
Copy link
Contributor Author

@4a6f656c 4a6f656c commented Sep 2, 2020

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:

https://go-review.googlesource.com/c/go/+/243517

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 18, 2020

Change https://golang.org/cl/263477 mentions this issue: cmd/compile,cmd/internal/obj/riscv: move g register on riscv64

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 18, 2020

Change https://golang.org/cl/263478 mentions this issue: cmd/link,cmd/internal/obj/riscv: add TLS support for linux/riscv64

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 19, 2020

Change https://golang.org/cl/263598 mentions this issue: cmd/dist,cmd/go,runtime: add support for cgo on linux/riscv64

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 20, 2020

Change https://golang.org/cl/263601 mentions this issue: cmd/link: add loadelf support for riscv64

ricardosalveti added a commit to ricardosalveti/meta-lmp that referenced this issue Oct 21, 2020
Backport patches from
https://github.com/4a6f656c/go/commits/riscv64-cgo-1.15 for risc-v
support for cgo.

Upstreaming is also in progress via
golang/go#36641.

Signed-off-by: Ricardo Salveti <ricardo@foundries.io>
gopherbot pushed a commit that referenced this issue Oct 21, 2020
The original riscv64 port used the thread pointer (TP aka X4) register for
the g pointer, however this register is also used when TLS support is
required, resulting in a conflict (for example, when a signal is received
we have no way of readily knowing if X4 contains a pointer to the TCB or
a pointer to a g).

In order to support cgo, free up the X4 register by moving g to X27.
This unfortunately means that the X4 register is unused in non-cgo mode,
however the alternative is to not support cgo on this platform.

Update #36641

Change-Id: Idcaf3e8ccbe42972a1b8943aeefde7149d9c960a
Reviewed-on: https://go-review.googlesource.com/c/go/+/263477
Trust: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.