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.
72 lines
1.3 KiB
Plaintext
72 lines
1.3 KiB
Plaintext
env GOPRIVATE=test/main
|
|
|
|
garble build
|
|
exec ./main
|
|
cmp stderr main.stderr
|
|
|
|
! binsubstr main$exe 'garbledFunc' 'GarbledFunc'
|
|
|
|
[short] stop # no need to verify this with -short
|
|
|
|
go build
|
|
exec ./main
|
|
cmp stderr main.stderr
|
|
|
|
-- go.mod --
|
|
module test/main
|
|
|
|
go 1.16
|
|
-- main.go --
|
|
package main
|
|
|
|
import (
|
|
_ "os/exec"
|
|
_ "strings"
|
|
_ "unsafe"
|
|
|
|
_ "test/main/imported"
|
|
)
|
|
|
|
// A linkname to an external non-garbled func.
|
|
//go:linkname byteIndex strings.IndexByte
|
|
func byteIndex(s string, c byte) int
|
|
|
|
// A linkname to an external non-garbled non-exported func.
|
|
//go:linkname interfaceEqual os/exec.interfaceEqual
|
|
func interfaceEqual(a, b interface{}) bool
|
|
|
|
// A linkname to an external garbled func.
|
|
//go:linkname garbledFunc test/main/imported.GarbledFuncImpl
|
|
func garbledFunc() string
|
|
|
|
// A linkname to an entirely made up name, implemented elsewhere.
|
|
//go:linkname renamedFunc madeup.newName
|
|
func renamedFunc() string
|
|
|
|
func main() {
|
|
println(byteIndex("01234", '3'))
|
|
println(interfaceEqual("Sephiroth", 7))
|
|
println(garbledFunc())
|
|
println(renamedFunc())
|
|
}
|
|
-- imported/imported.go --
|
|
package imported
|
|
|
|
import (
|
|
_ "unsafe"
|
|
)
|
|
|
|
func GarbledFuncImpl() string {
|
|
return "garbled func"
|
|
}
|
|
|
|
//go:linkname renamedFunc madeup.newName
|
|
func renamedFunc() string {
|
|
return "renamed func"
|
|
}
|
|
-- main.stderr --
|
|
3
|
|
false
|
|
garbled func
|
|
renamed func
|