/ go Public
cmd/go: list -compiled fails to populate CompiledGoFiles when the resulting package cannot be linked #34229
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
What version of Go are you using (
Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
What did you do?
Create a package with the following contents:
go list -json -x -compiledon the package
What did you expect to see?
No errors, no attempted linking of object files, complete JSON output (meaning CompiledGoFiles is populated).
What did you see instead?
That is, Go actually attempts to build the package and fails due to the missing library we're trying to link against. It also doesn't populate CompiledGoFiles, even though cgo preprocessing succeeded.
As I understand it, this is trying to do more work than is necessary. It also unnecessarily fails.
-compiledflag is documented as follows:
It does not imply actual compilation. Also note that we're not passing the
-exportedflag. Furthermore, in order to do cgo processing, we do not need the linker. For that, looking at headers suffices, and
go tool cgo foo.godoes succeed.
After a cursory look at cmd/go/internal/work/exec.go, (*Builder).build, it seems that if we require CompiledGoFiles, and they can't be found in the cache, we execute the full cgo pipeline used for building. In theory, it should be possible to optimize this.
The current behavior is problematic for two reasons, from the point of view of tools that analyze Go code:
/cc @matloob @ianthehat @bcmills
The text was updated successfully, but these errors were encountered: