]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.19] cmd/link: keep go.buildinfo even with --gc-sections
authorRuss Cox <rsc@golang.org>
Wed, 1 Feb 2023 17:15:08 +0000 (12:15 -0500)
committerDavid Chase <drchase@google.com>
Fri, 10 Feb 2023 17:30:36 +0000 (17:30 +0000)
commitf69dbb6dfa8af7a32a47070d71b82fc4ed4b9d2a
treecf53d0de963e7e6fea1a4d0cdb4f8bdc73bf302f
parenta16d4892d4e901579bb630f32502cf01db59d64e
[release-branch.go1.19] cmd/link: keep go.buildinfo even with --gc-sections

If you use an external linker with --gc-sections, nothing refers
to .go.buildinfo, so the section is deleted, which in turns makes
'go version' fail on the binary. It is important for vulnerability
scanning and the like to be able to run 'go version' on any binary.

Fix this by inserting a reference to .go.buildinfo from the rodata
section, which will not be GC'ed.

Fixes #58222.
Fixes #58223.

Change-Id: I1e13e9464acaf2f5cc5e0b70476fa52b43651123
Reviewed-on: https://go-review.googlesource.com/c/go/+/464435
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-on: https://go-review.googlesource.com/c/go/+/464795
src/cmd/go/testdata/script/version_gc_sections.txt [new file with mode: 0644]
src/cmd/link/internal/ld/data.go