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/scripts
Daniel Martí 68b39e8195 fix a link issue when obfuscating complex cgo packages
The added test case, which is obfuscating and linking os/user, would fail
before this fix:

	> garble build
	[stderr]
	# test/main
	/usr/lib/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
	/usr/bin/ld: $WORK/.tmp/go-link-073246656/go.o: in function `Chz0Yfs2._cgo_cmalloc':
	go.go:(.text+0x993cc): undefined reference to `Chz0Yfs2.runtime_throw'
	/usr/bin/ld: $WORK/.tmp/go-link-073246656/go.o: in function `Chz0Yfs2.tDfhQ8uK':
	go.go:(.text+0x99801): undefined reference to `Chz0Yfs2._cgo_runtime_gostring'
	/usr/bin/ld: go.go:(.text+0x9982a): undefined reference to `Chz0Yfs2._cgo_runtime_gostring'
	/usr/bin/ld: go.go:(.text+0x99853): undefined reference to `Chz0Yfs2._cgo_runtime_gostring'
	collect2: error: ld returned 1 exit status

The reason is that we would alter the linkname directives of cgo-generated
code, but we would not obfuscate the code itself at all.

The generated code would end up being transformed into:

	//go:linkname zh_oKZIy runtime.throw
	func runtime_throw(string)

One can clearly see the error there; handleDirectives obfuscated the
local linkname name, but since transformGo didn't run, the actual Go
declaration was not obfuscated in the same way. Thus, the linker fails
to find a function body for runtime_throw, and fails.

The solution is simple: handleDirectives assumes that it's running on
code being obfuscated, so only run it when transformGo is running.

We can also remove the cgo skip check in handleDirectives, as it never
runs on cgo-generated code now.

Fixes a number of build errors that have been noticed since
907aebd770.
4 years ago
..
asm.txt obfuscate asm function names as well (#273) 4 years ago
basic.txt testdata: use longer Go filenames for binsubstr 4 years ago
cgo.txt fix a link issue when obfuscating complex cgo packages 4 years ago
crossbuild.txt fix windows/arm cross-build linking 4 years ago
debugdir.txt refactor "current package" with TOOLEXEC_IMPORTPATH (#266) 4 years ago
embed.txt support embedding via embed.FS 4 years ago
goprivate.txt avoid reproducibility issues with full rebuilds 4 years ago
goversion.txt use "go env -json" to collect env info all at once 4 years ago
help.txt make "garble command -h" give command-specific help 4 years ago
implement.txt remove tinyfmt implementation from a test script 4 years ago
imports.txt testdata: use longer Go filenames for binsubstr 4 years ago
init.txt all: drop support for Go 1.15.x (#265) 4 years ago
ldflags.txt testdata: remove some unnecessary execs (#267) 4 years ago
linkname.txt fix obfuscating linkname directives that where the package name contained a dot 4 years ago
literals.txt make -literals succeed on all of std 4 years ago
modinfo.txt testdata: remove some unnecessary execs (#267) 4 years ago
plugin.txt all: drop support for Go 1.15.x (#265) 4 years ago
position.txt testdata: use longer Go filenames for binsubstr 4 years ago
reflect.txt testdata: use longer Go filenames for binsubstr 4 years ago
reverse.txt reverse lone filenames as well 4 years ago
seed.txt make flags like -literals and GOPRIVATE affect hashing (#288) 4 years ago
syntax.txt handle aliases to foreign named types properly 4 years ago
test.txt testdata: reduce the cost of short tests 4 years ago
tiny.txt testdata: deduplicate GODEBUG cleanup line 4 years ago