Disclaimer in the first place: I am not an expert in compilation toolkits and executable file formats. I will try not to say stupid things, but correct me if you see any mistake!
I ran these tests on an x86_64 ArchLinux laptop. Go version 1.8.1.
First, we need to know where these flags are 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
...
ELF, , , :
, .
DWARF, .
, , DWARF? ELF. , , , , , . , , Golang -ldflags='-s' -ldflags='-w':
- Go ,
.symtab - Go DWARF,
.debug_info. , , .
Linux , . readelf nm , , , .
, Go 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'")
}
}
Golang Hello World, , -s, -w -s -w. , -s DWARF, . , , .
ELF , Windows ( debug/pe).