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

cmd/link: don't assume all sections but __PKGDEF are object files #28429

alandonovan opened this issue Oct 26, 2018 · 2 comments


None yet
4 participants
Copy link

commented Oct 26, 2018

I'm currently implementing support for modular static analysis in Google's build system. Unlike "go vet", which saves analysis facts in a .vetx file known to the build system, I'm taking the approach of storing the facts in an extra section in the .a files produced by cmd/pack, as this requires no changes to the build system. Analysis facts are thus, fittingly, treated much like type checker facts, which are recorded in the __PKGDEF section. Unfortunately, cmd/link blindly assumes that all sections not named __PKGDEF are object files, and tries to link them.

cmd/link should use a better heuristic for deciding what sections to link than section.Name != "__PKGDEF"; I propose strings.HasSuffix(section.Name, ".o"). Do we ever care about object files not called *.o?


This comment has been minimized.

Copy link
Contributor Author

commented Oct 26, 2018

Answering my own question: the name field is only 16 bytes so we can't rely on the file name suffix being untruncated, and thus the heuristic will have to rely on the prefix, or apply only to names so short that they are untruncated. So, how about the following predicate for matching non-linkable sections len(sectionName) < 16 && !strings strings.HasSuffix(sectionName, ".o")?


This comment has been minimized.

Copy link

commented Oct 31, 2018

Change mentions this issue: cmd/link: don't link sections not named .o

@gopherbot gopherbot closed this in 484fc06 Nov 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.