From b4fc735a1e0fbb0a8ef0ca6386b4682f7568941d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 19 Apr 2021 21:09:54 +0100 Subject: [PATCH] fix windows/arm cross-build linking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Obfuscating some std packages for windows/arm triggered a bug; when encountering a call to runtime·memmove, we'd hash "memmove" with the current package's action ID. This is wrong on two levels: First, we aren't obfuscating the runtime package yet. And second, if we did, we would have to hash the symbol appropriately, with that package's action ID. For now, only hashing the local names does the trick. That's all that the code currently supports, anyway. --- main.go | 23 ++++++++++++++++++++++- testdata/scripts/crossbuild.txt | 18 ++++++++++-------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 8f750b7..bd33664 100644 --- a/main.go +++ b/main.go @@ -479,8 +479,24 @@ func transformAsm(args []string) ([]string, error) { remaining = nil break } - i += middleDotLen + // We want to replace "OP ·foo" and "OP $·foo", + // but not "OP somepkg·foo" just yet. + // "somepkg" is often runtime, syscall, etc. + // We don't obfuscate any of those for now. + // + // TODO: we'll likely need to deal with this + // when we start obfuscating the runtime. + // When we do, note that we can't hash with curPkg. + localName := false + if i >= 0 { + switch remaining[i-1] { + case ' ', '\t', '$': + localName = true + } + } + + i += middleDotLen buf.Write(remaining[:i]) remaining = remaining[i:] @@ -497,6 +513,11 @@ func transformAsm(args []string) ([]string, error) { name := string(remaining[:nameEnd]) remaining = remaining[nameEnd:] + if !localName { + buf.WriteString(name) + continue + } + newName := hashWith(curPkg.GarbleActionID, name) // log.Printf("%q hashed with %x to %q", name, curPkg.GarbleActionID, newName) buf.WriteString(newName) diff --git a/testdata/scripts/crossbuild.txt b/testdata/scripts/crossbuild.txt index f2c722b..6a0c3b9 100644 --- a/testdata/scripts/crossbuild.txt +++ b/testdata/scripts/crossbuild.txt @@ -1,16 +1,18 @@ -# TODO: always cross-build, even on a windows/arm host -env GOOS=windows -env GOARCH=arm +# We always build for a foreign GOOS. +# GOOS=windows, unless the host is also windows; then linux. +# GOARCH=arm, unless the host is also arm; then amd64. +# Windows and ARM are both interesting, +# and it helps with coverage as we mainly test on linux/amd64. +[!windows] env GOOS=windows +[windows] env GOOS=linux +[!arm] env GOARCH=arm +[arm] env GOARCH=arm64 env GOPRIVATE='*' -# TODO: seems like the linker fails for some reason with the full binary build below. -# For now, just test that we can build the library. -garble build net/http - # Link a binary importing net/http, which will catch whether or not we # support ImportMap when linking. -# garble build +garble build -- go.mod -- module test/main