Closed
Description
Using go1.12
Consider the following snippet:
package main
var GlobalMap = map[string]struct{}{"MY_GLOBAL_MAP": {}}
var GlobalSlice = []string{"MY_GLOBAL_SLICE"}
func main() {}
If I build the program and grep for my magic string, it is in the final binary:
$ go build main.go && strings main | grep -oE "MY_GLOBAL_(MAP|SLICE)"
MY_GLOBAL_MAP
This suggests that this global map is linked into the final binary even if unused. On the other hand, unused global slices are not linked into the final binary.