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: -buildmode=shared includes dead symbols #14578

Open
mdempsky opened this Issue Mar 1, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@mdempsky
Member

mdempsky commented Mar 1, 2016

Create a package with a source file like:

package foo
func Foo() {}
func bar()

and try to build on linux/amd64 with -buildmode=shared. You get a linker error:

# foo
$GOPATH/src/foo/foo.go:3: missing function body for "bar"

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/.

/cc @ianlancetaylor @mwhudson

@mdempsky

This comment has been minimized.

Member

mdempsky commented Mar 1, 2016

Actually, I suppose things like:

runtime/cgo/iscgo.go://go:linkname _iscgo runtime.iscgo

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.

@mwhudson

This comment has been minimized.

Contributor

mwhudson commented Mar 1, 2016

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.

@mwhudson

This comment has been minimized.

Contributor

mwhudson commented Mar 1, 2016

BTW, that error is from the compiler :-) you need to add an assembly file to the package to get the error you're talking about.

@bradfitz bradfitz added this to the Unplanned milestone Apr 10, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment