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

runtime,cmd/internal/objabi: incorrect funID of runtime.rt0_go and runtime.systemstack_switch #52092

Closed
zhouguangyuan0718 opened this issue Apr 1, 2022 · 1 comment
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@zhouguangyuan0718
Copy link
Contributor

zhouguangyuan0718 commented Apr 1, 2022

What version of Go are you using (go version)?

$ go version
go version go1.17.8 linux/amd64

Does this issue reproduce with the latest release?

Yes, it reproduce with the master branch.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
Unrelated.

What did you do?

I added some export function in runtime/export_test.go and a testcase to show this bug.

go/src/runtime/export_test.go

var specialFuncs = map[string]funcInfo{
	"runtime.rt0_go":             findfunc(abi.FuncPCABI0(rt0_go)),
	"runtime.systemstack_switch": findfunc(abi.FuncPCABI0(systemstack_switch)),
	"runtime.systemstack":        findfunc(abi.FuncPCABI0(systemstack)),
}

const (
	FuncID_rt0_go             = funcID_rt0_go
	FuncID_systemstack_switch = funcID_systemstack_switch
	FuncID_systemstack        = funcID_systemstack
)

func GetSpecialFuncInfo(name string) (funcInfo, bool) {
	f, ok := specialFuncs[name]
	return f, ok
}

func (f funcInfo) FuncID() funcID {
	return f.funcID
}

go/src/runtime/funcinfo_test.go(wherever)

func Test_FuncID(t *testing.T) {
	cases := []struct {
		give string
		want uint8
	}{
		{"runtime.rt0_go", uint8(runtime.FuncID_rt0_go)},
		{"runtime.systemstack_switch", uint8(runtime.FuncID_systemstack_switch)},
		{"runtime.systemstack", uint8(runtime.FuncID_systemstack)},
	}
	for _, cas := range cases {
		f, ok := runtime.GetSpecialFuncInfo(cas.give)
		if !ok {
			t.Fatal("can't get funcinfo of", cas.give)
		}
		got := f.FuncID()
		if uint8(got) != cas.want {
			t.Errorf("Check FuncInfo of %s failed, want %d, got %d", cas.give, cas.want, got)
		}
	}
}

Then I use go test to run this testcase.

What did you expect to see?

This testcase passed.

What did you see instead?

=== RUN   Test_FuncID
    funcinfo_test.go:20: Check FuncInfo of runtime.rt0_go failed, want 16, got 0
    funcinfo_test.go:20: Check FuncInfo of runtime.systemstack_switch failed, want 21, got 0
--- FAIL: Test_FuncID (0.00s)

The funcIDs of runtime.rt0_go and runtime.systemstack_switch are set incorrectly at

"go": FuncID_rt0_go,
and
"switch": FuncID_systemstack_switch,
.

It seems like a typo.

@gopherbot
Copy link

Change https://go.dev/cl/396797 mentions this issue: cmd/internal/objabi: fix FuncID of runtime.rt0_go and runtime.systemstack_switch

@cherrymui cherrymui added the NeedsFix The path to resolution is known, but the work has not been done. label Apr 5, 2022
@cherrymui cherrymui added this to the Backlog milestone Apr 5, 2022
@golang golang locked and limited conversation to collaborators Apr 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants