fix windows/arm cross-build linking

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.
pull/320/head
Daniel Martí 3 years ago committed by Andrew LeFevre
parent 6ac7dce4a0
commit b4fc735a1e

@ -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)

@ -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

Loading…
Cancel
Save