You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to create a tool to do build-time instrumentation of a Go program using the go build option -toolexec such as go build -toolexec my-tool .
It intercepts compiler calls and generates new Go files in the temporary build directory before replacing them in the compiler call.
It was working fine until I added an import to a new package.
What did you expect to see?
Being able to do add new imports that would be resolved at link-time.
What did you see instead?
But since this is happening after go build has done his dependency listing, the new import is not taken into account and the compilation fails because the new import is not in the importcfg file nor even compiled actually.
I tried to add it myself with a pre-compiled package but it is still detected by a compiler internal check:
/tmp/go-build445887355/b040/binary.go:29:2: internal compiler error: conflicting package heights 20 and 6 for path "reflect"
Note that since I want to instrument everything, I use the -a option to also instrument the standard library.
The text was updated successfully, but these errors were encountered:
As you've discovered, the -toolexec option is not powerful enough to support arbitrary source code rewriting. This is not a bug, it's just the way the option works. We are not going to add this capability, which would be difficult to implement safely. Sorry.
For the record, I did use the option -toolexec in the end in order to perform compile-time instrumentation. The limitations were avoided using the Go directive linkname to "export" or "import" function definitions from one package to another.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I am trying to create a tool to do build-time instrumentation of a Go program using the
go build
option-toolexec
such asgo build -toolexec my-tool .
It intercepts compiler calls and generates new Go files in the temporary build directory before replacing them in the compiler call.
It was working fine until I added an import to a new package.
What did you expect to see?
Being able to do add new imports that would be resolved at link-time.
What did you see instead?
But since this is happening after
go build
has done his dependency listing, the new import is not taken into account and the compilation fails because the new import is not in theimportcfg
file nor even compiled actually.I tried to add it myself with a pre-compiled package but it is still detected by a compiler internal check:
Note that since I want to instrument everything, I use the
-a
option to also instrument the standard library.The text was updated successfully, but these errors were encountered: