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

Fix elf segment matching (again) #318

Merged
merged 9 commits into from
Oct 5, 2023
Merged

Conversation

nsavoire
Copy link
Collaborator

@nsavoire nsavoire commented Oct 4, 2023

What does this PR do?

  • Use first LOAD segment for bias computation if available
    If all mappings are available (ie. they come from proc maps), then use the first LOAD segment (executable or not) to compute the bias.
    This will ensure that bias computation is possible even for processes that punch holes into existing mappings (eg.dotnet).

Other changes:

  • Fix typos and improve some naming
  • Use an enum class for DsoType and remove dso namespace
  • Add DsoOrigin to Dso class
    DsoOrigin indicates if Dso information was obtained from a perf mmap event or from parsing proc maps.
    *Only adjust Dso end if smaller
  • Improve mapping insertion
    When a new mapping is inserted, if it intersects other mappings, keep the remaining parts of the existing mappings if mapped file is the same or if new mapping is anonymous and it truncates the end of an existing mapping.
  • Avoid throwing exception if parsing of a proc map line fails
    Also explicits why expected return value of sscanf does not match number of specifiers.
  • Rename dso_from_procline to dso_from_proc_line
  • Improve const-correctness of dso_from_proc_line

DsoOrigin indicates if Dso information was obtained from a perf mmap event
or from parsing proc maps.
When a new mapping is inserted, if it intersects other mappings, keep
the remaining parts of the existing mappings if mapped file is the same
or if new mapping is anonymous and it truncates the end of an existing
mapping.
Also explicits why expected return value of sscanf does not match
number of specifiers.
If all mappings are available (ie. they come from proc maps), then
use the first LOAD segment (executable or not) to compute the bias.
@nsavoire nsavoire force-pushed the nsavoire/fix_elf_segment_matching branch from a8d8042 to b8efd7a Compare October 5, 2023 00:08
Dso dso2{5, 0x2000, 0x4fff, 0x1000, "libfoo.so.1", 0, PROT_READ | PROT_EXEC};
dso_hdr.insert_erase_overlap(Dso{dso2});

ASSERT_EQ(dso_hdr.get_nb_dso(), 2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this test.

Copy link
Collaborator

@r1viollet r1viollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Thanks for thoroughly looking into tricky load behaviours

@nsavoire nsavoire merged commit 0906294 into main Oct 5, 2023
@nsavoire nsavoire deleted the nsavoire/fix_elf_segment_matching branch October 5, 2023 11:54
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 this pull request may close these issues.

2 participants