Open ianlancetaylor opened 1 month ago
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Yeah, we should update the magic number. And it is a good idea to have mkbuiltin.go automatically updates it.
Change https://go.dev/cl/627417 mentions this issue: cmd/internal/goobj: make mkbuiltin.go automatically update Magic const
Go version
tip
Output of
go env
in your module/workspace:What did you do?
Where go is current go tip (version go1.24-bae2e968e2) and ~/go1.23/bin/go is go 1.23 (version 1.23.2):
What did you see happen?
Running go1.23 tool nm on an object created by go tip crashed.
What did you expect to see?
I expected to see an error, or ordinary nm output. I did not expect to see a crash.
Since making nm forward compatible seems infeasible, we should change it so that if run on a newer object version it reports an error and exits, rather than crashing.
The object file format already has a magic number that supports this (cmd/internal/goobj.Magic). That magic number is normally changed when the object file format changes. In this case what happened is that the list of builtin names changed. That is part of the object file format, because the index into the builtin name slice is stored in the file format (when the symbol
PkgIdx
isgoobj.PkgIdxBuiltin
, the symbolSymIdx
is an index intogoobj.builtins
).Perhaps we should make cmd/internal/goobj/mkbuiltin.go automatically update the magic number. Or at least print a message saying that the magic number should be updated. Or perhaps we need some different mechanism, like a hash of the builtin names.
CC @golang/compiler