GCCGO(1)

๐Ÿ“ฆ
version 9.5.0 ยท 2 versions
, in ubuntu noble

โœจ gccgo โœจ

okay bestie, this is the GNU manual page for gccgo ๐ŸŽ€ Let's get into it ๐Ÿ’…

โœจ NAME โœจ

gccgo โ€” a GCC-based compiler for the Go language ๐Ÿ’œ

๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

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

Heads up ๐Ÿ‘€ this only shows the most useful options. The rest are down in OPTIONS, so keep scrolling ๐Ÿซถ

๐ŸŒธ DESCRIPTION ๐ŸŒธ

Okay so gccgo is a frontend to gcc and it supports a bunch of the same options ๐Ÿ’… This page only covers the options that are specific to gccgo, so you're not reading the same stuff twice โœจ

You can use gccgo to compile Go source code into an object file, link a collection of object files together, or do both in one go. Main character energy ๐Ÿ‘‘

Go source code gets compiled as packages ๐Ÿ“ฆ A package is made of one or more Go source files. All the files in one package have to be compiled together, so you pass every file as an argument to gccgo. A single invocation of gccgo can only compile a single package, no exceptions ๐Ÿ™…โ€โ™€๏ธ

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 you link this package later, the compiled form of the imported package needs to be in the link command too, or it's giving broken ๐Ÿ’€

๐Ÿšจ 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 make it misbehave or fail entirely, so please don't do it, bestie ๐Ÿ˜ญ

๐Ÿ’– OPTIONS ๐Ÿ’–

  • -Idir โ€” tell it which directory to check when searching for an import package at compile time ๐Ÿ“‚
  • -Ldir โ€” when linking, add a library search directory, just like with gcc ๐Ÿ”—
  • -fgo-pkgpath=string โ€” sets the package path ๐Ÿ›ฃ๏ธ This is the value that the PkgPath method of reflect.Type objects returns, and it's also used for the names of globally visible symbols. Normally the argument should be the same string you'd use to import this package once it's installed. In other words, it's a pathname inside the directories you gave to the -I option.
  • -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 you use -fgo-pkgpath too, then -fgo-prefix gets ignored, so -fgo-pkgpath wins ๐Ÿ†
    • A single program can include more than one package with the same name in the "package" clause, obviously as long as the two packages get imported using different pathnames ๐Ÿ™„
    • For that to work with gccgo, you must 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, so that package can be imported like any other one ๐ŸŒˆ
  • -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 goes searching for it.
  • -frequire-return-statement, -fno-require-return-statement โ€” by default, gccgo warns you about functions that have one or more return parameters but don't have an 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, a division (or modulos) by zero causes a panic. On Unix systems, the runtime catches this 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 even be caught. On those systems, use this option. You can also remove the checks with -fno-go-check-divide-zero. This option is currently on by default, but in the future it might 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, that should wrap around and produce INT_MIN. Some processors, like x86, generate a trap on division overflow. On those systems, use this option. Or you can remove the checks with -fno-go-check-divide-overflow. Right now it's on by default, but in the future it might be off by default on systems that don't require it ๐Ÿ’…
  • -fno-go-optimize-allocs โ€” disables escape analysis, which is the thing that 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, so go big or go home ๐Ÿ”ฅ
  • -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 it to binary search across functions and uncover escape analysis bugs ๐Ÿ•ต๏ธโ€โ™€๏ธ
  • -fgo-c-header=file โ€” writes the top-level named Go struct definitions to file as C code ๐Ÿ“ This gets used when compiling the runtime package.
  • -fgo-compiling-runtime โ€” applies special rules for compiling the runtime package ๐Ÿ‘‘ Implicit memory allocation is forbidden here ๐Ÿ™…โ€โ™€๏ธ A few extra compiler directives are supported too.
  • -g โ€” this is the standard gcc option, and it's mentioned here because gccgo turns on debugging information generation by default, which is the equivalent of the standard option -g1 ๐Ÿ› Go programs need debugging information so they can get backtrace information, which is why it's on by default. You can use an explicit -g0 to disable generating debugging information, but then certain standard library functions, like runtime.Callers, won't work correctly ๐Ÿ’€
โš ๏ธ Using -g0 means runtime.Callers will not operate correctly. Don't say I didn't warn you ๐Ÿ™ˆ

๐Ÿงš SEE ALSO ๐Ÿงš

gpl(7), gfdl(7), fsf-funding(7), gcc(1) and the Info entries for gccgo and gcc ๐Ÿ“š

Copyright (c) 2010-2019 Free Software Foundation, Inc. โœจ

You can copy, distribute, and/or modify this document under the terms of 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.

Okay that's the whole tea โ˜•๐ŸŒธ This page is from gcc-9, dated 2022-05-27, so go compile something cute, bestie ๐Ÿฆ‹๐Ÿ’–

๐Ÿ“ฆ where this page comes from