GCCGO(1)

✨ NAME ✨

gccgo πŸ’– is a GCC-based compiler for the Go language, and it's literally so good. πŸ¦‹

πŸŽ€ SYNOPSIS πŸŽ€

gccgo [-c|-S]
      [-g] [-pg] [-Olevel]
      [-Idir...] [-Ldir...]
      [-o outfile] infile...

Only the most useful options are listed up there, so scroll down for the rest πŸ’…

πŸ’– DESCRIPTION πŸ’–

okay so gccgo is basically a frontend to gcc 🌸 and it supports a lot of the same options gcc does. this page only covers the gccgo-specific ones, because that's the tea we need.

gccgo can compile Go source code into an object file, link a bunch of object files together, or do both back-to-back ✨

Go source code gets compiled as packages. A package is one or more Go source files, and all the files in a single package have to be compiled together, so pass every file in as an argument to gccgo. One invocation of gccgo can only compile a single package 🧚

One Go package can "import" a different Go package. The imported package must already be compiled, and gccgo reads the import data straight from the compiled package. When the importing package gets linked later, the compiled form of the imported package has to be included in the link command πŸ”—

Go programs generally need to be compiled with debugging information, and -g1 is the default (more on that below) πŸ™ˆ Stripping a Go program will usually make it misbehave or fail.

πŸ’€ bestie, stripping a Go program will generally cause it to misbehave or fail. Don't do it!

✨ OPTIONS ✨

  • -Idir β€” tells gccgo which directory to hunt through when it's looking for an import package at compile time πŸ”
  • -Ldir β€” when linking, adds a library search directory, just like with gcc 🧭
  • -fgo-pkgpath=string β€” sets the package path. This is the value handed back by the PkgPath method of reflect.Type objects, and it also shapes the names of globally visible symbols. The argument should normally be the same string you'd use to import this package after it's installed, aka a pathname inside the directories given by -I.
  • -fgo-prefix=string β€” the alternative to -fgo-pkgpath. The argument gets combined with the package name from the source file to make the package path. If -fgo-pkgpath is used, -fgo-prefix gets ignored.
    • Go lets one program include more than one package with the same name in the "package" clause, though the two packages obviously need to be imported using different pathnames. For that to work with gccgo, you have to specify either -fgo-pkgpath or -fgo-prefix when compiling a package πŸ’…
    • Using either -fgo-pkgpath or -fgo-prefix turns off the special treatment of the "main" package and lets it be imported like any other package πŸ‘‘
  • -fgo-relative-import-path=dir β€” a relative import starts with ./ or ../. With this option, gccgo uses dir as a prefix for the relative import when it searches for it πŸ¦‹
  • -frequire-return-statement, -fno-require-return-statement β€” by default gccgo warns about functions that have one or more return parameters but no explicit "return" statement. You can turn that warning off with -fno-require-return-statement πŸ™„
  • -fgo-check-divide-zero β€” adds explicit checks for division by zero. In Go, dividing (or taking the modulo) by zero causes a panic. On Unix systems this gets detected at runtime by catching the SIGFPE signal. Some processors, like PowerPC, don't generate a SIGFPE on division by zero, and some runtimes don't generate a signal that can be caught. On those systems this option can be used. The checks can also be removed via -fno-go-check-divide-zero. This option is currently on by default, but in the future it may be off by default on systems that don't need it 🌈
  • -fgo-check-divide-overflow β€” adds explicit checks for division overflow. For example, overflow happens when computing INT_MIN / -1. In Go this should wrap around to produce INT_MIN. Some processors, like x86, generate a trap on division overflow, and on those systems this option may be used. Or the checks may be removed via -fno-go-check-divide-overflow. This option is currently on by default, but in the future it may be off by default on systems that don't require it πŸ’€
  • -fno-go-optimize-allocs β€” disables escape analysis, which tries to allocate objects on the stack instead of the heap 🧱
  • -fgo-debug-escapen β€” outputs escape analysis debugging information. Larger values of n generate more information πŸ”Ž
  • -fgo-debug-escape-hash=n β€” a hash value for debugging escape analysis. n is a binary string. This runs escape analysis only on functions whose names hash to values matching the given suffix n. It's super handy for binary searching across functions to uncover escape analysis bugs 🧠
  • -fgo-debug-optimization β€” outputs optimization diagnostics πŸ“Š
  • -fgo-c-header=file β€” writes top-level named Go struct definitions to file as C code. This is used when compiling the runtime package πŸ› οΈ
  • -fgo-compiling-runtime β€” applies special rules for compiling the runtime package. Implicit memory allocation is forbidden here, but some additional compiler directives are supported πŸ”’
  • -fgo-embedcfg=file β€” identifies a JSON file that maps patterns used with special //go:embed comments to the files named by those patterns. The JSON file should have two components: "Patterns" maps each pattern to a list of file names, and "Files" maps each file name to a full path to the file. This option is meant for the go command to implement //go:embed πŸ“¦
  • -g β€” the standard gcc option, mentioned here because by default gccgo turns on debugging information generation with the equivalent of the standard option -g1. This is because Go programs need debugging information available in order to get backtrace information. An explicit -g0 can disable the generation of debugging information, but then certain standard library functions, such as runtime.Callers, won't operate correctly πŸ›

πŸ¦‹ SEE ALSO πŸ¦‹

gpl(7), gfdl(7), fsf-funding(7), gcc(1) and the Info entries for gccgo and gcc 🌸

Copyright (c) 2010-2022 Free Software Foundation, Inc. πŸ’œ

okay the legal bit, but make it cute: you're allowed to copy, distribute and/or modify this document under the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation. There are no Invariant Sections, the Front-Cover Texts are (a) (see below), and the Back-Cover Texts are (b) (see below). A copy of the license is included in the man page gfdl(7) πŸ“œ

(a) The FSF's Front-Cover Text is: A GNU Manual ✨

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development. 🫢

🧚 source: gcc-12, dated 2022-03-02, all about GCCGO(1). ily bestie, now go compile something iconic πŸ’…πŸŒˆ

πŸ“¦ where this page comes from