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: support netbsd/arm64 #30824

Closed
coypoop opened this issue Mar 14, 2019 · 31 comments
Closed

all: support netbsd/arm64 #30824

coypoop opened this issue Mar 14, 2019 · 31 comments
Labels
arch-arm64 FeatureRequest FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-NetBSD
Milestone

Comments

@coypoop
Copy link
Contributor

coypoop commented Mar 14, 2019

Tracking progress of netbsd/arm64 support:

#29398 adds support, not completely functional.
A simple program (hello world) runs, getting further and trying to build Go itself fails.

@bradfitz bradfitz changed the title netbsd/arm64 support all: support netbsd/arm64 Mar 14, 2019
@bradfitz bradfitz added this to the Go1.13 milestone Mar 14, 2019
@gopherbot
Copy link

Change https://golang.org/cl/155739 mentions this issue: all: add netbsd/arm64 support

@bradfitz
Copy link
Contributor

What's the plan for a builder?

See https://golang.org/wiki/PortingPolicy

@bsiegert
Copy link
Contributor

We can run a builder on Scaleway, with the caveat that there needs to be a working builder binary first :)

Otherwise, I could contribute a builder on real hardware; I have an arm64 machine running NetBSD.

@bradfitz
Copy link
Contributor

We can run a builder on Scaleway, with the caveat that there needs to be a working builder binary first :)

Oh, does NetBSD boot on Scaleway ARM64 instances? I never had much luck with non-Linux OSes on Scaleway.

@coypoop
Copy link
Contributor Author

coypoop commented Mar 15, 2019

I can see two problems,

(1) By code inspection, nothing seems to set TLS.
netbsd/amd64 does it with a lwp_setprivate(m->tls) syscall in lwp_tramp.
I am new to TLS so I want to see effects to my changes so I am holding onto that change until I see it affecting something.

(2) broken signal handling. if I send SIGINFO (^T), it usually segfaults,

