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.
garble/testdata/script/asm.txtar

103 lines
2.1 KiB
Plaintext

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 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'
garble build
exec ./main
cmp stderr main.stderr
! binsubstr main$exe 'test/main' 'privateAdd' 'PublicAdd' 'garble_'
[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
! garble reverse .
! stderr .
garble -tiny build
exec ./main
cmp stderr main.stderr
! binsubstr main$exe 'privateAdd' 'PublicAdd'
go build
exec ./main
cmp stderr main.stderr
binsubstr main$exe 'privateAdd' 'PublicAdd'
-- go.mod --
module test/with.many.dots/main
go 1.19
-- main.go --
package main
import (
"test/with.many.dots/main/imported"
)
func privateAdd(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(privateAdd(1, 2))
println(goData[0], goData[1])
modifyGoData()
println(goData[0], goData[1])
modifyGoData2()
println(goData[0], goData[1])
println(imported.PublicAdd(3, 4))
}
-- garble_main_amd64.s --
#include "garble_define_amd64.h"
#include "extra/garble_define2_amd64.h"
TEXT ·privateAdd(SB),$0-16
JMP testwith·many·dotsmainimported·PublicAdd(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 PublicAdd(x, y int32) int32
-- imported/imported_amd64.s --
TEXT ·PublicAdd(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
1 2
13 36
25 70
7
-- empty-reverse.txt --