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

Elf sbss issue #621

Closed
wynemo opened this issue Oct 14, 2023 · 1 comment · Fixed by #624
Closed

Elf sbss issue #621

wynemo opened this issue Oct 14, 2023 · 1 comment · Fixed by #624

Comments

@wynemo
Copy link

wynemo commented Oct 14, 2023

Hello!

I noticed that when using py-spy to read a Python library for mips64el from https://github.com/benfred/py-spy/blob/master/src/binary_parser.rs#L96, it seems to be reading "sbss".

bash-4.2# readelf -S /tmp/mips64.txt | grep -i 'NOBITS'
[24] .sbss NOBITS 900000000034ad28 0033ad28
[25] .bss NOBITS 900000000034ad30 0033ad28

i also try to use goblin to check:

image

I'm not sure if it can be adjusted slightly here, maybe like this:

diff --git a/src/binary_parser.rs b/src/binary_parser.rs
index a8d977a..bceaf9a 100644
--- a/src/binary_parser.rs
+++ b/src/binary_parser.rs
@@ -93,7 +93,9 @@ pub fn parse_binary(filename: &Path, addr: u64, size: u64) -> Result<BinaryInfo,
             let bss_header = elf
                 .section_headers
                 .iter()
-                .find(|header| header.sh_type == goblin::elf::section_header::SHT_NOBITS)
+                .filter(|header| header.sh_type == goblin::elf::section_header::SHT_NOBITS)
+                .max_by_key(|header| header.sh_size)
                 .ok_or_else(|| {
                     format_err!(
                         "Failed to find BSS section header in {}"

thanks.

@benfred benfred linked a pull request Oct 23, 2023 that will close this issue
@benfred
Copy link
Owner

benfred commented Oct 23, 2023

thanks for the bug report! I also hit this issue when I was trying to add python 3.12 support - py-spy was picking up the .tbss section in the python 3.12 binary from conda, and failing.

The fix you suggested works here (thanks!) - but I also added an additional check on the section name in #624, trying to make sure the section is named .bss and not only taking the largest section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants