]> Cypherpunks repositories - gostls13.git/commit
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>
Thu, 2 Feb 2023 15:17:57 +0000 (15:17 +0000)
commit54bdb8ee70892dd77651c0a092e4a2e3edbb3ab6
treeaee8c10faaeabd06def63a8da19ca53353ffd9cf
parentd871f63bcfa4d32ec442afa0f2a190543f94073f
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.

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