PPC: Detect unpooled string literal references#188
Merged
encounter merged 2 commits intoencounter:mainfrom Apr 17, 2025
Merged
Conversation
encounter
approved these changes
Apr 17, 2025
| // Numeric type. | ||
| return Some(ty); | ||
| } | ||
| if bytes.len() >= 2 && bytes.iter().position(|&c| c == b'\0') == Some(bytes.len() - 1) { |
Owner
There was a problem hiding this comment.
Suggested change
| if bytes.len() >= 2 && bytes.iter().position(|&c| c == b'\0') == Some(bytes.len() - 1) { | |
| if bytes.len() >= 2 && bytes.iter().position(|&c| c == b'\0') == bytes.last() { |
I think this should work
Collaborator
Author
There was a problem hiding this comment.
last would return the last byte in the slice, I think? This is comparing to the last index (len-1), not the value, since all the values were already read inside the loop.
The compiler also doesn't like last for some reason:
can't compare `std::option::Option<usize>` with `std::option::Option<&u8>`
the trait `PartialEq<std::option::Option<&u8>>` is not implemented for `std::option::Option<usize>`
but trait `PartialEq<deranged::OptionRangedUsize<_, _>>` is implemented for it
for that trait implementation, expected `deranged::OptionRangedUsize<_, _>`, found `std::option::Option<&u8>`
Owner
There was a problem hiding this comment.
I think my brain was melted by C++ iterators, nevermind
| return Some(ty); | ||
| } | ||
| if bytes.len() >= 2 && bytes.iter().position(|&c| c == b'\0') == Some(bytes.len() - 1) { | ||
| // It may be an unpooled string if the symbol contains exactly one null byte at the end of the symbol. |
Owner
There was a problem hiding this comment.
Doesn't have to be this PR, just thinking aloud, this logic could easily live in common arch code.
Owner
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
objdiff already supports detected pooled PPC strings (
@stringBase), this PR adds support for unpooled ones as well:It assumes that a data symbol is an unpooled string if it's at least 2 bytes long and it contains exactly 1 null byte at the end of the symbol. I didn't check that all the bytes are displayable ASCII characters because I didn't want to exclude non-ASCII strings. This might have false positives but I haven't run into any in testing yet.