mirror of
https://github.com/burrowers/garble.git
synced 2026-04-22 23:57:14 +08:00
30357af923
This lets us start taking advantage of featurs from Go 1.23, particularly tracking aliases in go/types and iterators. Note that we need to add code to properly handle or skip over the new *types.Alias type which go/types produces for Go type aliases. Also note that we actually turn this mode off entirely for now, due to the bug reported at https://go.dev/issue/70394. We don't yet remove our own alias tracking code yet due to the above. We hope to be able to remove it very soon.
157 lines
3.5 KiB
Plaintext
157 lines
3.5 KiB
Plaintext
# Note that it doesn't really matter if the assembly below is badly written.
|
||
# We just care enough to see that it obfuscates and keeps the same behavior.
|
||
# TODO: support arm64, at least
|
||
[!amd64] skip 'the assembly is only written for amd64'
|
||
|
||
exec garble build
|
||
exec ./main
|
||
cmp stderr main.stderr
|
||
! binsubstr main$exe 'test/main' 'addJmp' 'AddImpl' 'garble_'
|
||
|
||
# We used to panic on broken packages with assembly.
|
||
! exec garble build ./broken/...
|
||
stderr -count=1 'broken[/\\]asm[/\\].*MissingType'
|
||
stderr -count=1 'broken[/\\]syntax[/\\].*unexpected newline'
|
||
|
||
[short] stop # no need to verify this with -short
|
||
|
||
# Ensure that reversing doesn't error with assembly files.
|
||
# It should fail, as there is nothing to reverse, but without any parse error.
|
||
stdin empty-reverse.txt
|
||
! exec garble reverse .
|
||
! stderr .
|
||
|
||
exec garble -tiny build
|
||
exec ./main
|
||
cmp stderr main.stderr
|
||
! binsubstr main$exe 'addJmp' 'AddImpl'
|
||
|
||
go build
|
||
exec ./main
|
||
cmp stderr main.stderr
|
||
binsubstr main$exe 'addJmp' 'AddImpl'
|
||
-- go.mod --
|
||
module test/with.many.dots/main
|
||
|
||
go 1.23
|
||
-- main.go --
|
||
package main
|
||
|
||
import (
|
||
"test/with.many.dots/main/imported"
|
||
)
|
||
|
||
func addJmpPkgPath(x, y int32) int32
|
||
func addJmpPkgName(x, y int32) int32
|
||
|
||
// goData is used from both assembly and header files.
|
||
var goData = [4]uint64{1, 2, 3, 4}
|
||
|
||
func modifyGoData()
|
||
func modifyGoData2()
|
||
|
||
func main() {
|
||
println(addJmpPkgPath(1, 2))
|
||
println(addJmpPkgName(1, 2))
|
||
|
||
println(goData[0], goData[1])
|
||
modifyGoData()
|
||
println(goData[0], goData[1])
|
||
modifyGoData2()
|
||
println(goData[0], goData[1])
|
||
|
||
println(imported.AddImpl(3, 4))
|
||
}
|
||
-- garble_main_amd64.s --
|
||
#include "garble_define_amd64.h"
|
||
|
||
#include "extra/garble_define2_amd64.h" // Inline: many·special∕asm·runes.
|
||
|
||
// A comment may include many·special∕asm·runes and it's okay.
|
||
//No space: many·special∕asm·runes.
|
||
// Indented: many·special∕asm·runes.
|
||
DATA bar+0(SB)/8, $0 // Inline: many·special∕asm·runes.
|
||
|
||
// Reference an imported package by its package path.
|
||
TEXT ·addJmpPkgPath(SB),$0-16
|
||
JMP test∕with·many·dots∕main∕imported·AddImpl(SB)
|
||
|
||
// Reference the current package by its package name.
|
||
TEXT ·addJmpPkgName(SB),$0-16
|
||
JMP main·addJmpPkgPath(SB)
|
||
|
||
TEXT ·modifyGoData(SB),$0-16
|
||
addGoDataTo($12)
|
||
ADDL $34, ·goData+8(SB)
|
||
RET
|
||
|
||
TEXT ·modifyGoData2(SB),$0-16
|
||
addGoDataTo2($12)
|
||
ADDL $34,·goData+8(SB) // note the lack of a space
|
||
RET
|
||
|
||
-- garble_define_amd64.h --
|
||
#define addGoDataTo(arg) \
|
||
ADDL arg, ·goData+0(SB)
|
||
|
||
-- extra/garble_define2_amd64.h --
|
||
#define addGoDataTo2(arg) \
|
||
ADDL arg, ·goData+0(SB)
|
||
|
||
-- imported/imported.go --
|
||
package imported
|
||
|
||
func AddImpl(x, y int32) int32
|
||
|
||
// Reference the current package by its package path.
|
||
func addJmpPkgPath(x, y int32) int32
|
||
|
||
// Reference the current package by its package path.
|
||
func addJmpPkgName(x, y int32) int32
|
||
|
||
-- imported/imported_amd64.s --
|
||
TEXT ·AddImpl(SB),$0-16
|
||
MOVL x+0(FP), BX
|
||
MOVL y+4(FP), BP
|
||
ADDL BP, BX
|
||
MOVL BX, ret+8(FP)
|
||
RET
|
||
|
||
TEXT ·addJmpPkgPath(SB),$0-16
|
||
JMP test∕with·many·dots∕main∕imported·AddImpl(SB)
|
||
|
||
TEXT ·addJmpPkgName(SB),$0-16
|
||
JMP imported·AddImpl(SB)
|
||
-- broken/syntax/broken.go --
|
||
package broken
|
||
|
||
func AddImpl
|
||
|
||
-- broken/asm/imported_amd64.s --
|
||
TEXT ·AddImpl(SB),$0-16
|
||
MOVL x+0(FP), BX
|
||
MOVL y+4(FP), BP
|
||
ADDL BP, BX
|
||
MOVL BX, ret+8(FP)
|
||
RET
|
||
-- broken/asm/broken.go --
|
||
package broken
|
||
|
||
func AddImpl(x, y int32) MissingType
|
||
|
||
-- broken/imported_amd64.s --
|
||
TEXT ·AddImpl(SB),$0-16
|
||
MOVL x+0(FP), BX
|
||
MOVL y+4(FP), BP
|
||
ADDL BP, BX
|
||
MOVL BX, ret+8(FP)
|
||
RET
|
||
-- main.stderr --
|
||
3
|
||
3
|
||
1 2
|
||
13 36
|
||
25 70
|
||
7
|
||
-- empty-reverse.txt --
|