]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.20] 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)
committerGopher Robot <gobot@golang.org>
Fri, 10 Feb 2023 17:19:20 +0000 (17:19 +0000)
commitfbba58a0a4f5ff4f3aa4cfa0d494b6d2fefd068a
tree12d62d1a6a0d68bb6f80ee5bfe78cfcb7106baba
parent9987cb6cf34cc893887ad2ecc9d832ee3c69c255
[release-branch.go1.20] 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 #58224.

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/+/464796
src/cmd/go/testdata/script/version_gc_sections.txt [new file with mode: 0644]
src/cmd/link/internal/ld/data.go