More correct comments transformation (#152)

More correct comments transformation was implemented.

Added processing of //go:linkname localname [importpath.name] directive, now localname is not renamed. This is safe and does not cause a name disclosure because the functions marked //linkname do not have a name in the resulting binary.

Added cgo directives support

Fixed filename leak protection for cgo

Part of #149
This commit is contained in:
pagran
2020-10-05 16:12:25 +03:00
committed by GitHub
parent 991fbb042b
commit ea4a01df87
3 changed files with 140 additions and 22 deletions

View File

@@ -1,19 +1,20 @@
env GOPRIVATE='test/main,rsc.io/*'
garble build
garble build -tags directives
exec ./main$exe
cmp stderr main.stderr
! binsubstr main$exe 'localName' 'globalConst' 'globalVar' 'globalType' 'valuable information' 'rsc.io'
! binsubstr main$exe 'localName' 'globalConst' 'globalVar' 'globalType' 'valuable information' 'rsc.io' 'remoteIntReturn' 'intReturn'
binsubstr main$exe 'magicFunc'
[short] stop # no need to verify this with -short
go build
go build -tags directives
exec ./main$exe
cmp stderr main.stderr
binsubstr main$exe 'globalVar' # 'globalType' only matches on go < 1.15
! binsubstr main$exe 'localName' 'globalConst'
! binsubstr main$exe 'localName' 'globalConst' 'remoteIntReturn' 'intReturn'
-- go.mod --
@@ -73,6 +74,7 @@ func main() {
scopesTest()
println(quote.Go())
sub.Test()
sub.TestDirectives()
}
-- scopes.go --
@@ -122,6 +124,39 @@ func Test() {
func noop(...interface{}) {}
-- sub/directives.go --
// +build directives
package sub
import (
_ "unsafe"
_ "test/main/sub/a"
)
//go:linkname remoteIntReturn a.magicFunc
func remoteIntReturn() int
//go:noinline
func TestDirectives() {
if remoteIntReturn() != 42 {
panic("invalid result")
}
}
-- sub/a/directives.go --
// +build directives
package a
import _ "unsafe"
//go:linkname intReturn a.magicFunc
//go:noinline
func intReturn() int {
return 42
}
-- main.stderr --
nil case
{"Foo":3}