Skip to content

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

Closed

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.

Activity

  1. randall77 commented on Apr 27, 2019

    @randall77
    Contributor

    I'm pretty sure this is #2559.

  2. locked and limited conversation to collaborators on Apr 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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