Skip to content

Fix short-circuiting when TSDInfo not present, preventing reading DTVInfo#1294

Merged
christos68k merged 3 commits intoopen-telemetry:mainfrom
Shopify:fix-dtvinfo-read-when-tsd-not-present-upstream
Mar 31, 2026
Merged

Fix short-circuiting when TSDInfo not present, preventing reading DTVInfo#1294
christos68k merged 3 commits intoopen-telemetry:mainfrom
Shopify:fix-dtvinfo-read-when-tsd-not-present-upstream

Conversation

@dalehamel
Copy link
Copy Markdown
Contributor

What

Updates ExtractLibcInfo to:

  • Only error out if BOTH reads fail
  • Only set the value if not an error on read
  • Add a regression test that builds an mock ELF file to verify the correct behaviour

Why

In #929, I incorrectly added short circuiting where we would fail to read the DTV.

During the review of #1226, the first actual use of the DTV, @nsavoire correctly pointed this out (thank you!)

I recall that in an earlier version of the branch, I had anticipated this and just logged an error, but then in subsequent refactoring and addressing feedback this must have gotten lost.

To avoid this from happening again, I've added a regression test which actually calls ExtractLibcInfo with a stub ELF binary for testing purposes to prove that it correctly still reads the DTV in this edge case where the DTV and TSD are in separate binaries, so we can actually merge them.

My apologies for the oversight, between reviews and switching tasks I forgot about this edge case.

- Only error out if BOTH reads fail
- Only set the value if not an error on read
- Add a regression test that builds an mock ELF file to verify the correct
behaviour
@dalehamel dalehamel requested review from a team as code owners March 27, 2026 17:46
Comment thread libc/libc_test.go
// buildTestELF creates a minimal 64-bit ELF binary with the given dynamic symbols.
// Each symbol maps to its corresponding code byte slice. The resulting ELF has a
// SysV hash table so pfelf.File can resolve symbols via LookupSymbol/SymbolData.
func buildTestELF(t *testing.T, machine elf.Machine, symbols map[string][]byte) *pfelf.File {
Copy link
Copy Markdown
Contributor Author

@dalehamel dalehamel Mar 27, 2026

Choose a reason for hiding this comment

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

This is a bit heavy but I wanted to be sure that this regression was caught cleanly. It might be useful elsewhere, but for now i think this is an OK spot for it.

Disclaimer: I had AI help me write this in order to add the test.

Comment thread libc/libc.go Outdated
dalehamel and others added 2 commits March 30, 2026 06:30
Co-authored-by: Florian Lehner <florianl@users.noreply.github.com>
Comment thread libc/libc.go
}, nil
// Return an error only if both extractions failed.
if tsdErr != nil && dtvErr != nil {
return nil, fmt.Errorf("TSD: %s; DTV: %s", tsdErr, dtvErr)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: Maybe it's better to introduce TSDError and DTVError inside extract{TSD,DTV}Info and then a simple errors.Join here.

@christos68k christos68k merged commit 8047150 into open-telemetry:main Mar 31, 2026
58 of 59 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.

3 participants