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

Implausible string size error when reading Mach-O files with symbolic debugging entry #12

Open
logan opened this issue May 28, 2020 · 0 comments · May be fixed by #17
Open

Implausible string size error when reading Mach-O files with symbolic debugging entry #12

logan opened this issue May 28, 2020 · 0 comments · May be fixed by #17

Comments

@logan
Copy link

logan commented May 28, 2020

Someone on my team uses the GoLand IDE on MacOS, which uses github.com/google/gops to list processes to attach a debugger to, which in turn uses goversion to identify which processes are go programs. They recently ran into an issue where GoLand no longer shows our own builds as a process to attach to, and determined that it was due to an incompatibility with goversion.

The incompatibility only exists with some of our builds. On these files we get errors like this:

implausible string size 13669722811215734528 for runtime.buildVersion

I stepped through this issue with a debugger, and it turns out some (but not all) of our builds include a "symbolic debugging entry" for _runtime.buildVersion, which happens to be found earlier in the file than the symbol entry which actually points to its value.

I don't know much about Mach-O, but I was looking at this include file:

https://opensource.apple.com/source/xnu/xnu-201/EXTERNAL_HEADERS/mach-o/nlist.h

The entry that confuses goversion has a type of 0x20 and a value of 0. According to nlist.h:

/*
 * The n_type field really contains three fields:
 *	unsigned char N_STAB:3,
 *		      N_PEXT:1,
 *		      N_TYPE:3,
 *		      N_EXT:1;
 * which are used via the following masks.
 */
#define	N_STAB	0xe0  /* if any of these bits set, a symbolic debugging entry */
#define	N_PEXT	0x10  /* private external symbol bit */
#define	N_TYPE	0x0e  /* mask for the type bits */
#define	N_EXT	0x01  /* external symbol bit, set for external symbols */

/*
 * Only symbolic debugging entries have some of the N_STAB bits set and if any
 * of these bits are set then it is a symbolic debugging entry (a stab).  In
 * which case then the values of the n_type field (the entire field) are given
 * in <mach-o/stab.h>
 */

Note that the value of 32 is one of those N_STAB bits.

If I modify goversion to ignore symbols where (type & 0xe0) != 0, then goversion can read the version of our builds again (I will follow up with a PR for this shortly).

Unfortunately I have not been able to come up with a way to reproduce these builds (without sharing code that I do not have permission to share). The only hints I have are that it only started happening after we migrated our code to a go module and/or after we upgraded from go 1.13 to 1.14 (1.14.1, to be precise). I've built a few targets from our repo, and it seems like only the relatively larger builds have these symbols, but I have too few data points so far to conclude that it has anything to do with size or complexity.

logan pushed a commit to logan/goversion that referenced this issue May 28, 2020
My team has encountered an issue where `goversion` can no longer
recognize our builds (see issue rsc#12) due to a symbolic debugging entry
for `_runtime.buildVersion`.

If we omit such entries from the symbol list before looking for
`_runtime.BuildVersion`, then `goversion` works for our builds once
again.
FiloSottile added a commit to FiloSottile/goversion that referenced this issue Dec 15, 2020
Imported the cmd/go/internal/version implementation at
c32140fa94cfc51a2152855825f57e27ae3ba133, and restored Symbols and
TextRange to implement the gccgo and crypto checks.

It looks like the amd64 matching had broken, but it should be more
stable to just track what we do upstream with minimal modifications, so
I replaced the core mechanism rather than fixing the matcher.

Fixes rsc#14
Fixes rsc#12
Fixes rsc#11
Fixes rsc#7
Closes rsc#13
Closes rsc#9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant