Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/link: -buildmode=shared includes dead symbols #14578
Create a package with a source file like:
and try to build on linux/amd64 with
I would expect cmd/link to notice that foo.bar is unreachable and omit it from the resulting shared object.
Noticed working on https://go-review.googlesource.com/#/c/20076/.
Actually, I suppose things like:
mean cmd/link can't just assume locally-unused unexported symbols are globally unused.
Instead, let me refine the complaint to: since bar is unused and has no definition, cmd/link shouldn't need to complain. It should just omit defining a foo.bar symbol in the shared object.
If any later builds try to reference foo.bar, they should fail instead.
I agree this is awkward and annoying.
The reason this errors is because something is referencing foo.bar: the foo.bar·f structure the compiler creates. I guess that structure could use a special relocation type that causes foo.bar·f to be omitted iff the symbol the reloc points to is undefined? Maybe Ian can think of a better hack.