You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
garble/testdata/script/linker.txtar

69 lines
1.8 KiB
Plaintext

# Past garble versions might not properly patch cmd/link with "git apply"
# when running inside a git repository. Skip the extra check with -short.
[!short] [exec:git] exec git init -q
[!short] [exec:git] env GARBLE_CACHE=${WORK}/garble-cache
use fewer build flags when building std or cmd When we use `go list` on the standard library, we need to be careful about what flags are passed from the top-level build command, because some flags are not going to be appropriate. In particular, GOFLAGS=-modfile=... resulted in a failure, reproduced via the GOFLAGS variable added to linker.txtar: go: inconsistent vendoring in /home/mvdan/tip/src: golang.org/x/crypto@v0.5.1-0.20230203195927-310bfa40f1e4: is marked as explicit in vendor/modules.txt, but not explicitly required in go.mod golang.org/x/net@v0.7.0: is marked as explicit in vendor/modules.txt, but not explicitly required in go.mod golang.org/x/sys@v0.5.1-0.20230208141308-4fee21c92339: is marked as explicit in vendor/modules.txt, but not explicitly required in go.mod golang.org/x/text@v0.7.1-0.20230207171107-30dadde3188b: is marked as explicit in vendor/modules.txt, but not explicitly required in go.mod To ignore the vendor directory, use -mod=readonly or -mod=mod. To sync the vendor directory, run: go mod vendor To work around this problem, reset the -mod and -modfile flags when calling "go list" on the standard library, as those are the only two flags which alter how we load the main module in a build. The code which builds a modified cmd/link has a similar problem; it already reset GOOS and GOARCH, but it could similarly run into problems if other env vars like GOFLAGS were set. To be on the safe side, we also disable GOENV and GOEXPERIMENT, which we borrow from Go's bootstrapping commands.
1 year ago
# Any build settings for the main build shouldn't affect building the linker.
# If this flag makes it through when using build commands on std or cmd,
# those commands are likely to fail as std and cmd are their own modules.
env GOFLAGS=-modfile=${WORK}/go.mod
exec garble build
exec ./main
! cmp stderr main.stderr
[short] stop # no need to verify this with -short
# The rebuilt linker should use the executable extension for the host GOOS,
# not the target one. Not doing so might be harmless, but can result in
# building the linker twice, wasting CPU and disk.
[!windows] env GOOS=windows
[windows] env GOOS=linux
exec garble build
[!windows] [exec:git] exists ${GARBLE_CACHE}/tool/link
[!windows] [exec:git] ! exists ${GARBLE_CACHE}/tool/link.exe
[windows] [exec:git] ! exists ${GARBLE_CACHE}/tool/link
[windows] [exec:git] exists ${GARBLE_CACHE}/tool/link.exe
env GOOS=
# Verify a build without garble.
go build
exec ./main
cmp stderr main.stderr
-- go.mod --
module test/main
go 1.22
-- main.go --
package main
import (
"strconv"
"strings"
_ "unsafe"
)
type fakeModuleData struct {
pcHeader *struct {
magic uint32
}
}
//go:linkname activeModules runtime.activeModules
func activeModules() []*fakeModuleData
// genericMagicValue returns magic value without last digit
func genericMagicValue() string {
mod := activeModules()[0]
magicValHex := strings.ToUpper(strconv.FormatUint(uint64(mod.pcHeader.magic), 16))
return "0x" + magicValHex[:len(magicValHex)-1] + "?"
}
func main() {
println(genericMagicValue())
}
-- main.stderr --
0xFFFFFFF?