Thread 3 received signal SIGSEGV, Segmentation fault.
0x000000000004e2b4 in runtime.sigtrampgo (sig=<optimized out>, info=0x4000449bd0, ctx=0x4000449c50) at /home/fly/go/src/runtime/signal_unix.go:307
307             if sp < g.m.gsignal.stack.lo || sp >= g.m.gsignal.stack.hi {
(gdb) bt
#0  0x000000000004e2b4 in runtime.sigtrampgo (sig=<optimized out>, info=0x4000449bd0, ctx=0x4000449c50) at /home/fly/go/src/runtime/signal_unix.go:307
#1  0x00000000000640ec in runtime.sigtramp () at /home/fly/go/src/runtime/sys_netbsd_arm64.s:297
#2  0x0000000000064060 in runtime.sigprocmask () at /home/fly/go/src/runtime/sys_netbsd_arm64.s:253
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

here g.m=NULL. I guess g is invalid.

The code for that is the runtime.sig* functions. It's probably just wrong and not exercised by other things.

@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. FeatureRequest labels Apr 12, 2019
@coypoop
Copy link
Contributor Author

coypoop commented Apr 20, 2019

../cmd/vet/all/whitelist/darwin_arm.txt
5:runtime/asm_arm.s: [arm] sigreturn: function sigreturn missing Go declaration
../cmd/vet/all/whitelist/darwin_arm64.txt
3:runtime/asm_arm64.s: [arm64] sigreturn: function sigreturn missing Go declaration
../cmd/vet/all/whitelist/freebsd_arm.txt
3:runtime/asm_arm.s: [arm] sigreturn: function sigreturn missing Go declaration

let's just move this to linux?

made #31583 for this

@bsiegert
Copy link
Contributor

bsiegert commented Apr 20, 2019 via email

gopherbot pushed a commit that referenced this issue Apr 20, 2019
This works well enough to run some code natively on arm64, but not well enough for more complicated code. I've been suggested to start a pull request anyway.

Updates #30824

Change-Id: Ib4f63e0e8a9edfc862cf65b5f1b0fbf9a8a1628e
GitHub-Last-Rev: b01b105
GitHub-Pull-Request: #29398
Reviewed-on: https://go-review.googlesource.com/c/go/+/155739
Run-TryBot: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
@gopherbot
Copy link

Change https://golang.org/cl/174078 mentions this issue: runtime: gofmt defs1_netbsd_arm64.go

gopherbot pushed a commit that referenced this issue Apr 26, 2019
Updates #30824

Change-Id: I3d9ad7896d528d8274ec78378a546b0356986b9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/174078
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@gopherbot
Copy link

Change https://golang.org/cl/175237 mentions this issue: syscall: support generating netbsd/arm64 files in mkall.sh

gopherbot pushed a commit that referenced this issue May 5, 2019
CL 155739 added the generated files but didn't update mkall.sh. Do so
now.

Updates #30824

Change-Id: I642bbff6afbc976091a0dc291fa2beff5e245246
Reviewed-on: https://go-review.googlesource.com/c/go/+/175237
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@gopherbot
Copy link

Change https://golang.org/cl/177120 mentions this issue: runtime: fix netbsd/arm64 assembly

@4a6f656c
Copy link
Contributor

(1) By code inspection, nothing seems to set TLS.
netbsd/amd64 does it with a lwp_setprivate(m->tls) syscall in lwp_tramp.
I am new to TLS so I want to see effects to my changes so I am holding onto that change until I see it affecting something.

Where/when possible Go will use a dedicated register rather than using TLS - in the case of arm64, this is register R28 (g). If cgo is used then the resulting binary has a PT_TLS segment and the dynamic loader (ld.so) is usually responsible for allocating and setting up TLS, which can then be used by the thread. In the case of cgo the g register is still used, however there are known points where we have to reload it from TLS.

(2) broken signal handling. if I send SIGINFO (^T), it usually segfaults,

The main reason for this is that the NetBSD kernel trashes the g register, by storing a pointer to the ucontext in R28 (in addition to R2) - see /* put in callee save register */ comment in:

http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/arch/aarch64/aarch64/sig_machdep.c?rev=1.1.28.2&content-type=text/x-cvsweb-markup

At first glance, in the non-cgo case we may be able to be somewhat "clever" and reload g from the mcontext, since it should match what we had previously. Otherwise it would need to use a similar set up to what amd64 does - use lwp_setprivate to set the TLS pointer to m_tls and then load_g and save_g through TLS (which will be somewhat of a performance hit).

gopherbot pushed a commit that referenced this issue May 17, 2019
Fix various bugs in the netbsd/arm64 runtime assembly.

Updates #30824.

Change-Id: I5ca10926ab663a8ff4df9973530e645e2469c1aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/177120
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@tklauser
Copy link
Member

While reading through some code I noticed https://golang.org/cl/174129 and its related issue #31746 regarding CPU feature detection on openbsd/arm64. Does netbsd/arm64 need a similar mechanism as well? Or does it provide CPU feature detection via AT_HWCAP?

@coypoop
Copy link
Contributor Author

coypoop commented May 22, 2019

netbsd doesn't supply AT_HWCAP either, but it does have a bunch of sysctls. I wonder how bad it will be to just provide AT_HWCAP.

@gopherbot
Copy link

Change https://golang.org/cl/179939 mentions this issue: internal/socket: add support for netbsd/arm64

gopherbot pushed a commit to golang/net that referenced this issue Jun 3, 2019
Updates golang/go#30824

Change-Id: I872b725d6640e29570652171b6c45634fc21a461
Reviewed-on: https://go-review.googlesource.com/c/net/+/179939
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
@bsiegert
Copy link
Contributor

So I tried a test run on a real machine, a Raspberry Pi 3 running NetBSD-current in 64-bit mode.

$ go env
Memory fault (core dumped)

Other invocations of the go tool that I tried fail in the same way. Here are full outputs of backtraces from gdb and ktrace:

gdb.txt
kdump.txt

The relevant bits are, I think:

   418      5 go       PSIG  SIGCHLD caught handler=0x644c0 mask=(): code=CLD_EXITED child pid=1828, uid=1000,  status=1, utime=0, stime=0)
   418      1 go       RET   __wait450 1828/0x724
   418      5 go       PSIG  SIGSEGV SIG_DFL: code=SEGV_MAPERR, addr=0x50, trap=-1845493753)

And:

