March 2020
Intermediate to advanced
406 pages
8h 39m
English
While building a Go binary, the -gcflags flag lets you pass optional compiler arguments, while the -ldflags flag lets you pass optional linker arguments. A full list of compiler and linker flags can be found by invoking the following commands:
go tool compile -helpgo tool link -help
Let's look at an example of utilizing compiler and linker flags. We can build a simple program that returns the value of an uninitialized string variable. The following program seems innocuous enough:
package mainimport "fmt"var linkerFlag stringfunc main() { fmt.Println(linkerFlag)}
If we build this with some of the common compiler and linker flags, we will see some helpful output:
The compiler flags that we passed here achieve the ...
Read now
Unlock full access