Skip to content

Instantly share code, notes, and snippets.

@jxsl13
Last active October 15, 2024 02:23
Show Gist options
  • Save jxsl13/22f0d461e6e8b18a14869ddb46066523 to your computer and use it in GitHub Desktop.
Save jxsl13/22f0d461e6e8b18a14869ddb46066523 to your computer and use it in GitHub Desktop.

Porting Go to SPARC Solaris

Source: https://sysadm.life/posts/porting_golang_to_sparc/

Learn how to compile and port Go for SPARC Solaris Tue, 18 Dec 2018 label GO Solaris
This article aims to present the steps required to create a port of Go for SPARC Solaris. The ‘spark’ that kicked this idea off was part of an aspiration to first get the Prometheus node exporter for the core machine metrics running on SPARC tin for Solaris 11.3, then potentially other node exporters such as the JMX exporter and a Oracle DB exporter.

Note: Oracle announced Go version 1.7.6 will be available in Solaris 11.4. However, it seems like that 11.4 is a no go for a lot of SPARC hardware

A port of Go for SPARC is available here:

https://github.com/4ad/go

This post is based on discussions from the porting go to sparc Solaris discussion from the golang-dev@googlegroups.com Google group available here:

https://Go-dev.narkive.com/g6r4eJoA/porting-go-to-sparc-solaris

What I ended up doing was compiling Go on an x86 based Linux system and then copying that over and using it on my sparc based Solaris system.

Let’s give it a GO!

First things first, let’s stage the required media and get Go installed on our Linux box.

mkdir -p /opt/stage
cd /opt/stage
wget https://dl.google.com/go/go1.12.5.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.12.5.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
git clone https://github.com/4ad/go.git

Now every thing is in place, time to try a build for SPARC Solaris:

cd /opt/stage/go
echo "GO_build_01" >> VERSION

export GOROOT_BOOTSTRAP=/usr/local/go
export GOROOT=/usr/local/go

export GOARCH=sparc64
export GOOS=solaris

cd /opt/stage/go/src
./make.bash

Great, that looked to have worked. Now let’s archive that up and get it over to the SPARC server.

cd /opt/stage
tar -cvf go_go_sun.tar go

Testing

Here’s a quick example of building and running a ‘Hello World’ program. All the below steps are performed on a Solaris 11.3 zone.

Sample code for ‘hello.go’:

package main

import "fmt"

func main() {
        fmt.Printf("hello, world\n")
}

After copying over and extracting our ‘go_go_sun.tar’ archive to ‘/usr/local/gosparc’ set the below relevant enviorment variables.

mkdir /usr/local/gosparc
export GOOS=solaris
export GOARCH=sparc64
export PATH=$PATH:/usr/local/gosparc/go/bin/solaris_sparc64
go build

Post performing the build for our ‘Hello World’ application we now have a ‘hello’ binary.

ls -l
  total 1675
  -rw-r--r--   1 user     user          82 Jun  5 17:06 hello.go
  -rwxr-xr-x   1 user     user     1814246 Jun  6 09:52 hello
./hello
 hello, world
go version
 go version GO_build_01 solaris/sparc64

Great it works!

@jxsl13
Copy link
Author

jxsl13 commented Jan 11, 2022

More references to building Go on exotic target systems:
https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63

@Here-Be-Saoirse
Copy link

Attempted this on an x64 linux host. Didn't work

freya@moana:/storage/opt/stage/go/src$ ./make.bash  
##### Building Go bootstrap tool.
cmd/dist
go: cannot find main module, but found .git/config in /storage/opt/stage/go
        to create a module there, run:
        cd .. && go mod init
freya@moana:/storage/opt/stage/go/src$

@mirusky
Copy link

mirusky commented Oct 15, 2024

Set go mod disabled:

export GO111MODULE=off

@Here-Be-Saoirse
Copy link

copy, noted. thank

@Here-Be-Saoirse
Copy link

update. It dettonated!

freya@moana:/storage/opt/stage/goroot/src$ export GOOS=solaris
freya@moana:/storage/opt/stage/goroot/src$ export GOARCH=sparc64
freya@moana:/storage/opt/stage/goroot/src$ GO111MODULE=off ./make.bash
##### Building Go bootstrap tool.
cmd/dist

