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

debug/gosym: func (*Sym) PackageName() returns wrong package names #29551

Closed
Julio-Guerra opened this issue Jan 4, 2019 · 1 comment
Closed
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@Julio-Guerra
Copy link

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

go version go1.10.7 linux/amd64

What did you do?

I am using PackageName() on the symbol table to get the list of packages at run-time.

But it returns some unexpected values for symbols not only prefixed by the package name. Such as type..eq. and type..hash..

For example PackageName() on symbols:

  • type..eq.runtime._panic returns type instead of runtime
  • type..hash.github.com/golang/protobuf/proto.textWriter returns type..hash.github.com/golang/protobuf/proto

So either PackageName() needs to handle this case, or these prefixes should come after the package name so that PackageName()'s expectations are true, ie. the prefix before is the package name.

Here is the piece of code reading the symbol table of the currently running executable file:

       executable, err := os.Executable()
	if err != nil {
		log.Fatal(err)
	}

	log.Println("reading ELF file ", executable)

	exe, err := elf.Open(executable)
	if err != nil {
		log.Fatal(err)
	}
	defer exe.Close()

	var pclndat []byte
	if sec := exe.Section(".gopclntab"); sec != nil {
		pclndat, err = sec.Data()
		if err != nil {
			log.Fatal("cannot read .gopclntab section: ", err)
		}
	}

	sec := exe.Section(".gosymtab")
	symTabRaw, err := sec.Data()
	if err != nil {
		log.Fatal(err)
	}
	pcln := gosym.NewLineTable(pclndat, exe.Section(".text").Addr)
	symTab, err := gosym.NewTable(symTabRaw, pcln)
	if err != nil {
		log.Fatal("cannot create the Go synbol table: ", err)
	}
	for i := range symTab.Funcs {
		fmt.Println(symTab.Funcs[i].PackageName())
	}
@Julio-Guerra Julio-Guerra changed the title debug/gosym: func (*Sym) PackageName() returns type..eq. and type..hash. prefixes debug/gosym: func (*Sym) PackageName() returns wrong pacakge names Jan 4, 2019
@Julio-Guerra Julio-Guerra changed the title debug/gosym: func (*Sym) PackageName() returns wrong pacakge names debug/gosym: func (*Sym) PackageName() returns wrong package names Jan 4, 2019
@ianlancetaylor ianlancetaylor added help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jan 4, 2019
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Jan 4, 2019
@gopherbot
Copy link

Change https://golang.org/cl/156397 mentions this issue: debug/gosym: parse symbol name with linker prefix correctly

@golang golang locked and limited conversation to collaborators Mar 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants