Skip to content

cmd/compile: linker does not elide unused global maps #31704

Closed
@dsnet

Description

@dsnet

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions