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

Closed
mdempsky opened this issue Mar 1, 2016 · 4 comments
Closed

cmd/link: -buildmode=shared includes dead symbols #14578

mdempsky opened this issue Mar 1, 2016 · 4 comments

Comments

@mdempsky
Copy link
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
Copy link
Member Author

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
Copy link
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
Copy link
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
@seankhliao
Copy link
Member

Obsoleted by #47788

@golang golang locked and limited conversation to collaborators Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants