Skip to content

pfelf: fix and optimize mmapped section reading#526

Merged
fabled merged 2 commits intoopen-telemetry:mainfrom
fabled:tt-pfelf-sections-mmap-fix
Jun 16, 2025
Merged

pfelf: fix and optimize mmapped section reading#526
fabled merged 2 commits intoopen-telemetry:mainfrom
fabled:tt-pfelf-sections-mmap-fix

Conversation

@fabled
Copy link
Copy Markdown
Contributor

@fabled fabled commented Jun 13, 2025

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.

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.
@fabled fabled requested review from a team as code owners June 13, 2025 08:55
Comment thread libpf/pfelf/file.go
return 0, io.EOF
}
if uint64(off)+uint64(len(p)) > sh.FileSize {
p = p[:sh.FileSize-uint64(off)]
Copy link
Copy Markdown
Member

@christos68k christos68k Jun 13, 2025

Choose a reason for hiding this comment

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

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. Per io.ReaderAt contract an error needs to be returned if read is short. I've added this.

@fabled fabled merged commit c02b9f2 into open-telemetry:main Jun 16, 2025
25 checks passed
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.

4 participants