rewrite go:linkname directives with garbled names (#200)
If code includes a linkname directive pointing at a name in an imported package, like: //go:linkname localName importedpackage.RemoteName func localName() We should rewrite the comment to replace "RemoteName" with its obfuscated counterpart, if the package in question was obfuscated and that name was as well. We already had some code to handle linkname directives, but only to ensure that "localName" was never obfuscated. This behavior is kept, to ensure that the directive applies to the right name. In the future, we could instead rewrite "localName" in the directive, like we do with "RemoteName". Add plenty of tests, too. The linkname directive used to be tested in imports.txt and syntax.txt, but that was hard to maintain as each file tested different edge cases. Now that we have build caching, adding one extra testscript file isn't a big problem anymoree. Add linkname.txt, which is self-explanatory. The other two scripts also get a bit less complex. Fixes #197.pull/201/head
parent
2b26183253
commit
c0731921c2
@ -0,0 +1,64 @@
|
||||
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.15
|
||||
-- main.go --
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "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 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(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
|
||||
garbled func
|
||||
renamed func
|
Loading…
Reference in New Issue