-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/link: make it easy to find binary versions
It is useful to be able to dig the Go version out of a binary, even a stripped binary. rsc.io/goversion does this for x86 binaries by disassembling the binary to find runtime/proc.go's startup-time reference to runtime.buildVersion's address. That approach is quite fragile: the implementation doesn't work for non-x86 and must be updated as the generated code changes. rsc.io/goversion finds the module version string by looking for random 16-byte framing around the actual string. This is less fragile but fairly kludgy and requires scanning the entire data segment. cmd/buildid finds the build ID by looking for an ELF note or else falling back to scanning the beginning of the text segment for a magic string. This has proved quite reliable and doesn't require scanning much of the binary. This CL makes it possible to find the Go and module versions using a scan more like the build ID scan: a symbol early in the writable data segment starts with a magic number and then has pointers to the two string variables. Setting up for "go version <binary>". For #31624. Change-Id: I78ea8c52fe1686b5cc5a829ca5f198104d10ebf0 Reviewed-on: https://go-review.googlesource.com/c/go/+/173342 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
- Loading branch information
Showing
5 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,8 @@ const ( | |
SPCLNTAB | ||
|
||
// Writable sections. | ||
SFirstWritable | ||
SBUILDINFO | ||
SELFSECT | ||
SMACHO | ||
SMACHOGOT | ||
|