Which part of go compiler set the symbol "runtime.text" in the final build?

106 views
Skip to first unread message

Zxilly Chou

unread,
Jan 24, 2024, 1:21:59 PM1/24/24
to golang-nuts
Yesterday, I reported an issue on debug/gosym at issues/65232 regarding the difference between the symbol table and gopclntab. A member of the Go team informed me that the start of the .text segment is not always kept the same as 'runtime.text' value.
I am curious about how the compiler sets this symbol and if there is a way to obtain this value without relying on the symbol table. Additionally, how does a compiled binary locate it even after being stripped?
Any suggestions would be appreciated.

Def Ceb

unread,
Jan 24, 2024, 2:09:44 PM1/24/24
to golan...@googlegroups.com
The binary stores a lot of ancillary data for runtime access. This
(mostly?) spans out from runtime.pclntab and runtime.firstmoduledata and
all the structures referenced by them. This is uniform across all
platforms too, with the runtime doing the same operations across
different OS-es and executable formats instead of using some
ELF/PE/Mach-O specific features.

Looking at a decompiled cgo binary where .text != runtime.text, some
values that reference runtime.text are:
runtime.pclntab.textStart
runtime.firstmoduledata.minpc
runtime.firstmoduledata.text

I think this should, at the very least, lead you in the right direction.

Zxilly Chou:
> --
> You received this message because you are subscribed to the Google
> Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to golang-nuts...@googlegroups.com
> <mailto:golang-nuts...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/cf32849d-64a0-4615-bfa1-8add7b1f2b62n%40googlegroups.com <https://groups.google.com/d/msgid/golang-nuts/cf32849d-64a0-4615-bfa1-8add7b1f2b62n%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages