User:Aslantis/Full gccgo guide on Gentoo

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 the "official" Go compiler, and is more prone to issues. That said, gccgo is the only option on systems with a CPU architecture and OS combination unsupported by the "official" compiler.

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!

Invocation
Two separate CLI utilities should be installed: and, where n is the major version of GCC, i.e, 11.

has syntax very much alike GCC. This can be invoked if you're more comfortable coding in C.

has syntax identical (plus extra goodies!) to the "official" Go compiler. Using this should be no different than what you're used to, if you're used to the "official" Go compiler.

Enabling system-wide useage
To make gccgo the default Go compiler on the system, the "official" Go compiler will need to be removed from the system first, if installed.

Force unmerging it should not be necessary, but if needed can be done, as another Go compiler is about to be installed.

Enabling system-wide useage is simple. All that needs to be done is to link  to.

Now, try emerging your favorite package written in Go, and give it a spin!

Enabling system-wide optimization flags
This is tricky. The 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. For example,  is a correct useage, whereas   is not. This script would have to be called  in $PATH and interpret commands to figure out where to place the -gccgoflags argument, if at all, to.