pfelf: fix and optimize mmapped section reading#526
Merged
fabled merged 2 commits intoopen-telemetry:mainfrom Jun 16, 2025
Merged
pfelf: fix and optimize mmapped section reading#526fabled merged 2 commits intoopen-telemetry:mainfrom
fabled merged 2 commits intoopen-telemetry:mainfrom
Conversation
The Section reader elfReader was assigned the SectionReader, not the backing pfelf.File's elfReader. This caused the dynamic cast to mmap.ReaderAt always fail in Section.Data(). Fix the assignment to pass the backing elfReader, for the cast to work correctly. And while at it, remove the SectionReader as it causes GC pressure and implement the ReadAt() function on the struct directly. This also fixes the Section to implement io.ReaderAt itnerface which commit 9788d39 accidentally removed by removing the embedded io.ReaderAt interface. Add also interace contract tests in the file.
florianl
approved these changes
Jun 13, 2025
rockdaboot
approved these changes
Jun 13, 2025
christos68k
approved these changes
Jun 13, 2025
| return 0, io.EOF | ||
| } | ||
| if uint64(off)+uint64(len(p)) > sh.FileSize { | ||
| p = p[:sh.FileSize-uint64(off)] |
Member
There was a problem hiding this comment.
Should we explicitly also return EOF here? The following ReadAt will not do that for this case (as it doesn't know anything about sh.FileSize).
Contributor
Author
There was a problem hiding this comment.
Yes. Per io.ReaderAt contract an error needs to be returned if read is short. I've added this.
This was referenced Jul 8, 2025
This was referenced Aug 14, 2025
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.
The Section reader elfReader was assigned the SectionReader, not the backing pfelf.File's elfReader. This caused the dynamic cast to mmap.ReaderAt always fail in Section.Data().
Fix the assignment to pass the backing elfReader, for the cast to work correctly. And while at it, remove the SectionReader as it causes GC pressure and implement the ReadAt() function on the struct directly. This also fixes the Section to implement io.ReaderAt itnerface which commit 9788d39 accidentally removed by removing the embedded io.ReaderAt interface. Add also interace contract tests in the file.