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

go tool nm: weird local.$(pkg) symbol #31568

Closed
dengoswei opened this issue Apr 19, 2019 · 5 comments
Closed

go tool nm: weird local.$(pkg) symbol #31568

dengoswei opened this issue Apr 19, 2019 · 5 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@dengoswei
Copy link

dengoswei commented Apr 19, 2019

What version of Go are you using (go version)?

$ go version
go version go1.11.1 linux/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/weicheng.dengos/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/data00/home/weicheng.dengos/go"
GOPROXY=""
GORACE=""
GOROOT="/home/weicheng.dengos/open-src/go"
GOTMPDIR=""
GOTOOLDIR="/home/weicheng.dengos/open-src/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build517419942=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$(mypkg) binary size 364MB.
By using https://github.com/knz/go-binsize-viz, I found:

  • runtime: take 100MB binary size;
  • "local.$(mypkg)" take 84MB binary size;
  • "$(mypkg)" take 80MB binary size;

By using "go tool nm ", I found something like this:
64ce350 2709 t local.code.byted.org/..../game_entry.(*GameEntryRequest).Read
64ce350 2709 T code.byted.org/..../game_entry.(*GameEntryRequest).Read

So the questions is: what's the local.(pkg) symbol ? where is it come from ??

What did you expect to see?

What did you see instead?

@ianlancetaylor
Copy link
Contributor

I don't know. I don't see that in Go binaries that I build. How exactly did you build your binary? Are you sure that nothing imports "local.code.byted.org/..."?

Note that you are likely to get better answers on a forum like golang-nuts. See https://golang.org/wiki/Questions.

@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 19, 2019
@rsc
Copy link
Contributor

rsc commented Apr 20, 2019

It comes from cmd/link/internal/ld/symtab.go:

if ctxt.DynlinkingGo() && bind == STB_GLOBAL && elfbind == STB_LOCAL && x.Type == sym.STEXT {
	// When dynamically linking, we want references to functions defined
	// in this module to always be to the function object, not to the
	// PLT. We force this by writing an additional local symbol for every
	// global function symbol and making all relocations against the
	// global symbol refer to this local symbol instead (see
	// (*sym.Symbol).ElfsymForReloc). This is approximately equivalent to the
	// ELF linker -Bsymbolic-functions option, but that is buggy on
	// several platforms.
	putelfsyment(ctxt.Out, putelfstr("local."+s), addr, size, STB_LOCAL<<4|typ&0xf, elfshnum, other)
	x.LocalElfsym = int32(numelfsym)
	numelfsym++
	return
} else if bind != elfbind {
	return
}

I still don't know exactly what it means. I think you can ignore it for purposes of binary size, though: the symbol clearly has the same address as the real one.

@dengoswei
Copy link
Author

Turn out: one of the common lib using plugin.

import plugin

_, err := plugin.Open("x.so")

a dummy code like this will introduce significant amount of local.* symbols in the final binary, which huge increase the binary size (dep on u binary size).

@dengoswei
Copy link
Author

dengoswei commented Apr 22, 2019

demo

package main

import (
	"fmt"
	"plugin"
)

func main() {
	_, err := plugin.Open("test.so")
	if err != nil {
		fmt.Println("tet")
	}

}

go tool nm ./$(binary) | grep runtime.abort.f

@ianlancetaylor
Copy link
Contributor

The duplicate local symbols don't increase the actual binary size. They only increase the binary size as reported by programs that compute the binary size by adding up all the symbol sizes. That process of adding up symbol sizes double counts the size of all the local symbols.

@golang golang locked and limited conversation to collaborators Apr 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants