User:Aslantis/Full gccgo guide on Gentoo
This article is incomplete and subject to change, take caution.
gccgo is a Go compiler front end for GCC. It has the potential to work on all architectures that GCC does, as well as take all of its language-agnostic optimization flags (i.e, -O2 -pipe -march=native). However, it is usually less performant than gc (aka dev-lang/go), and is more prone to issues.
That said, gccgo is the only option on systems with a CPU architecture and OS combination unsupported by gc.
This guide will show how to set portage (and the rest of the system!) to use gccgo, and my workaround on how to set global optimization flags to it.
Installation
Installing gccgo is as simple as emerging GCC with the go USE flag!
*/gcc go
root #
emerge --ask gcc
Invocation
Two separate CLI utilities should be installed: gccgo and go-n, where n is the major version of GCC, i.e, 11.
gccgo has syntax very much alike GCC. This can be invoked if you're more comfortable coding in C.
go-n has syntax identical (plus extra goodies!) to gc. Using this should be no different than what you're used to, if you're already used to Go coding with gc.
Enabling system-wide useage
To make gccgo the default Go compiler on the system, gc will need to be removed from the system first, if installed.
root #
emerge --ask --depclean dev-lang/go
Force unmerging it should not be necessary, but if needed can be done, as another Go compiler is about to be installed.
If a package builds and runs with gccgo, and hard depends on dev-lang/go, consider making a PR/bug to remove the hard dep.
Enabling system-wide useage is simple. All that needs to be done is to link $PATH/go-n
(see bug #567806) to $PATH/go
.
root #
ln -s /usr/bin/go-11 /usr/bin/go
Now, try emerging your favorite package written in Go, and give it a spin!
Enabling system-wide optimization flags
This is tricky. The go-n utility does not seem to pull in these from any environment variables. The most likely solution in my eyes (please let me know if you think of a better one!) is to create a PR upstream to implement this functionality, or create a "wrapper" script to specify them on the command line.
The problem with this latter approach, is that the placement of these flags (or their existence at all!) depends on the subcommand to go
. For example, go build -gccgoflags -Wl,-R,${prefix}/lib/gcc/MACHINE/VERSION
is a correct useage, whereas go help -gccgoflags -O2
is not. This script would have to be called go
in $PATH and interpret commands to figure out where to place the -gccgoflags argument, if at all, to go-n.