GCCGO(1)

πŸ’– GCCGO(1) Β· gccgo πŸ’–

okay bestie, this is the manual for gccgo, and it's giving GCC-powered Go compiler energy ✨

🧚 NAME 🧚

gccgo is the GCC-based compiler for the Go language. no cap, it's iconic πŸ’…

πŸŽ€ SYNOPSIS πŸŽ€

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

only the most useful options are listed up here, so check below for the rest πŸ‘‡πŸŒΈ

🌈 DESCRIPTION 🌈

okay so gccgo is a frontend to gcc and it supports a lot of the same options 🫢 this page only covers the stuff that's specific to gccgo, so you don't have to relearn all of gcc πŸ™ˆ

the gccgo command can compile Go source code into an object file, link a bunch of object files together, or do both in sequence. main character energy πŸ¦‹

Go source code gets compiled as packages πŸ“¦ a package is one or more Go source files. all the files in one package have to be compiled together, so pass every file as an argument to gccgo. a single invocation of gccgo can only compile a single package, so don't try to be extra πŸ’€

one Go package can "import" a different Go package. the imported package has to be compiled already, and gccgo reads the import data straight from the compiled package πŸ§ƒ when this package gets linked later, the compiled form of that package has to be 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 generally cause it to misbehave or fail. do not strip your Go programs, bestie 😭

πŸ¦‹ OPTIONS πŸ¦‹

  • -Idir β€” pick a directory to search when hunting for an import package at compile time πŸ“‚
  • -Ldir β€” when linking, set a library search directory, same as with gcc πŸ”—
  • -fgo-pkgpath=string β€” sets the package path ✨ this is the value returned by the PkgPath method of reflect.Type objects, and it's also used for the names of globally visible symbols. the argument should normally be the string that gets used to import this package after it's installed, which is basically a pathname inside the directories given by the -I option πŸ›£οΈ
  • -fgo-prefix=string β€” an 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 have to be imported using different pathnames. for this to work with gccgo, you need to specify either -fgo-pkgpath or -fgo-prefix when compiling a package πŸŽ€ using either one also turns off the special treatment of the "main" package and lets it be imported like any other πŸ™Œ
  • -fgo-relative-import-path=dir β€” a relative import is one that starts with ./ or ../ 🧭 if you use 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 caught 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, use this option. or you can remove the checks with -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, division overflow happens when computing INT_MIN / -1. in Go this should be wrapped to produce INT_MIN. some processors, like x86, generate a trap on division overflow, so on those systems use this option. or remove the checks with -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 info πŸ”Ž 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 that match the given suffix n. you can use this to binary search across functions and 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, and some additional compiler directives are supported.
  • -fgo-embedcfg=file β€” identifies a JSON file that maps patterns used with the 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 use when it implements //go:embed.
  • -g β€” this is the standard gcc option, but it's mentioned here because by default gccgo turns on debugging information generation with the equivalent of the standard option -g1 πŸͺ² Go programs need debugging info to get backtrace information. an explicit -g0 disables debugging info generation, but then certain standard library functions, like "runtime.Callers", won't work 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. 🌷

Permission is granted 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.

that's a wrap, bestie πŸ¦‹πŸ’– this page is from gcc-12 and was dated 2022-02-22. go compile something iconic πŸŽ€βœ¨

πŸ“¦ where this page comes from