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 support for FreeBSD / aarch64 #24715

Closed
SylvainGarrigues opened this issue Apr 5, 2018 · 52 comments
Closed

all: add support for FreeBSD / aarch64 #24715

SylvainGarrigues opened this issue Apr 5, 2018 · 52 comments
Labels
FeatureRequest FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. OS-FreeBSD
Milestone

Comments

@SylvainGarrigues
Copy link

Go 1.10 works for me on FreeBSD-CURRENT / arm, but I’d love an arm64 port.

@bradfitz bradfitz added help wanted NeedsFix The path to resolution is known, but the work has not been done. FeatureRequest labels Apr 6, 2018
@bradfitz bradfitz added this to the Unplanned milestone Apr 6, 2018
@bradfitz bradfitz changed the title Add support for FreeBSD / aarch64 all: add support for FreeBSD / aarch64 Apr 6, 2018
@jsirianni
Copy link

I will plus this

@valpackett
Copy link

I made an attempt: https://github.com/myfreeweb/go/commit/04a920776cbee1428cb698503e1c99784475cf53
It compiles, and even does some syscalls, but crashes when starting the first thread.

I wonder if it's possible to take my patches to the standard library and use gccgo with them?

@ianlancetaylor
Copy link
Contributor

@myfreeweb Patches like adding build tags here and there are likely the same for gccgo and gc. But gccgo has no equivalent to runtime/sys_freebsd_arm64.s.

@SylvainGarrigues
Copy link
Author

Anyone working on this?

@peterjeremy
Copy link

I'm also interested in this but haven't looked to see how much effort would be involved.

@bsd-hacker
Copy link

I try.

"go version" is work, but src/make.bash not work.

# uname -a
FreeBSD pine64-01.os-hackers.jp 13.0-CURRENT FreeBSD 13.0-CURRENT r340361 GENERIC  arm64
# go version
go version devel +04a920776c Mon Jul 16 19:43:23 2018 +0300 freebsd/arm64

my fixes are,

diff --git a/src/runtime/sys_freebsd_arm64.s b/src/runtime/sys_freebsd_arm64.s
index 887c4a3ef1..d637e21a3a 100644
--- a/src/runtime/sys_freebsd_arm64.s
+++ b/src/runtime/sys_freebsd_arm64.s
@@ -13,7 +13,7 @@
 #define AT_FDCWD -100

 #define CLOCK_REALTIME 0
-#define CLOCK_MONOTONIC 1
+#define CLOCK_MONOTONIC 4

 #define SYS_exit 1
 #define SYS_read 3
@@ -57,27 +57,31 @@ TEXT runtime揃sys_umtx_op(SB),NOSPLIT,$0

 TEXT runtime揃thr_new(SB),NOSPLIT,$0
        MOVD param+0(FP), R0
-       MOVD size+8(FP), R1
-       MOVW $SYS_thr_new, R8
+       MOVW size+8(FP), R1
+       MOVD $SYS_thr_new, R8
        SVC
        MOVW    R0, ret+16(FP)
        RET

 TEXT runtime揃thr_start(SB),NOSPLIT,$0
        // set up g
-       MOVD    R10, g_m(R11)
-       MOVD    R11, g
-       //BL runtime揃stackcheck(SB)
+       MOVD    m_g0(R0), g
+       MOVD    R0, g_m(g)
+       //MOVD  R10, g_m(R11)
+       //MOVD  R11, g
+       //BL runtimestackcheck(SB)
        BL runtime揃mstart(SB)

-       MOVW $2, R8  // crash (not reached)
-       MOVW R8, (R8)
+       MOVD $2, R8  // crash (not reached)
+       MOVD R8, (R8)
        RET

 TEXT runtime揃exit(SB),NOSPLIT|NOFRAME,$0-4
        MOVW    code+0(FP), R0
        MOVD    $SYS_exit, R8
        SVC
+       MOVD    $0, R8
+       MOVD    R8, (R8)
        RET

 // func exitThread(wait *uint32)

tklauser added a commit to tklauser/sys that referenced this issue Nov 27, 2018
For now zerrors_freebsd_arm64.go and ztypes_freebsd_arm64.go is just a
copy of the freebsd/amd64 version of the files. Regenerate once
bootstrapping a compiler works.

Updates golang/go#24715

