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/elf: elf.Symbols() incorrectly returns ErrNoSymbols for valid elf binaries. #50626

Closed
ok-john opened this issue Jan 15, 2022 · 2 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@ok-john
Copy link

ok-john commented Jan 15, 2022

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

go1.18-3b5eec9

Does this issue reproduce with the latest release?

Yes.

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

linux/amd64

What did you do?

Attempted to view the symbol table of both static & dynamically linked binaries compiled with gcc.

For example, readelf -{s, S} /bin/ls (or even readelf -{s, S} /bin/* on most distributions of linux) shows the symbol table of each elf binary without error.

Attempting to view the symbol table of every binary under /bin/* on a basic linux distro by using elf.Symbols() failed in all cases.

See example script here.

What did you expect to see?

A valid return of []elf.Symbol from elf.Symbols() for at least one elf binary.

What did you see instead?

elf.Symbols() returns ErrNoSymbols (ref)

@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 16, 2022
@ianlancetaylor
Copy link
Contributor

In many Linux distros programs like /bin/ls have no SHT_SYMTAB section, so the debug/elf Symbols method on such a file will return ErrNoSymbols. The readelf -s output that you mention is the dynamic symbols, the SHT_DYNSYM section (readelf -s displays both the normal symbols and the dynamic symbols). With debug/elf you can fetch that information using the DynamicSymbols method.

@ok-john
Copy link
Author

ok-john commented Jan 16, 2022

In many Linux distros programs like /bin/ls have no SHT_SYMTAB section, so the debug/elf Symbols method on such a file will return ErrNoSymbols. The readelf -s output that you mention is the dynamic symbols, the SHT_DYNSYM section (readelf -s displays both the normal symbols and the dynamic symbols). With debug/elf you can fetch that information using the DynamicSymbols method.

Thanks for clarifying.

@golang golang locked and limited conversation to collaborators Jan 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

4 participants