aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/buildid
AgeCommit message (Collapse)Author
2025-10-21all: eliminate unnecessary type conversionsJes Cok
Found by github.com/mdempsky/unconvert Change-Id: I88ce10390a49ba768a4deaa0df9057c93c1164de GitHub-Last-Rev: 3b0f7e8f74f58340637f33287c238765856b2483 GitHub-Pull-Request: golang/go#75974 Reviewed-on: https://go-review.googlesource.com/c/go/+/712940 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: David Chase <drchase@google.com>
2024-10-21cmd/internal/buildid: skip over GNU build ID from buildid computationCherry Mui
This is similar to CL 618597, but for GNU build ID on ELF. This makes it possible to enable "-B gobuildid" by default on ELF. Updates #41004. For #63934. Change-Id: I4e663a27a2f7824bce994c783fe6d9ce8d1a395a Reviewed-on: https://go-review.googlesource.com/c/go/+/618600 Reviewed-by: Than McIntosh <thanm@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-10-21cmd/internal/buildid: skip over Mach-O UUID from buildid computationCherry Mui
With the "-B gobuildid" linker option (which will be the default on some platforms), the host build ID (GNU build ID, Mach-O UUID) depends on the Go buildid. If the host build ID is included in the Go buildid computation, it will lead to convergence problem for the toolchain binaries. So ignore the host build ID in the buildid computation. This CL only handles Mach-O UUID. ELF GNU build ID will be handled later. For #68678. For #63934. Cq-Include-Trybots: luci.golang.try:gotip-darwin-amd64_14,gotip-darwin-arm64_13 Change-Id: Ie8ff20402a1c6083246d25dea391140c75be40d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/618597 Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@golang.org>
2024-03-04cmd/internal/buildid: fix typo in commentguoguangwu
Change-Id: I271f25aefaace61935d55a1b6b7c026d022d92a7 GitHub-Last-Rev: 304e3ee979f4fde58184e7035cd5d0d6b50bca74 GitHub-Pull-Request: golang/go#66023 Reviewed-on: https://go-review.googlesource.com/c/go/+/567918 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-08-17cmd/internal/buildid: don't crash on 0 phdr.p_align fieldIan Lance Taylor
A 0 in phdr.p_align is the same as 1, meaning no alignment. Fixes #62097 Change-Id: I931bab443fd6a89b5b45c8f99ead217f02e9b453 Reviewed-on: https://go-review.googlesource.com/c/go/+/520597 Auto-Submit: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2022-09-27debug/elf: suport files with >= 65280 (0xff00) sectionsZeke Lu
The spec https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html states: 1. e_shnum: If the number of sections is greater than or equal to SHN_LORESERVE (0xff00), this member has the value zero and the actual number of section header table entries is contained in the sh_size field of the section header at index 0. 2. e_shstrndx: If the section name string table section index is greater than or equal to SHN_LORESERVE (0xff00), this member has the value SHN_XINDEX (0xffff) and the actual index of the section name string table section is contained in the sh_link field of the section header at index 0. This CL makes these changes to support files with >= 0xff00 sections: 1. if shoff > 0 && shnum == 0, read sh_size from the initial section header entry as shnum. 2. if shstrndx == SHN_XINDEX, read sh_link from the initial section header entry as shstrndx. It returns an error if the type of the initial section is not SHT_NULL. A file with >= 0xff00 sections is too big to include in the repository, so the test case constructs one on the fly, with some of the sections zeroed out. While here, remove the unnecessary use of reflect.DeepEqual in the test. Fixes #55294. Change-Id: I15ec43612c7cce6e8decfe4e81da3a5b16de47f7 GitHub-Last-Rev: 797c16480bc76524ff1a7c01ed09b759fcd7d45b GitHub-Pull-Request: golang/go#55295 Reviewed-on: https://go-review.googlesource.com/c/go/+/432255 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-09-20all: replace package ioutil with os and io in srcAndy Pan
For #45557 Change-Id: I56824135d86452603dd4ed4bab0e24c201bb0683 Reviewed-on: https://go-review.googlesource.com/c/go/+/426257 Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Andy Pan <panjf2000@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-08-20cmd/internal/buildid: reject empty idRuss Cox
The loop that makes progress assumes that after matching an id you should advance len(id) bytes in the file. If id is the empty string, then it will match and advance 0 bytes repeatedly. 0-byte ids are not really build IDs, so just reject it outright. Fixes #47852. Change-Id: Ie44a3a51dec22e2f68fb72d54ead91be98000cfe Reviewed-on: https://go-review.googlesource.com/c/go/+/344049 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-12-01cmd/internal/buildid: update Mach-O code signature when rewriting buildidCherry Zhang
As the code signature contains hashes of the entire file (except the signature itself), rewriting buildid will invalidate the signature. This CL makes it regenerate the signature when rewriting the buildid. It only does it when the file already has a code signature, with proper size (darwin/arm64 binaries generated by the Go linker should have). Updates #38485, #42684. Change-Id: I082d9e5808b0ee6a35f9c362d7262aadd9113c81 Reviewed-on: https://go-review.googlesource.com/c/go/+/272257 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2020-12-01cmd/internal/buildid: exclude Mach-O code signature in hash calculationCherry Zhang
The code signature contains hashes of the entire file (except the signature itself), including the buildid. Therefore, the buildid cannot depend on the signature. Otherwise updating buildid will invalidate the signature, and vice versa. As we cannot change the code-signing algorithm, we can only change buildid calculation. This CL changes the buildid calculation to exclude the Mach-O code signature. So updating code signature after stamping the buildid will not invalidate the buildid. Updates #38485, #42684. Change-Id: I8a9e2e25ca9dc00d9556d13b81652f43bbf6a084 Reviewed-on: https://go-review.googlesource.com/c/go/+/272255 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2020-10-28cmd/buildid: move and reuse duplicated HashToString code to ↵Mikhail Fesenko
cmd/internal/buildid/buildid Change-Id: I1e1ac770d4aac12d7d7ec57ef95f77a3e14a678c GitHub-Last-Rev: c01db4346eb08ffe0c1953892fb4222764048e30 GitHub-Pull-Request: golang/go#42052 Reviewed-on: https://go-review.googlesource.com/c/go/+/263418 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Trust: Jay Conrod <jayconrod@google.com> Trust: Michael Matloob <matloob@golang.org>
2020-10-20all: update references to symbols moved from os to io/fsRuss Cox
The old os references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. For #41190. Change-Id: I8f9526977867c10a221e2f392f78d7dec073f1bd Reviewed-on: https://go-review.googlesource.com/c/go/+/243907 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2019-11-21all: base64-encode binaries that will cause Apple notarization to failAndrew
Starting with macOS 10.15 (Catalina), Apple now requires all software distributed outside of the App Store to be notarized. Any binaries we distribute must abide by a strict set of requirements like code-signing and having a minimum target SDK of 10.9 (amongst others). Apple’s notarization service will recursively inspect archives looking to find notarization candidate binaries. If it finds a binary that does not meet the requirements or is unable to decompress an archive, it will reject the entire distribution. From cursory testing, it seems that the service uses content sniffing to determine file types, so changing the file extension will not work. There are some binaries and archives included in our distribution that are being detected by Apple’s service as potential candidates for notarization or decompression. As these are files used by tests and some are intentionally invalid, we don’t intend to ever make them compliant. As a workaround for this, we base64-encode any binaries or archives that Apple’s notarization service issues a warning for, as these warnings will become errors in January 2020. Updates #34986 Change-Id: I106fbb6227b61eb221755568f047ee11103c1680 Reviewed-on: https://go-review.googlesource.com/c/go/+/208118 Run-TryBot: Andrew Bonventre <andybons@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-12-10all: move cmd/internal/xcoff to internal/xcoffClément Chigot
This commit moves cmd/internal/xcoff package to internal/xcoff because it will be needed to add XCOFF support in go/internal/gccgoimporter. Change-Id: Id12df0c438fb7db4a6a458fc1478480851bf7771 Reviewed-on: https://go-review.googlesource.com/c/152719 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-31cmd: allow build with gccgo on AIXClément Chigot
This commit adapts cmd/internal/buildid and cmd/go to allow the use of gccgo on AIX. Buildid is supported only for AIX archives. Change-Id: I14c790a8994ae8d2ee629d8751e04189c30ffd94 Reviewed-on: https://go-review.googlesource.com/c/145417 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-07-16cmd/internal/buildid: close ELF file after reading noteIan Lance Taylor
Updates #26400 Change-Id: I1747d1f1018521cdfa4b3ed13412a944829967cf Reviewed-on: https://go-review.googlesource.com/124235 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-02-26cmd: avoid unnecessary type conversionsKunpei Sakai
CL generated mechanically with github.com/mdempsky/unconvert. Also updated cmd/compile/internal/ssa/gen/*.rules manually. Change-Id: If721ef73cf0771ae83ce7e2d11623fc8d9155768 Reviewed-on: https://go-review.googlesource.com/97075 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-01-05cmd/go: add support for build IDs with gccgoIan Lance Taylor
This just adds support on ELF systems, which is OK for now since that is all that gccgo works on. For the archive file generated by the compiler we add a new file _buildid.o that has a section .go.buildid containing the build ID. Using a new file lets us set the SHF_EXCLUDE bit in the section header, so the linker will discard the section. It would be nicer to use `objcopy --add-section`, but objcopy doesn't support setting the SHF_EXCLUDE bit. For an executable we just use an ordinary GNU build ID. Doing this required modifying cmd/internal/buildid to look for a GNU build ID, and use it if there is no other Go-specific note. This CL fixes a minor bug in gccgoTOolchain.link: it was using .Target instead of .built, so it failed for a cached file. This CL fixes a bug reading note segments: the notes are aligned as reported by the PT_NOTE's alignment field. Updates #22472 Change-Id: I4d9e9978ef060bafc5b9574d9af16d97c13f3102 Reviewed-on: https://go-review.googlesource.com/85555 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2017-10-11cmd/internal/buildid: add missing f.Close in ReadFileRuss Cox
On Windows, not closing f keeps us from being able to remove it. Change-Id: Id4cb709b6ce0b30485b87364a9f0e6e71d2782bd Reviewed-on: https://go-review.googlesource.com/70070 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: David Crawshaw <crawshaw@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-10-11cmd/buildid: add new tool factoring out code needed by go commandRuss Cox
This CL does a few things. 1. It moves the existing "read a build ID" code out of the go command and into cmd/internal/buildid. 2. It adds new code there to "write a build ID". 3. It adds better tests. 4. It encapsulates cmd/internal/buildid into a new standalone program "go tool buildid". The go command is going to use the new "write a build ID" functionality in a future CL. Adding the separate "go tool buildid" gives "go build -x" a printable command to explain what it is doing in that new step. (This is similar to the go command printing "go tool pack" commands equivalent to the actions it is taking, even though it's not invoking pack directly.) Keeping go build -x honest means that other build systems can potentially keep up with the go command. Change-Id: I01c0a66e30a80fa7254e3f2879283d3cd7aa03b4 Reviewed-on: https://go-review.googlesource.com/69053 Reviewed-by: David Crawshaw <crawshaw@golang.org>