Thread 1 (process 9):
#0  0x000000000004e3e4 in runtime.sigtrampgo (sig=<optimized out>, info=0x4000239bd0, ctx=0x4000239c50) at /usr/local/go/src/runtime/signal_unix.go:308
#1  0x0000000000064538 in runtime.sigtramp () at /usr/local/go/src/runtime/sys_netbsd_arm64.s:314
#2  0x0000000000064460 in runtime.sigprocmask () at /usr/local/go/src/runtime/sys_netbsd_arm64.s:248

Note that line 248 is in the implementation of runtime·sigprocmask, in the failure handler which deliberately references a null pointer to provoke a crash.

@coypoop @tklauser Any ideas?

@4a6f656c
Copy link
Contributor

4a6f656c commented Jun 16, 2019

@bsiegert - signal handling is currently completely broken, since the kernel trashes the g register (see my earlier #30824 (comment) for details).

@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@gopherbot
Copy link

Change https://golang.org/cl/192998 mentions this issue: [release-branch.go1.13] doc/go1.13: remove announcements of arm64 support on NetBSD and OpenBSD

gopherbot pushed a commit that referenced this issue Sep 3, 2019
…port on NetBSD and OpenBSD

Those configurations currently lack builders, and it is not clear to
me what state their tests are in.

The Go porting policy¹ requires builders for all active ports, so
let's not claim support until that requirement is met.

¹https://golang.org/wiki/PortingPolicy#requirements-for-a-new-port

Updates #30824
Updates #31656
Updates #34035
Updates #34036

Change-Id: I6496de9d92fb8546048abf139cf10546a47e314b
Reviewed-on: https://go-review.googlesource.com/c/go/+/192997
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
(cherry picked from commit 9f5127b)
Reviewed-on: https://go-review.googlesource.com/c/go/+/192998
Run-TryBot: Bryan C. Mills <bcmills@google.com>
t4n6a1ka pushed a commit to t4n6a1ka/go that referenced this issue Sep 5, 2019
Those configurations currently lack builders, and it is not clear to
me what state their tests are in.

The Go porting policy¹ requires builders for all active ports, so
let's not claim support until that requirement is met.

¹https://golang.org/wiki/PortingPolicy#requirements-for-a-new-port

Updates golang#30824
Updates golang#31656
Updates golang#34035
Updates golang#34036

Change-Id: I6496de9d92fb8546048abf139cf10546a47e314b
Reviewed-on: https://go-review.googlesource.com/c/go/+/192997
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@bsiegert
Copy link
Contributor

There are some local patches in the pkgsrc repository that make Go actually work on netbsd/arm64. Would these patches be accepted during the freeze? It would be awesome if we could get arm64 support as part of Go 1.15.

@gopherbot
Copy link

Change https://golang.org/cl/235097 mentions this issue: cpu: avoid illegal instruction on netbsd/arm64

gopherbot pushed a commit to golang/sys that referenced this issue May 23, 2020
On NetBSD, this package tries to read a privileged register,
which results in a SIGILL. Use the same workaround as Android and
iOS. In the future, we could use sysctl(3) instead.

Update golang/go#30824

Change-Id: Ifd9aa2a2cf4dac43341d013602d1ccb4b8d6eb6d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/235097
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@gopherbot
Copy link

Change https://golang.org/cl/231957 mentions this issue: runtime: use hw.ncpuonline sysctl in getncpu on netbsd

@andybons
Copy link
Member

andybons commented Jun 8, 2020

Would these patches be accepted during the freeze? It would be awesome if we could get arm64 support as part of Go 1.15.

I’d rather we not land anything in the tree this far into the freeze. Sorry.

gopherbot pushed a commit that referenced this issue Aug 17, 2020
Since NetBSD 7, hw.ncpuonline reports the number of CPUs online, while
hw.cpu reports the number of CPUs configured. Try hw.cpuonline first and
fall back to hw.ncpu in case it fails (which is the case on NetBSD
before 7.0).

This follows the behavior on OpenBSD (see CL 161757). Also, Go
in pkgsrc is patched to use hw.cpuonline, so this CL would allow said
patch to be dropped.

Updates #30824

Change-Id: Id1c19dff2c1e4401e6074179fae7c708ba0e3098
Reviewed-on: https://go-review.googlesource.com/c/go/+/231957
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
@gopherbot
Copy link

Change https://golang.org/cl/257643 mentions this issue: cmd/dist: detect gohostarch on netbsd/arm64 hosts

gopherbot pushed a commit that referenced this issue Sep 26, 2020
On netbsd/arm64 `uname -m` reports `evbarm` which is mapped to
gohostarch=arm. Fix this by checking for "aarch64" in `uname -p` output
to fix self-hosted build on netbsd/arm64.

Updates #30824

Change-Id: I0f0450ff35af0bec51aeec3b210143ba892216c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/257643
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
@gopherbot
Copy link

Change https://golang.org/cl/257645 mentions this issue: runtime: fix stack alignment for pipe2 return value on netbsd-arm64

gopherbot pushed a commit that referenced this issue Sep 28, 2020
Add missing declaration of crosscall1.

Fix stack alignment for pipe2 return value.

Work around kernel clobbering of r28 on aarch64 by reloading from ucontext.
https://nxr.netbsd.org/xref/src/sys/arch/aarch64/aarch64/sig_machdep.c#104

Update #30824

Change-Id: I7f9472939f4c02953f8c207308610118f5d3c54c
Reviewed-on: https://go-review.googlesource.com/c/go/+/257645
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Benny Siegert <bsiegert@gmail.com>
@gopherbot
Copy link

Change https://golang.org/cl/257938 mentions this issue: dashboard: only build tip on netbsd-arm64-bsiegert builder

@gopherbot
Copy link

Change https://golang.org/cl/257998 mentions this issue: runtime: initialise cpu.HWCap on netbsd/arm64

gopherbot pushed a commit that referenced this issue Sep 28, 2020
NetBSD does not supply AT_HWCAP, however we still need to initialise
cpu.HWCaps.  For now specify the bare minimum until we add some form of
capabilities detection. See
https://golang.org/issue/30824#issuecomment-494901591

Follows CL 174129 which did the same for openbsd/arm64.

Updates #30824

Change-Id: I43a86b583bc60d259a66772703de06970124bb7f
Reviewed-on: https://go-review.googlesource.com/c/go/+/257998
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
gopherbot pushed a commit to golang/build that referenced this issue Sep 29, 2020
The build fails on 1.15 and earlier.

Updates golang/go#30824

Change-Id: I1f62d37cc05dde988cbb7e5124bd97916b38bcb3
Reviewed-on: https://go-review.googlesource.com/c/build/+/257938
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
@gopherbot
Copy link

Change https://golang.org/cl/258000 mentions this issue: runtime: correct arguments to pipe2 syscall in pipe

gopherbot pushed a commit that referenced this issue Sep 29, 2020
Follow the implementation of pipe2 to pass arguments and handle return
values.

With this fix the runtime tests pass on netbsd/arm64 (tested using
gomote on the netbsd-arm64-bsiegert builder).

Update #30824

Change-Id: I346db68fc9dde8dc7f11351af05c1ad3105f4a32
Reviewed-on: https://go-review.googlesource.com/c/go/+/258000
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
@bsiegert
Copy link
Contributor

So with the last change, we finally seem to have a builder that finishes with an "ok" status. Thanks everyone for this achievement!

@gopherbot
Copy link

Change https://golang.org/cl/259277 mentions this issue: doc/go1.16: announce netbsd/arm64 support

gopherbot pushed a commit that referenced this issue Oct 2, 2020
netbsd/arm64 now complies with all the requirements for a port as
specified on https://golang.org/wiki/PortingPolicy

Note that this was preliminarily announced in the Go 1.13 release notes
(CL 183637) but then removed again due to the port lacking a builder at
that time (CL 192997).

Updates #30824

Change-Id: I2f40fabc84fe9cb699282e6a9d13ed9b64478e36
Reviewed-on: https://go-review.googlesource.com/c/go/+/259277
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@4a6f656c
Copy link
Contributor

4a6f656c commented Dec 7, 2020

Per #42422, this port still appears to be unstable.

@tklauser
Copy link
Member

tklauser commented Mar 25, 2022

netbsd/arm64 is supported since Go 1.16 and the builder seems to run stable since #42422 was resolved. I think this can be closed.

@golang golang locked and limited conversation to collaborators Mar 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-arm64 FeatureRequest FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-NetBSD
Projects
None yet
Development

No branches or pull requests

10 participants