Disclaimer first: I'm no expert of compilation toolchains and executable file formats. I'll try not to say stupid things, but correct me if you see any mistake !
I ran those tests on an ArchLinux laptop, with x86_64 architecture. Go version is 1.8.1.
First, we need to know where those flags are actually used:
$ go help build
...
-ldflags 'flag list'
arguments to pass on each go tool link invocation
...
go tool link
$ go tool link
...
-s disable symbol table
...
-w disable DWARF generation
...
Taken from the short introduction to ELF that I found here, here is the header text concerning the Symbol Table:
An object file’s symbol table holds information needed to locate and relocate a program’s symbolic definitions and references.
As for DWARF, this is a format for debugging data.
-ldflags='-s'-ldflags='-w'
.symtab.debug_info
readelfnm
debug/elf
package main
import "fmt"
import "os"
import "debug/elf"
func main() {
fileName := "path/to/main"
fp, err := elf.Open(fileName)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
symtab := fp.Section(".symtab")
if symtab == nil {
fmt.Println("No Symbol Table : compiled with -ldflags='-s'")
}
debugInfo := fp.Section(".debug_info")
if debugInfo == nil {
fmt.Println("No DWARF data : compiled with -ldflags='-w'")
}
}
-s-w-s -w-s
debug/pe