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

Introduce ELF Backend type #941

Merged
merged 7 commits into from
Dec 23, 2024
Merged

Conversation

danielocfb
Copy link
Collaborator

For implementation peculiarities on Linux, we cannot make do with an ELF parser that unconditionally relies on memory mapped data. Rather, for certain /proc files we are actually forced to use file I/O instead. In order to switch between the two, introduce the Backend trait that abstracts over the differences between the two. In a nutshell, for the mmap backend we continue reading references to objects while for the file I/O based one we will work with owned objects instead.

d-e-s-o added 2 commits July 13, 2023 11:38
For implementation peculiarities on Linux, we cannot make do with an ELF
parser that unconditionally relies on memory mapped data. Rather, for
certain /proc files we are actually forced to use file I/O instead. In
order to switch between the two, introduce the Backend trait that
abstracts over the differences between the two. In a nutshell, for
the mmap backend we continue reading references to objects while for the
file I/O based one we will work with owned objects instead.

Signed-off-by: Daniel Müller <[email protected]>
So far our ELFN enumeration, which abstracts over the differences
between 32 and 64 bit ELF types, was solely storing references. In the
future, we are going to work with owned objects on some occasions. Store
Cow objects instead of references inside ElfN to make that possible.

Signed-off-by: Daniel Müller <[email protected]>
In order to switch the ElfParser logic between memory mapped I/O and
file I/O, parametrize it by the "backend" to employ. Using the Mmap
backend will stay the default, as it is the more sensible option.

Signed-off-by: Daniel Müller <[email protected]>
Now that our ELF logic is starting to become parametrized by the backend
to use and no longer necessarily employs memory mapping, rename the
'mmap lifetime to 'elf to be a bit less misleading.

Signed-off-by: Daniel Müller <[email protected]>
Similar to what we did for the ElfN enum, store a Cow object instead of
a reference inside ElfNSlice. Doing so will allow us to abstract over
the precise memory representation, which can change depending on the
backend in use.

Signed-off-by: Daniel Müller <[email protected]>
Copy link

codecov bot commented Dec 23, 2024

Codecov Report

Attention: Patch coverage is 73.54839% with 41 lines in your changes missing coverage. Please review.

Project coverage is 94.25%. Comparing base (6ee4daa) to head (e2ab057).

Files with missing lines Patch % Lines
src/elf/parser.rs 70.58% 40 Missing ⚠️
src/elf/types.rs 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #941      +/-   ##
==========================================
- Coverage   94.56%   94.25%   -0.32%     
==========================================
  Files          57       57              
  Lines       10527    10584      +57     
==========================================
+ Hits         9955     9976      +21     
- Misses        572      608      +36     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Instead of unconditionally relying on memory mapped data in our
ElfParser and Cache, switch over to using the recently introduced
backend. The backend will transparently decide whether to work with
references or owned objects.

Signed-off-by: Daniel Müller <[email protected]>
Add some tests for our file I/O based ELF parser.

Signed-off-by: Daniel Müller <[email protected]>
@danielocfb danielocfb merged commit 3f4b694 into libbpf:main Dec 23, 2024
41 checks passed
@danielocfb danielocfb deleted the topic/elf-backend branch December 23, 2024 19:01
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