Skip to content
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

x/tools/go/ssa/interp: panic: no code for function: time.runtimeNano on darwin #30881

Open
ajalab opened this issue Mar 16, 2019 · 3 comments
Open
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@ajalab
Copy link

ajalab commented Mar 16, 2019

What did you do?

main.go

package main

import (
	"go/types"
	"log"

	"golang.org/x/tools/go/packages"
	"golang.org/x/tools/go/ssa"
	"golang.org/x/tools/go/ssa/interp"
	"golang.org/x/tools/go/ssa/ssautil"
)

func main() {
	target := "./testdata"

	cfg := &packages.Config{
		Mode:  packages.LoadAllSyntax,
		Tests: false,
	}

	pkgs, err := packages.Load(cfg, target)
	if err != nil {
		log.Fatalf("failed to load package: %v", err)
		return
	}

	ssaProg, ssaPkgs := ssautil.AllPackages(pkgs, 0)
	ssaProg.Build()

	var mainPkg *ssa.Package
	for _, ssaPkg := range ssaPkgs {
		if ssaPkg.Pkg.Name() == "main" {
			mainPkg = ssaPkg
		}
	}

	mode := interp.EnableTracing
	interp.Interpret(mainPkg, mode, &types.StdSizes{WordSize: 8, MaxAlign: 8}, "main", []string{})
}

testdata/t.go

package main

import "fmt"

func main() {
	fmt.Println("hello")
}

go.mod

module github.com/ajalab/ssainterp

go 1.12

require golang.org/x/tools v0.0.0-20190315214010-f0bfdbff1f9c

What did you expect to see?

The program prints "hello" to stdout.

What did you see instead?

The program panics.

Entering time.runtimeNano at /usr/local/go/src/time/time.go:1076:6.
Leaving time.runtimeNano, resuming time.init at /usr/local/go/src/time/time.go:1084:34.
Panicking: string no code for function: time.runtimeNano.
Leaving time.init, resuming internal/poll.init.
Panicking: string no code for function: time.runtimeNano.
Leaving internal/poll.init, resuming os.init.
Panicking: string no code for function: time.runtimeNano.
Leaving os.init, resuming fmt.init.
Panicking: string no code for function: time.runtimeNano.
Leaving fmt.init, resuming github.com/ajalab/ssainterp/testdata.init.
Panicking: string no code for function: time.runtimeNano.
Leaving github.com/ajalab/ssainterp/testdata.init.
panic: no code for function: time.runtimeNano

Does this issue reproduce with the latest release (go1.12.1)?

yes

System details

go version go1.12.1 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/koki/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/koki/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/koki/prj/ssainterp/go.mod"
GOROOT/bin/go version: go version go1.12.1 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.12.1
uname -v: Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST 2018; root:xnu-4903.241.1~1/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.14.3
BuildVersion:	18D42
lldb --version: lldb-1000.0.38.2
  Swift-4.2
@gopherbot gopherbot added this to the Unreleased milestone Mar 16, 2019
@ajalab
Copy link
Author

ajalab commented Mar 16, 2019

I didn't see the error in the previous Go version.

It seems that we have to add more external functions in externals in external/darwin.go.
I confirmed that adding emulated functions for time.runtimeNano, runtime.envKeyEqual and internal/syscall/unix.fcntl prevents the panic caused in the above code, but I am not sure that all the causes are these three functions or this situation will happen in other OSs.

@agnivade
Copy link
Contributor

@randall77 for darwin. @alandonovan for go/ssa

@agnivade agnivade added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 22, 2019
@alandonovan
Copy link
Contributor

I finally got around to doing what I've been putting off for years:
https://go-review.googlesource.com/c/tools/+/168898

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants