From 229695a2833ead7bbee53071f52f34e2ce1c2802 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 28 Jan 2021 09:32:55 -0500 Subject: [PATCH] runtime: clean up funcID assignment Large enum sets should be sorted by name when the values don't matter, as they don't here. Do that. Also replace the large switch with a map lookup. This CL is part of a stack adding windows/arm64 support (#36439), intended to land in the Go 1.17 cycle. This CL is, however, not windows/arm64-specific. It is cleanup meant to make the port (and future ports) easier. Change-Id: Ibe727b5d8866bf4c40c96020e1f4632bde7efd59 Reviewed-on: https://go-review.googlesource.com/c/go/+/288798 Trust: Russ Cox Trust: Jason A. Donenfeld Reviewed-by: Cherry Zhang Reviewed-by: Jason A. Donenfeld Reviewed-by: Ian Lance Taylor --- src/cmd/internal/objabi/funcid.go | 117 +++++++++++++----------------- src/runtime/symtab.go | 30 ++++---- 2 files changed, 65 insertions(+), 82 deletions(-) diff --git a/src/cmd/internal/objabi/funcid.go b/src/cmd/internal/objabi/funcid.go index 1d098ee1725..e921a82c0c4 100644 --- a/src/cmd/internal/objabi/funcid.go +++ b/src/cmd/internal/objabi/funcid.go @@ -4,6 +4,8 @@ package objabi +import "strings" + // A FuncID identifies particular functions that need to be treated // specially by the runtime. // Note that in some situations involving plugins, there may be multiple @@ -13,88 +15,69 @@ type FuncID uint8 const ( FuncID_normal FuncID = iota // not a special function - FuncID_runtime_main + FuncID_asmcgocall + FuncID_asyncPreempt + FuncID_cgocallback + FuncID_debugCallV1 + FuncID_externalthreadhandler + FuncID_gcBgMarkWorker FuncID_goexit + FuncID_gogo + FuncID_gopanic + FuncID_handleAsyncEvent FuncID_jmpdefer FuncID_mcall FuncID_morestack FuncID_mstart - FuncID_rt0_go - FuncID_asmcgocall - FuncID_sigpanic - FuncID_runfinq - FuncID_gcBgMarkWorker - FuncID_systemstack_switch - FuncID_systemstack - FuncID_cgocallback - FuncID_gogo - FuncID_externalthreadhandler - FuncID_debugCallV1 - FuncID_gopanic FuncID_panicwrap - FuncID_handleAsyncEvent - FuncID_asyncPreempt + FuncID_rt0_go + FuncID_runfinq + FuncID_runtime_main + FuncID_sigpanic + FuncID_systemstack + FuncID_systemstack_switch FuncID_wrapper // any autogenerated code (hash/eq algorithms, method wrappers, etc.) ) +var funcIDs = map[string]FuncID{ + "asmcgocall": FuncID_asmcgocall, + "asyncPreempt": FuncID_asyncPreempt, + "cgocallback": FuncID_cgocallback, + "debugCallV1": FuncID_debugCallV1, + "externalthreadhandler": FuncID_externalthreadhandler, + "gcBgMarkWorker": FuncID_gcBgMarkWorker, + "go": FuncID_rt0_go, + "goexit": FuncID_goexit, + "gogo": FuncID_gogo, + "gopanic": FuncID_gopanic, + "handleAsyncEvent": FuncID_handleAsyncEvent, + "jmpdefer": FuncID_jmpdefer, + "main": FuncID_runtime_main, + "mcall": FuncID_mcall, + "morestack": FuncID_morestack, + "mstart": FuncID_mstart, + "panicwrap": FuncID_panicwrap, + "runfinq": FuncID_runfinq, + "sigpanic": FuncID_sigpanic, + "switch": FuncID_systemstack_switch, + "systemstack": FuncID_systemstack, + + // Don't show in call stack but otherwise not special. + "deferreturn": FuncID_wrapper, + "runOpenDeferFrame": FuncID_wrapper, + "reflectcallSave": FuncID_wrapper, +} + // Get the function ID for the named function in the named file. // The function should be package-qualified. func GetFuncID(name string, isWrapper bool) FuncID { if isWrapper { return FuncID_wrapper } - switch name { - case "runtime.main": - return FuncID_runtime_main - case "runtime.goexit": - return FuncID_goexit - case "runtime.jmpdefer": - return FuncID_jmpdefer - case "runtime.mcall": - return FuncID_mcall - case "runtime.morestack": - return FuncID_morestack - case "runtime.mstart": - return FuncID_mstart - case "runtime.rt0_go": - return FuncID_rt0_go - case "runtime.asmcgocall": - return FuncID_asmcgocall - case "runtime.sigpanic": - return FuncID_sigpanic - case "runtime.runfinq": - return FuncID_runfinq - case "runtime.gcBgMarkWorker": - return FuncID_gcBgMarkWorker - case "runtime.systemstack_switch": - return FuncID_systemstack_switch - case "runtime.systemstack": - return FuncID_systemstack - case "runtime.cgocallback": - return FuncID_cgocallback - case "runtime.gogo": - return FuncID_gogo - case "runtime.externalthreadhandler": - return FuncID_externalthreadhandler - case "runtime.debugCallV1": - return FuncID_debugCallV1 - case "runtime.gopanic": - return FuncID_gopanic - case "runtime.panicwrap": - return FuncID_panicwrap - case "runtime.handleAsyncEvent": - return FuncID_handleAsyncEvent - case "runtime.asyncPreempt": - return FuncID_asyncPreempt - case "runtime.deferreturn": - // Don't show in the call stack (used when invoking defer functions) - return FuncID_wrapper - case "runtime.runOpenDeferFrame": - // Don't show in the call stack (used when invoking defer functions) - return FuncID_wrapper - case "runtime.reflectcallSave": - // Don't show in the call stack (used when invoking defer functions) - return FuncID_wrapper + if strings.HasPrefix(name, "runtime.") { + if id, ok := funcIDs[name[len("runtime."):]]; ok { + return id + } } return FuncID_normal } diff --git a/src/runtime/symtab.go b/src/runtime/symtab.go index 7667f23f1db..fc93c00c2d7 100644 --- a/src/runtime/symtab.go +++ b/src/runtime/symtab.go @@ -308,27 +308,27 @@ type funcID uint8 const ( funcID_normal funcID = iota // not a special function - funcID_runtime_main + funcID_asmcgocall + funcID_asyncPreempt + funcID_cgocallback + funcID_debugCallV1 + funcID_externalthreadhandler + funcID_gcBgMarkWorker funcID_goexit + funcID_gogo + funcID_gopanic + funcID_handleAsyncEvent funcID_jmpdefer funcID_mcall funcID_morestack funcID_mstart - funcID_rt0_go - funcID_asmcgocall - funcID_sigpanic - funcID_runfinq - funcID_gcBgMarkWorker - funcID_systemstack_switch - funcID_systemstack - funcID_cgocallback - funcID_gogo - funcID_externalthreadhandler - funcID_debugCallV1 - funcID_gopanic funcID_panicwrap - funcID_handleAsyncEvent - funcID_asyncPreempt + funcID_rt0_go + funcID_runfinq + funcID_runtime_main + funcID_sigpanic + funcID_systemstack + funcID_systemstack_switch funcID_wrapper // any autogenerated code (hash/eq algorithms, method wrappers, etc.) )