mirror of
https://github.com/burrowers/garble.git
synced 2025-12-24 12:58:05 +08:00
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:
43
testdata/scripts/syntax.txt
vendored
43
testdata/scripts/syntax.txt
vendored
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user