DO NOT REVIEW
DO NOT SUBMIT

Change-Id: I90a7e3ea0c0b6ecab4033f2908331b7be164a236
tklauser added a commit to tklauser/sys that referenced this issue Nov 27, 2018
Updates golang/go#24715

DO NOT REVIEW
DO NOT SUBMIT

For now zerrors_freebsd_arm64.go and ztypes_freebsd_arm64.go are just
copie of the freebsd/amd64 version of the files. Regenerate once
bootstrapping a compiler works.

Change-Id: I90a7e3ea0c0b6ecab4033f2908331b7be164a236
@bsd-hacker
Copy link

I fix to pass argc/argv.
current diff:

diff --git a/src/runtime/rt0_freebsd_arm64.s b/src/runtime/rt0_freebsd_arm64.s
index db0e16886f..8745e922b8 100644
--- a/src/runtime/rt0_freebsd_arm64.s
+++ b/src/runtime/rt0_freebsd_arm64.s
@@ -5,8 +5,8 @@
 #include "textflag.h"

 TEXT _rt0_arm64_freebsd(SB),NOSPLIT|NOFRAME,$0
-       MOVD    0(RSP), R0      // argc
-       ADD     $8, RSP, R1     // argv
+       ADD     $8, R0, R1      // argv
+       MOVW    0(R0), R0       // argc
        BL      main(SB)

 // When building with -buildmode=c-shared, this symbol is called when the shared
@@ -35,7 +35,7 @@ TEXT _rt0_arm64_freebsd_lib(SB),NOSPLIT,$184
        // Initialize g as null in case of using g later e.g. sigaction in cgo_sigaction.go
        MOVD    ZR, g

-       MOVD    R0, _rt0_arm64_freebsd_lib_argc<>(SB)
+       MOVW    R0, _rt0_arm64_freebsd_lib_argc<>(SB)
        MOVD    R1, _rt0_arm64_freebsd_lib_argv<>(SB)

        // Synchronous initialization.
@@ -82,13 +82,13 @@ restore:
        RET

 TEXT _rt0_arm64_freebsd_lib_go(SB),NOSPLIT,$0
-       MOVD    _rt0_arm64_freebsd_lib_argc<>(SB), R0
+       MOVW    _rt0_arm64_freebsd_lib_argc<>(SB), R0
        MOVD    _rt0_arm64_freebsd_lib_argv<>(SB), R1
        MOVD    $runtime揃rt0_go(SB),R4
        B       (R4)

-DATA _rt0_arm64_freebsd_lib_argc<>(SB)/8, $0
-GLOBL _rt0_arm64_freebsd_lib_argc<>(SB),NOPTR, $8
+DATA _rt0_arm64_freebsd_lib_argc<>(SB)/4, $0
+GLOBL _rt0_arm64_freebsd_lib_argc<>(SB),NOPTR, $4
 DATA _rt0_arm64_freebsd_lib_argv<>(SB)/8, $0
 GLOBL _rt0_arm64_freebsd_lib_argv<>(SB),NOPTR, $8

diff --git a/src/runtime/sys_freebsd_arm64.s b/src/runtime/sys_freebsd_arm64.s
index 887c4a3ef1..e0509457ca 100644
--- a/src/runtime/sys_freebsd_arm64.s
+++ b/src/runtime/sys_freebsd_arm64.s
@@ -13,7 +13,7 @@
 #define AT_FDCWD -100

 #define CLOCK_REALTIME 0
-#define CLOCK_MONOTONIC 1
+#define CLOCK_MONOTONIC 4

 #define SYS_exit 1
 #define SYS_read 3
@@ -56,28 +56,30 @@ TEXT runtime揃sys_umtx_op(SB),NOSPLIT,$0
        RET

 TEXT runtime揃thr_new(SB),NOSPLIT,$0
-       MOVD param+0(FP), R0
-       MOVD size+8(FP), R1
-       MOVW $SYS_thr_new, R8
+       MOVD    param+0(FP), R0
+       MOVW    size+8(FP), R1
+       MOVD    $SYS_thr_new, R8
        SVC
        MOVW    R0, ret+16(FP)
        RET

 TEXT runtime揃thr_start(SB),NOSPLIT,$0
        // set up g
