mirror of
https://github.com/burrowers/garble.git
synced 2025-09-27 04:05:52 +08:00
use the correct toolchain "go" tool under GOTOOLCHAIN=auto
We call `go list` to collect information about all the packages to obfuscate and build, which is crucial to be able to perform obfuscation of names used across packages. However, when GOTOOLCHAIN causes a toolchain upgrade, we must ensure that we use the upgraded Go tool; otherwise we are mixing information from different toolchain versions. Fixes #934.
This commit is contained in:

committed by
Paul Scheduikat

parent
7f80dfb59d
commit
db3003b9fa
1
main.go
1
main.go
@@ -2326,6 +2326,7 @@ To install Go, see: https://go.dev/doc/install
|
|||||||
if err := json.Unmarshal(out, &sharedCache.GoEnv); err != nil {
|
if err := json.Unmarshal(out, &sharedCache.GoEnv); err != nil {
|
||||||
return fmt.Errorf(`cannot unmarshal from "go env -json": %w`, err)
|
return fmt.Errorf(`cannot unmarshal from "go env -json": %w`, err)
|
||||||
}
|
}
|
||||||
|
sharedCache.GoCmd = filepath.Join(sharedCache.GoEnv.GOROOT, "bin", "go")
|
||||||
sharedCache.GOGARBLE = cmp.Or(os.Getenv("GOGARBLE"), "*") // we default to obfuscating everything
|
sharedCache.GOGARBLE = cmp.Or(os.Getenv("GOGARBLE"), "*") // we default to obfuscating everything
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -49,6 +49,10 @@ type sharedCacheType struct {
|
|||||||
|
|
||||||
GOGARBLE string
|
GOGARBLE string
|
||||||
|
|
||||||
|
// GoCmd is [GoEnv.GOROOT]/bin/go, so that we run exactly the same version
|
||||||
|
// of the Go tool that the original "go build" invocation did.
|
||||||
|
GoCmd string
|
||||||
|
|
||||||
// GoVersion is a version of the Go toolchain currently being used,
|
// GoVersion is a version of the Go toolchain currently being used,
|
||||||
// as reported by "go env GOVERSION" and compatible with go/version.
|
// as reported by "go env GOVERSION" and compatible with go/version.
|
||||||
// Note that the version of Go that built the garble binary might be newer.
|
// Note that the version of Go that built the garble binary might be newer.
|
||||||
@@ -292,7 +296,7 @@ func appendListedPackages(packages []string, mainBuild bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
args = append(args, packages...)
|
args = append(args, packages...)
|
||||||
cmd := exec.Command("go", args...)
|
cmd := exec.Command(sharedCache.GoCmd, args...)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
log.Printf("original build info obtained in %s via: go %s", debugSince(startTime), strings.Join(args, " "))
|
log.Printf("original build info obtained in %s via: go %s", debugSince(startTime), strings.Join(args, " "))
|
||||||
|
11
testdata/script/gotoolchain.txtar
vendored
11
testdata/script/gotoolchain.txtar
vendored
@@ -4,9 +4,6 @@
|
|||||||
setup-go go1.23.7
|
setup-go go1.23.7
|
||||||
env GOPROXY=proxy.golang.org
|
env GOPROXY=proxy.golang.org
|
||||||
env GOMODCACHE=${HOST_GOMODCACHE}
|
env GOMODCACHE=${HOST_GOMODCACHE}
|
||||||
# The bug below is about a badly patched cmd/link, so we need a separate
|
|
||||||
# GARBLE_CACHE to not allow reusing the host's working patched linker.
|
|
||||||
env GARBLE_CACHE=${WORK}/.garble-cache
|
|
||||||
|
|
||||||
# Verify that we are using an older version of Go.
|
# Verify that we are using an older version of Go.
|
||||||
exec go version
|
exec go version
|
||||||
@@ -19,9 +16,11 @@ cd mod
|
|||||||
exec go run .
|
exec go run .
|
||||||
stderr 'hello from go1\.24\.1'
|
stderr 'hello from go1\.24\.1'
|
||||||
|
|
||||||
# TODO: fix this.
|
# Note that garble hides runtime.Version by design, but we know that it requires
|
||||||
! exec garble run .
|
# the Go toolchain version to match the exact same version that built garble,
|
||||||
stderr 'gcMarkTermination: relocation target .* not defined'
|
# and that version is most likely newer than GOVERSION_BASE.
|
||||||
|
exec garble run .
|
||||||
|
stderr 'hello from unknown'
|
||||||
|
|
||||||
-- mod/go.mod --
|
-- mod/go.mod --
|
||||||
module test
|
module test
|
||||||
|
Reference in New Issue
Block a user