From 77aea691762f46daeb56c2e1fe764fd3898fff6b Mon Sep 17 00:00:00 2001
From: Alberto Donizetti
This document explains how to use gccgo, a compiler for
-the Go language. The gccgo compiler is a new frontend
-for GCC, the widely used GNU compiler. Although the
+the Go language. The gccgo compiler is a new frontend
+for GCC, the widely used GNU compiler. Although the
frontend itself is under a BSD-style license, gccgo is
normally used as part of GCC and is then covered by
the GNU General Public
@@ -24,10 +24,10 @@ compiler.
The simplest way to install gccgo is to install a GCC binary release
-built to include Go support. GCC binary releases are available from
+built to include Go support. GCC binary releases are available from
various
websites and are typically included as part of GNU/Linux
-distributions. We expect that most people who build these binaries
+distributions. We expect that most people who build these binaries
will include Go support.
Due to timing, the GCC 4.8.0 and 4.8.1 releases are close to but not
-identical to Go 1.1. The GCC 4.8.2 release includes a complete Go
+identical to Go 1.1. The GCC 4.8.2 release includes a complete Go
1.1.2 implementation.
The GCC 5 releases include a complete implementation of the Go 1.4
-user libraries. The Go 1.4 runtime is not fully merged, but that
+user libraries. The Go 1.4 runtime is not fully merged, but that
should not be visible to Go programs.
The GCC 6 releases include a complete implementation of the Go 1.6.1
-user libraries. The Go 1.6 runtime is not fully merged, but that
+user libraries. The Go 1.6 runtime is not fully merged, but that
should not be visible to Go programs.
The GCC 7 releases include a complete implementation of the Go 1.8.1
-user libraries. As with earlier releases, the Go 1.8 runtime is not
+user libraries. As with earlier releases, the Go 1.8 runtime is not
fully merged, but that should not be visible to Go programs.
-The GCC 8 releases are expected to include a complete implementation
-of the Go 1.10 release, depending on release timing. The Go 1.10
-runtime has now been fully merged into the GCC development sources,
-and concurrent garbage collection is expected to be fully supported in
-GCC 8.
+The GCC 8 releases include a complete implementation of the Go 1.10.1
+release. The Go 1.10 runtime has now been fully merged into the GCC
+development sources, and concurrent garbage collection is fully
+supported.
+
+The GCC 9 releases include a complete implementation of the Go 1.12.2
+release.
If you cannot use a release, or prefer to build gccgo for
yourself,
-the gccgo source code is accessible via Subversion. The
+the gccgo source code is accessible via Subversion. The
GCC web site
has instructions for getting the
-GCC source code. The gccgo source code is included. As a
+GCC source code
Note that although
Building gccgo is just like building GCC
-with one or two additional options. See
+with one or two additional options. See
the instructions on the gcc web
-site. When you run
On x86 GNU/Linux systems the gccgo compiler is able to
-use a small discontiguous stack for goroutines. This permits programs
+use a small discontiguous stack for goroutines. This permits programs
to run many more goroutines, since each goroutine can use a relatively
-small stack. Doing this requires using the gold linker version 2.22
-or later. You can either install GNU binutils 2.22 or later, or you
+small stack. Doing this requires using the gold linker version 2.22
+or later. You can either install GNU binutils 2.22 or later, or you
can build gold yourself.
To build gold yourself, build the GNU binutils,
using
-The gccgo compiler works like other gcc frontends. As of GCC 5 the gccgo
+The gccgo compiler works like other gcc frontends. As of GCC 5 the gccgo
installation also includes a version of the
To run the resulting file, you will need to tell the program where to
-find the compiled Go packages. There are a few ways to do this:
+find the compiled Go packages. There are a few ways to do this:
Here
The gccgo compiler will look in the current
-directory for import files. In more complex scenarios you
+directory for import files. In more complex scenarios you
may pass the
If you use the Source code
@@ -77,10 +81,10 @@ GCC 8.
svn://gcc.gnu.org/svn/gcc/branches/gccgo
.
@@ -90,7 +94,7 @@ This branch is periodically updated with stable Go compiler sources.
gcc.gnu.org
is the most convenient way
to get the source code for the Go frontend, it is not where the master
-sources live. If you want to contribute changes to the Go frontend
+sources live. If you want to contribute changes to the Go frontend
compiler, see Contributing to
gccgo.
configure
, add the
+site. When you run configure
, add the
option --enable-languages=c,c++,go
(along with other
-languages you may want to build). If you are targeting a 32-bit x86,
+languages you may want to build). If you are targeting a 32-bit x86,
then you will want to build gccgo to default to
supporting locked compare and exchange instructions; do this by also
using the configure
option --with-arch=i586
(or a newer architecture, depending on where you need your programs to
-run). If you are targeting a 64-bit x86, but sometimes want to use
+run). If you are targeting a 64-bit x86, but sometimes want to use
the -m32
option, then use the configure
option --with-arch-32=i586
.
--with-arch-32=i586
.
--enable-gold=default
when you run
-the configure
script. Before building, you must install
-the flex and bison packages. A typical sequence would look like
+the configure
script. Before building, you must install
+the flex and bison packages. A typical sequence would look like
this (you can replace /opt/gold
with any directory to
which you have write access):
--with-ld=GOLD_BINARY
.
A number of prerequisites are required to build GCC, as
described on
the gcc web
-site. It is important to install all the prerequisites before
+site. It is important to install all the prerequisites before
running the gcc configure
script.
The prerequisite libraries can be conveniently downloaded using the
script contrib/download_prerequisites
in the GCC sources.
@@ -183,7 +187,7 @@ make install
Using gccgo
go
command,
which may be used to build Go programs as described at
https://golang.org/cmd/go.
@@ -208,7 +212,7 @@ gccgo -o file file.o
@@ -226,11 +230,11 @@ export LD_LIBRARY_PATH
${prefix}
is the --prefix
option used
-when building gccgo. For a binary install this is
-normally /usr
. Whether to use lib
+when building gccgo. For a binary install this is
+normally /usr
. Whether to use lib
or lib64
depends on the target.
Typically lib64
is correct for x86_64 systems,
-and lib
is correct for other systems. The idea is to
+and lib
is correct for other systems. The idea is to
name the directory where libgo.so
is found.
-I
or -L
option to
-gccgo. Both options take directories to search. The
+gccgo. Both options take directories to search. The
-L
option is also passed to the linker.
-g
option when you compile, you can run
-gdb
on your executable. The debugger has only limited
-knowledge about Go. You can set breakpoints, single-step,
-etc. You can print variables, but they will be printed as though they
-had C/C++ types. For numeric types this doesn't matter. Go strings
-and interfaces will show up as two-element structures. Go
+gdb
on your executable. The debugger has only limited
+knowledge about Go. You can set breakpoints, single-step,
+etc. You can print variables, but they will be printed as though they
+had C/C++ types. For numeric types this doesn't matter. Go strings
+and interfaces will show up as two-element structures. Go
maps and channels are always represented as C pointers to run-time
structures.
-A slice in Go is a structure. The current definition is +A slice in Go is a structure. The current definition is (this is subject to change):
@@ -413,15 +417,15 @@ struct __go_slice {The type of a Go function is a pointer to a struct (this is -subject to change). The first field in the +subject to change). The first field in the struct points to the code of the function, which will be equivalent to a pointer to a C function whose parameter types are equivalent, with -an additional trailing parameter. The trailing parameter is the +an additional trailing parameter. The trailing parameter is the closure, and the argument to pass is a pointer to the Go function struct. When a Go function returns more than one value, the C function returns -a struct. For example, these functions are roughly equivalent: +a struct. For example, these functions are roughly equivalent:
@@ -458,7 +462,7 @@ pointer while the C function is still using it.Go code can call C functions directly using a Go extension implemented in gccgo: a function declaration may be preceded by -
@@ -518,11 +522,11 @@ the//extern NAME
. For example, here is how the C function +//extern NAME
. For example, here is how the C functionopen
can be declared in Go:-gccgo
option instead.Compile your C code as usual, and add the option -
-- 2.50.0-fdump-go-spec=FILENAME
. This will create the +-fdump-go-spec=FILENAME
. This will create the fileFILENAME
as a side effect of the -compilation. This file will contain Go declarations for the types, -variables and functions declared in the C code. C types that can not -be represented in Go will be recorded as comments in the Go code. The +compilation. This file will contain Go declarations for the types, +variables and functions declared in the C code. C types that can not +be represented in Go will be recorded as comments in the Go code. The generated file will not have apackage
declaration, but can otherwise be compiled directly by gccgo.