-
Notifications
You must be signed in to change notification settings - Fork 18k
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: mangled function names for method value wrapper #64985
Comments
Similar to #24488 |
what's |
I suppose that it is a question. A simple test demonstrating this effect can be found here: I had to add another stage of function name parsing into the tested function located here: If I do not split the name with a hyphen, I get a strange function name like |
I think this is expected. The compiler inserts the -fm suffix as the closure name (that is the way methods are implemented) and the suffix prevents collisions with existing function names. The function name has no real use outside of debuggers and maybe FuncForPC. |
@mauri870 , |
@vault-thirteen The way method sets are implemented, the |
@mauri870, |
Not to my knowledge. It seems a rather internal detail about the compiler implementation. For instance, gccgo outputs the following for the program I linked above:
Reading the spec it only mentions that method sets must be unique. Maybe the compiler folks can shine some line in here. /cc @golang/compiler |
@mauri870 , thank you for the information. For me it looks like Go language needs to introduce method overriding as in C++ and make a stable API and ABI, so that we do not see all these strange things any more. Who knows what will the postfix |
The -fm suffix indicates a method value wrapper. (The suffix predates my involvement in the Go compiler, so I'm not sure what significance the letters "fm" have.) I don't believe we currently guarantee what FuncForPC returns on method values. I'm open to defining it. (/cc @ianlancetaylor @alandonovan for gccgo and x/tools/go/ssa.)
While we reserve the right to change internal symbol mangling, it's not something we do casually. We know it risks churn for end users. (Eg, I believe gc has used the -fm suffix since method values were added in Go 1.1.) |
@mdempsky , thank you for the details. |
In my opinion this is an area where the compiler should retain flexibility. We shouldn't pin down precisely how So, closing. Please comment if you disagree. |
Go version
go version go1.20.12 windows/amd64
Output of
go env
in your module/workspace:What did you do?
I get a name of a function with the following code:
For the method
Ping
of aServer
class (type) it returns the following name:github.com/vault-thirteen/SimpleBB/pkg/ACM.(*Server).Ping-fm
For some reason a
-fm
postfix is added to the function's full name.When I tested the package which gets name of a function locally -- there was no
-fm
postfix and all the tests of this code pass normally.Why does a name contain the minus (hyphen) sign which can not be used for identifiers in Go language ?
What does the
fm
mean ?How do I get a normal function name without
-fm
postfix ?What did you see happen?
I saw
github.com/vault-thirteen/SimpleBB/pkg/ACM.(*Server).Ping-fm
.What did you expect to see?
I expected to see the same function name as in tests of the method, i.e. a normal name of a function without any postfixes.
The text was updated successfully, but these errors were encountered: