Skip to content

runtime_link.go:8: could not import runtime (open : no such file or directory) #311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xhd2015 opened this issue Apr 12, 2025 · 13 comments
Closed
Labels
bug Something isn't working done potential_go_bug the issue contains a potential go bug that we may report to go team

Comments

@xhd2015
Copy link
Owner

xhd2015 commented Apr 12, 2025

This is an issue from github workflow:

Image

It can be replicated in local with: go run ./script/run-test --include go1.19.13 --with-setup-only --log-debug -v ./runtime/test/build/modules_with_trap_all/service

It seems caused by -overlay, after removing the overlay content, the build passes.

@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 12, 2025

After adding some debug, found that GOCACHE are different:

  • without --with-setup-only
    • GOCACHE=/tmp/xgo/go-instrument/go1.19.13_Us_xh_Pr_xh_xg_go_go_7ddb57fe/build-cache
  • with --with-setup-only
    • GOCACHE=/tmp/xgo/go-instrument/go1.19.13_Us_xh_.x_go_go_go_539cb0a6/build-cache

If force --with-setup-only to use the upper GOCACHE, the test passes.

@xhd2015 xhd2015 added the bug Something isn't working label Apr 12, 2025
@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 12, 2025

fixed in 2688f96

@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 12, 2025

The fix significantly reduces the --with-setup overhead with cache, because GOCACHE now becomes consistent, there is no useless extra tests running.

Image

@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 13, 2025

However, this seems likely not only related to inconsistent build cache, but a bug related cache+overlay combination:

The follow image shows:

  • first build, --reset-instrument without --trap-all, this clears the build cache
  • second build, --trap-all, the reuses the build cache with all files having overlay
    Image

@xhd2015 xhd2015 reopened this Apr 13, 2025
@xhd2015 xhd2015 added the potential_go_bug the issue contains a potential go bug that we may report to go team label Apr 13, 2025
@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 13, 2025

The bug could be go's mishandling of GOCACHE and -overlay.

Workaround could be making xgo's instrument to be idempotent:

  • same file set + flags -> same build cache

flags affecting build cache:

  • --trap pkg
  • --mock-rule
  • --trap-all
  • -cover
  • run or test
  • the main module
  • -tags

@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 13, 2025

The go's build action computes cache:

https://github.com/golang/go/blob/a9d9b5570964c2c2ef07992150174bd3d1b2d891/src/cmd/go/internal/work/exec.go#L385

	inputFiles := str.StringList(
		p.GoFiles,
		p.CgoFiles,
		p.CFiles,
		p.CXXFiles,
		p.FFiles,
		p.MFiles,
		p.HFiles,
		p.SFiles,
		p.SysoFiles,
		p.SwigFiles,
		p.SwigCXXFiles,
		p.EmbedFiles,
	)
	for _, file := range inputFiles {
		fmt.Fprintf(h, "file %s %s\n", file, b.fileHash(filepath.Join(p.Dir, file)))
	}

@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 13, 2025

After per-flag cache:

Image

@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 13, 2025

We can't fully suppress this failure. Currently if user encounter such error, add a --reset-instrument would solve it.

It already shows that in some cases with some specific building sequence, this bug can be replicated.

@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 13, 2025

It's probably due to go compile's missing Deps in import cfg.

A possible solution would be: always import runtime.

Image

@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 13, 2025

Always import runtime, this fixed everything:

Image

@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 14, 2025

fixed in
09acbf9#diff-1455ecf704192d385801798bf96fbe01b3efeca6aa92d6ff200cf78626c5e879

The issue occurs after go1.19, tests show go1.17 and go1.18 are ok:

minor, err := getGo1MinorVersion()
if err != nil {
t.Fatalf("failed to get go minor version: %v", err)
}
if minor >= 19 {
if afterErr == nil {
t.Errorf("expect cache+overlay combination error, actual nil")

@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 14, 2025

go:vet also fails:

Image

@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 17, 2025

fixed in #323 5e9b1fb

see golang/go#73368 (comment)

@xhd2015 xhd2015 closed this as completed Apr 17, 2025
@xhd2015 xhd2015 added the done label Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working done potential_go_bug the issue contains a potential go bug that we may report to go team
Projects
None yet
Development

No branches or pull requests

1 participant