##### Building Go toolchain using /storage/opt/go.

##### Building go_bootstrap for host, linux/amd64.
runtime/internal/sys
runtime/internal/atomic
runtime
go_asm.h:272:26: 'p' exponent requires hexadecimal mantissa
go_asm.h:468:33: 'p' exponent requires hexadecimal mantissa
go_asm.h:1159:26: 'p' exponent requires hexadecimal mantissa
go_asm.h:272:26: 'p' exponent requires hexadecimal mantissa
go_asm.h:468:33: 'p' exponent requires hexadecimal mantissa
go_asm.h:1159:26: 'p' exponent requires hexadecimal mantissa
encoding
internal/race
math
unicode/utf8
errors
unicode
unicode/utf16
sync/atomic
sort
sync
container/heap
io
internal/singleflight
syscall
bytes
hash
strings
hash/adler32
strconv
bufio
path
reflect
encoding/base64
regexp/syntax
crypto
internal/syscall/windows/registry
internal/syscall/windows
time
crypto/sha1
regexp
os
encoding/binary
fmt
os/signal
path/filepath
io/ioutil
os/exec
go/token
log
encoding/json
text/template/parse
compress/flate
flag
debug/dwarf
net/url
go/scanner
go/ast
compress/zlib
text/template
debug/macho
debug/elf
go/parser
go/doc
go/build
cmd/go
runtime (solaris/sparc64)

##### Building packages and commands for host, linux/amd64.
runtime/internal/sys
runtime/internal/atomic
runtime
# runtime
go_asm.h:272:26: 'p' exponent requires hexadecimal mantissa
go_asm.h:468:33: 'p' exponent requires hexadecimal mantissa
go_asm.h:1159:26: 'p' exponent requires hexadecimal mantissa
# runtime
go_asm.h:272:26: 'p' exponent requires hexadecimal mantissa
go_asm.h:468:33: 'p' exponent requires hexadecimal mantissa
go_asm.h:1159:26: 'p' exponent requires hexadecimal mantissa
sync/atomic
errors
internal/race
unicode
unicode/utf8
sort
math
container/list
container/ring
crypto/subtle
encoding
unicode/utf16
runtime/race
image/color
cmd/vet/internal/whitelist
sync
io
syscall
internal/singleflight
image/color/palette
container/heap
hash
crypto/cipher
runtime/trace
hash/adler32
hash/crc32
crypto/hmac
hash/crc64
hash/fnv
bytes
strings
bufio
text/tabwriter
strconv
math/rand
math/cmplx
html
path
compress/bzip2
time
internal/syscall/unix
regexp/syntax
reflect
crypto
crypto/aes
crypto/rc4
encoding/base64
encoding/ascii85
encoding/base32
image
crypto/md5
crypto/sha512
crypto/sha1
crypto/sha256
encoding/pem
image/internal/imageutil
image/draw
image/jpeg
os
regexp
path/filepath
runtime/debug
os/signal
encoding/binary
fmt
io/ioutil
os/exec
cmd/pprof/internal/svg
crypto/des
index/suffixarray
flag
log
cmd/internal/unvendor/golang.org/x/arch/arm/armasm
cmd/internal/unvendor/golang.org/x/arch/x86/x86asm
compress/flate
debug/dwarf
debug/gosym
debug/plan9obj
archive/tar
compress/lzw
math/big
encoding/hex
go/token
database/sql/driver
encoding/csv
encoding/gob
encoding/json
encoding/xml
internal/golang.org/x/net/http2/hpack
mime
mime/quotedprintable
net/http/internal
net/url
text/template/parse
text/scanner
runtime/pprof
internal/trace
image/gif
net/internal/socktest
database/sql
go/scanner
testing/iotest
cmd/compile/internal/big
cmd/internal/gcprog
cmd/pack
cmd/internal/obj
testing/quick
go/ast
cmd/asm/internal/flags
cmd/pprof/internal/tempfile
testing
compress/zlib
archive/zip
compress/gzip
debug/macho
debug/pe
text/template
debug/elf
image/png
cmd/pprof/internal/profile
internal/testenv
crypto/dsa
crypto/elliptic
encoding/asn1
crypto/rand
go/constant
cmd/internal/obj/arm
cmd/internal/goobj
cmd/internal/obj/arm64
cmd/internal/obj/mips
cmd/internal/obj/ppc64
cmd/internal/obj/sparc64
cmd/internal/obj/x86
cmd/asm/internal/lex
go/parser
go/printer
crypto/rsa
cmd/dist
cmd/link/internal/ld
crypto/x509/pkix
cmd/internal/objfile
crypto/ecdsa
go/doc
html/template
cmd/pprof/internal/plugin
cmd/pprof/internal/symbolz
go/types
cmd/pprof/internal/symbolizer
cmd/addr2line
cmd/nm
cmd/objdump
cmd/cgo
go/format
cmd/gofmt
cmd/compile/internal/ssa/gen
cmd/fix
cmd/yacc
go/build
cmd/compile/internal/ssa
cmd/pprof/internal/report
cmd/asm/internal/arch
cmd/asm/internal/asm
cmd/cover
cmd/doc
cmd/newlink
cmd/pprof/internal/commands
cmd/asm
cmd/pprof/internal/driver
runtime/cgo
go/internal/gccgoimporter
go/internal/gcimporter
cmd/api
cmd/link/internal/amd64
cmd/link/internal/arm
cmd/link/internal/arm64
cmd/link/internal/mips64
cmd/link/internal/ppc64
cmd/link/internal/sparc64
cmd/link/internal/x86
go/importer
cmd/link
cmd/vet
net
os/user
crypto/x509
net/textproto
log/syslog
mime/multipart
net/mail
crypto/tls
net/http
net/smtp
cmd/compile/internal/gc
expvar
net/http/cgi
net/http/cookiejar
net/http/httptest
net/http/pprof
net/http/httputil
net/rpc
cmd/go
cmd/pprof/internal/fetch
cmd/trace
cmd/pprof
net/http/fcgi
net/rpc/jsonrpc
cmd/compile/internal/amd64
cmd/compile/internal/arm
cmd/compile/internal/arm64
cmd/compile/internal/mips64
cmd/compile/internal/ppc64
cmd/compile/internal/sparc64
cmd/compile/internal/x86
cmd/compile

##### Building packages and commands for solaris/sparc64.
runtime/internal/sys
runtime/internal/atomic
runtime
internal/race
sync/atomic
errors
unicode
unicode/utf8
math
sort
container/list
container/ring
crypto/subtle
encoding
unicode/utf16
image/color
runtime/race
cmd/vet/internal/whitelist
# sync/atomic
sync/atomic/doc.go:56: missing function body for "SwapInt32"
sync/atomic/doc.go:59: missing function body for "SwapInt64"
sync/atomic/doc.go:62: missing function body for "SwapUint32"
sync/atomic/doc.go:65: missing function body for "SwapUint64"
sync/atomic/doc.go:68: missing function body for "SwapUintptr"
sync/atomic/doc.go:71: missing function body for "SwapPointer"
sync/atomic/doc.go:74: missing function body for "CompareAndSwapInt32"
sync/atomic/doc.go:77: missing function body for "CompareAndSwapInt64"
sync/atomic/doc.go:80: missing function body for "CompareAndSwapUint32"
sync/atomic/doc.go:83: missing function body for "CompareAndSwapUint64"
sync/atomic/doc.go:83: too many errors
container/heap
image/color/palette
# math
math/asin.go:19: missing function body for "Asin"
math/asin.go:51: missing function body for "Acos"
math/atan.go:95: missing function body for "Atan"
math/atan2.go:29: missing function body for "Atan2"
math/dim.go:13: missing function body for "Dim"
math/dim.go:26: missing function body for "Max"
math/dim.go:53: missing function body for "Min"
math/exp.go:14: missing function body for "Exp"
math/exp.go:135: missing function body for "Exp2"
math/expm1.go:124: missing function body for "Expm1"
math/expm1.go:124: too many errors
freya@moana:/storage/opt/stage/goroot/src$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment