Skip to content

patch: cmd/link: add opt-in mechanism to fail if reflect is used (was: TS_LINK_FAIL_REFLECT) #115

Description

@bradfitz

Back in our Go 1.17 toolchain, we had support (ab6e4fe) for TS_LINK_FAIL_REFLECT to make the linker explode if somebody used a IsReflectMethod value anywhere in the program. (e.g. using reflect.Value which then bloats binaries conservatively because a bunch of deadcode can't happen just in case a text/template or something looks up a method by a string)

bradfitz@bradm4-2 go % git co tailscale.go1.18
git gbranch 'tailscale.go1.18' set up to track 'origin/tailscale.go1.18'.
Switched to a new branch 'tailscale.go1.18'
bradfitz@bradm4-2 go % git grep TS_LINK_FAIL_REFLECT
bradfitz@bradm4-2 go % git co tailscale.go1.17
branch 'tailscale.go1.17' set up to track 'origin/tailscale.go1.17'.
Switched to a new branch 'tailscale.go1.17'
bradfitz@bradm4-2 go % git grep TS_LINK_FAIL_REFLECT
src/cmd/link/internal/ld/deadcode.go:           if v, _ := strconv.ParseBool(os.Getenv("TS_LINK_FAIL_REFLECT")); v {
src/cmd/link/internal/ld/deadcode.go:                   panic("unexpected reflect with TS_LINK_FAIL_REFLECT")

But we lost it in Go 1.18+

We should bring it back. We still set it in gocross.

/cc @barnstar @awly

Activity

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