-       MOVD    R10, g_m(R11)
-       MOVD    R11, g
+       MOVD    m_g0(R0), g
+       MOVD    R0, g_m(g)
        //BL runtime揃stackcheck(SB)
        BL runtime揃mstart(SB)

-       MOVW $2, R8  // crash (not reached)
-       MOVW R8, (R8)
+       MOVD    $2, R8  // crash (not reached)
+       MOVD    R8, (R8)
        RET

 TEXT runtime揃exit(SB),NOSPLIT|NOFRAME,$0-4
        MOVW    code+0(FP), R0
        MOVD    $SYS_exit, R8
        SVC
+       MOVD    $0, R8  // crash (not reached)
+       MOVD    R8, (R8)
        RET

 // func exitThread(wait *uint32)

tklauser added a commit to tklauser/go that referenced this issue Nov 29, 2018
Taken from
golang#24715 (comment)

Change-Id: I78f863bf2f9975e392067c494b0abd1bcb9af764
@ziprandom
Copy link

@tklauser what's the status here? do these patches enable cross compilation for freebsd-arm64 already?

@tklauser
Copy link
Member

@ziprandom yes, building a bootstrap toolchain should already work.

@ziprandom
Copy link

nice! and what's missing before this can be merged?

@tklauser
Copy link
Member

@ziprandom I think we'll need to get Go building completely on freebsd/arm64 first. Also, as per https://golang.org/wiki/PortingPolicy we'd need someone to maintain the port, a builder for https://build.golang.org and someone willing to maintain that builder.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/155978 mentions this issue: unix: add support for freebsd/arm64

gopherbot pushed a commit to golang/sys that referenced this issue Jan 2, 2019
This wasn't actually generated on freebsd/arm64 yet. It's mostly a copy
of the amd64 files for now.

Updates golang/go#24715

Change-Id: If24c3c5803a4708f0b26d738f690cbea1694ca88
Reviewed-on: https://go-review.googlesource.com/c/155978
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
tklauser added a commit to tklauser/go that referenced this issue Jan 7, 2019
Taken from
golang#24715 (comment)

Change-Id: I78f863bf2f9975e392067c494b0abd1bcb9af764
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/156499 mentions this issue: route: add support for freebsd/arm64

gopherbot pushed a commit to golang/net that referenced this issue Jan 7, 2019
This wasn't actually generated on freebsd/arm64 yet. It's mostly a copy
of the amd64 files for now.

Updates golang/go#24715

Change-Id: Iee8c12c29f1d74780948553047bc693668dde0b3
Reviewed-on: https://go-review.googlesource.com/c/156499
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@bsd-hacker
Copy link

golang 1.12 is released.
Anyone work to update patches, from 1.10 to 1.12 ?

@dmgk
Copy link
Member

dmgk commented Apr 26, 2019

With @tklauser freebsd-arm64 branch rebased on current master and a few more tweaks (https://github.com/dmgk/go), I was able to build the compiler/standard lib and run a few simple programs.

% uname -a
FreeBSD rpi3.localdomain 13.0-CURRENT FreeBSD 13.0-CURRENT r346544 GENERIC  arm64
% go version
go version devel +271222c098 Fri Apr 26 12:51:33 2019 -0500 freebsd/arm64

Known issues:

  • cgo needs to be disabled. I was getting lld errors "Should not have claimed to be relaxable" - I don't know if there errors are specific to 13.0-CURRENT only:
# cmd/pprof                                                                                                                             
/usr/home/dmgk/go/pkg/tool/freebsd_arm64/link: running clang failed: exit status 254                                                                                                                                                  
Should not have claimed to be relaxable                                                                                                                                                                                             
UNREACHABLE executed at /home/dmgk/freebsd/current/contrib/llvm/tools/lld/ELF/Target.cpp:17                                                                                                                                           6!                                                                                                  
clang: error: unable to execute command: Abort trap (core dumped)                                                                                                                                                                   
clang: error: linker command failed due to signal (use -v to see invocation)                                                                                                                                                        

# cmd/trace                                                                                                                             
/usr/home/dmgk/go/pkg/tool/freebsd_arm64/link: running clang failed: exit status 254                                                                                                                                                  
Should not have claimed to be relaxable                                                                                                                                                                                             
UNREACHABLE executed at /home/dmgk/freebsd/current/contrib/llvm/tools/lld/ELF/Target.cpp:17                                                                                                                                           6!                                                                                                  
clang: error: unable to execute command: Abort trap (core dumped)                                                                                                                                                                   
clang: error: linker command failed due to signal (use -v to see invocation)                                                                                                                                                        

# cmd/go                                                                                                                    
/usr/home/dmgk/go/pkg/tool/freebsd_arm64/link: running clang failed: exit status 254                                                                                                                                                  
Should not have claimed to be relaxable                                                                                                                                                                                             
UNREACHABLE executed at /home/dmgk/freebsd/current/contrib/llvm/tools/lld/ELF/Target.cpp:17                                                                                                                                           6!                                                                                                  
clang: error: unable to execute command: Abort trap (core dumped)                                                                                                                                                                   
clang: error: linker command failed due to signal (use -v to see invocation)                                                                                                                                                        

go tool dist: FAILED: /usr/home/dmgk/go/pkg/tool/freebsd_arm64/go_bootstrap install -gcflag                                                                                                                                           s=all= -ldflags=all= std cmd: exit status 2                                                                                                                                                                                         
  • The test suite seems to be hanging after cmd/asm/internal/lex. There is a single failure up to that point:
--- FAIL: TestDisableAllCapabilities (0.03s)
    cpu_test.go:56: TestAllCapabilitiesDisabled with GODEBUG=cpu.all=off: want PASS, got FAIL
FAIL
FAIL    internal/cpu    0.079s

@MikaelUrankar
Copy link
Contributor

MikaelUrankar commented Apr 27, 2019

FWIW, I'm also working on it :) https://github.com/MikaelUrankar/go/tree/freebsd-aarch64
It's based on the work of myfreeweb, bsd-hacker and coypoop (netbsd)
I'm able to natively build go and pass the test suite.
I see the same error as dmgk with cgo and clang (it compiles fine with gcc8)
Todo:

  • - implement hwcap (or something similar based on reading ID_AA64ISAR0_EL1/ID_AA64PFR0_EL1)
  • - use the Virtual Timer Count register / vdso for timecounting.

@gopherbot
Copy link
Contributor

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

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/203420 mentions this issue: dashboard: only build tip on freebsd-arm64-dmgk builder

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/203421 mentions this issue: dashboard: add SlowBot alias for freebsd-arm64-dmgk

gopherbot pushed a commit to golang/build that referenced this issue Oct 25, 2019
This should fix TestSlowBotAliases on tip.

Updates golang/go#24715
Updates golang/go#34501

Change-Id: I80f99a5c24ef0860717605816a753fe6625aff17
Reviewed-on: https://go-review.googlesource.com/c/build/+/203421
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
gopherbot pushed a commit to golang/build that referenced this issue Oct 26, 2019
Updates golang/go#24715

Change-Id: I9f1aeac0d3b5f625e0f68b6bad17445a41a87b22
Reviewed-on: https://go-review.googlesource.com/c/build/+/203420
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
@tklauser
Copy link
Member

There still seem to be some issues with cgo, see https://golang.org/cl/199919:

--- FAIL: TestSigStackSwapping (12.99s)
    crash_test.go:95: testprogcgo SigStack exit status: signal: segmentation fault (core dumped)
    crash_cgo_test.go:480: expected "OK\n" got 
--- FAIL: TestCgoNumGoroutine (12.93s)
    crash_test.go:95: testprogcgo NumGoroutine exit status: signal: segmentation fault (core dumped)
    crash_cgo_test.go:411: expected "OK\n" got 
--- FAIL: TestEnsureDropM (21.49s)
    crash_test.go:95: testprogcgo EnsureDropM exit status: signal: segmentation fault (core dumped)
    crash_cgo_test.go:174: expected "OK\n", got 
--- FAIL: TestCgoExternalThreadSignal (26.27s)
    crash_cgo_test.go:129: exit status: signal: segmentation fault (core dumped)
--- FAIL: TestCgoExternalThreadPanic (11.53s)
    crash_test.go:95: testprogcgo CgoExternalThreadPanic exit status: signal: segmentation fault (core dumped)
    crash_cgo_test.go:82: want failure containing "panic: BOOM". output:
        
--- FAIL: TestCgoExternalThreadSIGPROF (26.92s)
    crash_cgo_test.go:106: exit status: signal: segmentation fault (core dumped)
--- FAIL: TestCgoCallbackGC (12.73s)
    crash_test.go:95: testprogcgo CgoCallbackGC exit status: signal: segmentation fault (core dumped)
    crash_cgo_test.go:70: expected "OK\n", but got:
FAIL
FAIL	runtime	101.212s
FAIL

Not sure whether these are the same as the cgo issues @dmgk and @MikaelUrankar saw. Or maybe these are some changes I forgot to pick up during rebase of https://golang.org/cl/198544.

@MikaelUrankar
Copy link
Contributor

Yes, it looks similar to the ld.lld issue. We need a linker from binutils (bfd or gold) or from llvm trunk.
I'll try tomorrow to confirm.

gopherbot pushed a commit that referenced this issue Oct 28, 2019
Based on work by Mikaël Urankar (@MikaelUrankar).

Updates #24715
Updates #35197

Change-Id: I91144101043d67d3f8444bf8389c9606abe2a66c
Reviewed-on: https://go-review.googlesource.com/c/go/+/199919
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@MikaelUrankar
Copy link
Contributor

It's ok with lld10 :
ALL TESTS PASSED

ld -v
LLD 10.0.0 (https://github.com/llvm/llvm-project 95b5d459a0eb18d3a563f8ef84489635d85cdecd) (compatible with GNU linkers)

@tklauser
Copy link
Member

tklauser commented Nov 4, 2019

The respective CLs have been submitted and the freebsd-arm64-dmgk builder has been passing for some time now. Let's close this and deal with any follow-up action in separate issues.

Thanks to everybody who contributed!

@tklauser tklauser closed this as completed Nov 4, 2019
@tklauser tklauser modified the milestones: Unplanned, Go1.14 Nov 4, 2019
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/205798 mentions this issue: dashboard: add misc-compile builder for freebsd/arm64

codebien pushed a commit to codebien/build that referenced this issue Nov 13, 2019
Updates golang/go#24715

Change-Id: I8eb3f6372d69718b6f453e5415cdf16aa00ccae6
Reviewed-on: https://go-review.googlesource.com/c/build/+/198597
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
codebien pushed a commit to codebien/build that referenced this issue Nov 13, 2019
This should fix TestSlowBotAliases on tip.

Updates golang/go#24715
Updates golang/go#34501

Change-Id: I80f99a5c24ef0860717605816a753fe6625aff17
Reviewed-on: https://go-review.googlesource.com/c/build/+/203421
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
codebien pushed a commit to codebien/build that referenced this issue Nov 13, 2019
Updates golang/go#24715

Change-Id: I9f1aeac0d3b5f625e0f68b6bad17445a41a87b22
Reviewed-on: https://go-review.googlesource.com/c/build/+/203420
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/210119 mentions this issue: doc/go1.14: document freebsd/arm64 port

gopherbot pushed a commit that referenced this issue Dec 5, 2019
Updates #24715

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

Change https://golang.org/cl/220426 mentions this issue: doc/go1.14: freebsd/arm64 requires FreeBSD 12.0 or later

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/220427 mentions this issue: doc/go1.14: document that freebsd/arm64 requires FreeBSD 12.0 or later

gopherbot pushed a commit that referenced this issue Feb 24, 2020
Updates #24715
Updates #37345

Change-Id: I787a9b2ab1c68e1d379aac0a31bdf6217f04f911
Reviewed-on: https://go-review.googlesource.com/c/go/+/220426
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
gopherbot pushed a commit that referenced this issue Feb 24, 2020
…res FreeBSD 12.0 or later

Updates #24715
Updates #37345

Change-Id: I787a9b2ab1c68e1d379aac0a31bdf6217f04f911
Reviewed-on: https://go-review.googlesource.com/c/go/+/220426
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
(cherry picked from commit 28c501b)
Reviewed-on: https://go-review.googlesource.com/c/go/+/220427
@advancedwebdeveloper
Copy link

advancedwebdeveloper commented Jan 5, 2021 via email

@davecheney
Copy link
Contributor

@advancedwebdeveloper kqueue is used by the runtime on platforms that offer it.

@golang golang locked and limited conversation to collaborators Jan 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. OS-FreeBSD
Projects
None yet
Development

No branches or pull requests