Repository navigation
PROF-16674 Make ElfParser follow the gABI for symbols, the dynamic array and PLT relocations - #1024
zhengyu123 wants to merge 15 commits into
Conversation
…bles loadSymbolTable added every symbol with a non-zero st_value at base + st_value. Per the gABI that is wrong for three kinds of symbol: - STT_TLS: st_value is an offset into the TLS template, so the entry landed at the image start (libjvm, glibc). - SHN_ABS and other reserved section indices: st_value is not an address, but it was relocated by the load bias anyway. - SHN_UNDEF: in an executable a non-zero st_value is the PLT stub address, so the stub was named after the real function. Skip these, and the STT_SECTION and STT_FILE bookkeeping entries. Add a test with a hand-built ELF image. Give the symbols in symbolTableMisalignedEntries a defined section index, as real symbols have. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…m DT_PLTREL parseDynamicSection had three gABI defects: - It walked p_memsz bytes and ignored DT_NULL, so stale slots after the terminator (patchelf, prelink) could override real tags. A p_memsz that is not a multiple of sizeof(ElfDyn) also read a partial entry. - It returned early when DT_RELENT/DT_RELAENT was missing. A library with only PLT relocations has neither, so it lost all its imports and the hooks were not patched. The DT_JMPREL entry size now comes from DT_PLTREL. - DT_REL and DT_RELA shared one set of variables, so one table hid the other. They now have separate tables. Apply the same entry sizes and tables in hashImportLayout, so the image fingerprint covers what the parser records. Add tests with hand-built in-memory images for a PLT-only library and for tags after DT_NULL. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ile and common symbols Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…thout overflow, test DT_PLTREL precedence Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…print, assert the strAt() bound test, drop dead clamps Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e size Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… strAt() bound with a control; guard skip <= size Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…4_Rela Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cannot pick DT_RELENT for a RELA table Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
More details
Import parsing and fingerprinting use consistent relocation strides for PLT-only images without DT_RELENT/DT_RELAENT. Static review found no actionable defects; runtime behavior was not exercised.
🤖 Bits Code Review · Commit eaee154
CI Test ResultsRun: #44814626519 | Commit:
Status Overview
Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled Summary: Total: 32 | Passed: 32 | Failed: 0 Updated: 2026-11-20 21:10:58 UTC |
Reliability & Chaos Results✅ All reliability & chaos checks passed Pipeline: https://gitlab.ddbuild.io/DataDog/java-profiler/-/pipelines/154758098 |
|
@DataDog review |
There was a problem hiding this comment.
More details
Static review found no actionable defect in symbol filtering, dynamic-array termination, or relocation parsing and fingerprinting. Runtime behavior remains unverified because builds and tests were not run.
🤖 Bits Code Review · Commit eaee154
kaahos
left a comment
There was a problem hiding this comment.
LGTM! I left 2 comments about branches that are not tested I think but the implementation is good to me.
…of pltEntrySize Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…, cover valid DT_RELAENT and DT_PLTREL=DT_RELA Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…cover each REL/RELA and fallback stride positively Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…, drop a duplicate row, add RELENT/RELAENT rows Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…second entry inside the table Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
jbachorik
left a comment
There was a problem hiding this comment.
Sphinx Review
Automated review findings for this pull request are posted as inline comments below.
Reviewed commit: 405e6b4
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🧞 Sphinx — automated review
| static size_t pltEntrySize(uint64_t pltrel, size_t relent, size_t relaent) { | ||
| if (pltrel == DT_REL) return sizeof(Elf64_Rel); | ||
| if (pltrel == DT_RELA) return sizeof(Elf64_Rela); | ||
| return relaent != 0 ? relaEntrySize(relaent) : relent; |
There was a problem hiding this comment.
pltEntrySize() silently falls back to relaent/relent when DT_PLTREL is present but holds any value other than DT_REL/DT_RELA (e.g. a corrupted or nonstandard image).
A bogus DT_PLTREL is exactly the case where the stride is unknown, yet the code guesses one and walks the untrusted DT_JMPREL table at that guessed stride anyway, both in parseDynamicSection() (wrong imports can be recorded: a misaligned r_offset + a coincidentally resolvable symbol name registers a bogus addImport slot for LibraryPatcher) and in hashImportLayout() (fingerprint of garbage). The PR notes acknowledge this ("A DT_PLTREL value other than REL/RELA falls back silently"), but for a table whose entry type is explicitly declared and wrong, the safe gABI behavior is to skip the table, as relaEntrySize() already does for undersized DT_RELAENT.
- (a) Treat an out-of-range DT_PLTREL as invalid:
if (pltrel != 0 && pltrel != DT_REL && pltrel != DT_RELA) return 0;before the fallback, so the table is skipped the same wayrelaEntrySize()skips undersized entries. - (b) Alternatively, keep the fallback but log a warning once per image, so a nonstandard DT_PLTREL is diagnosable instead of silently mis-strided.
- Add a test mirroring
pltRelOverridesRelaentwithDT_PLTREL = 0x1234asserting the PLT table is skipped in both the parse and the fingerprint.
Evidence
static size_t pltEntrySize(uint64_t pltrel, size_t relent, size_t relaent) {
if (pltrel == DT_REL) return sizeof(Elf64_Rel);
if (pltrel == DT_RELA) return sizeof(Elf64_Rela);
return relaent != 0 ? relaEntrySize(relaent) : relent;
}React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🧞 Sphinx — automated review
| // Imports can also be in .rela.dyn / .rel.dyn, for example if a shared | ||
| // library is built without PLT (-fno-plt). If both tables exist, | ||
| // addImport saves them both. | ||
| addImports(rela, relasz, relaEntrySize(relaent), relativeBytes(relacount, relaent, relasz), true); |
There was a problem hiding this comment.
For the
.rela.dyn table, the stride is taken from DT_RELAENT and the table is skipped entirely when the tag is absent (relaEntrySize(0) returns 0).
Per the gABI the Elf64_Rela entry size for a DT_RELA table is implied by the format, and DT_RELAENT is not required to be present; a spec-valid image with DT_RELA/DT_RELASZ but no DT_RELAENT silently loses all its R_GLOB_DAT/R_ABS64 imports (e.g. pthread_create for a -fno-plt library), which LibraryPatcher then cannot patch. The same applies to .rel.dyn with a missing DT_RELENT. This is not a regression (the old code required a non-zero relent too), and every mainstream linker emits the *ENT tags, so it only bites hand-built or stripped-tag images — but the PR's own rationale for the DT_JMPREL fix was exactly that a table must not depend on an entry-size tag being present.
- Default
relaenttosizeof(Elf64_Rela)(andrelenttosizeof(Elf64_Rel)) when the tag is absent, using the tag value only when present and >= the implied size — mirroring howpltEntrySize()now derives theDT_JMPRELstride without relying on the*ENTtags. - Or document explicitly (comment + PR notes) that
DT_RELAENT/DT_RELENTabsence is treated as invalid by design, so the asymmetry withDT_JMPRELis intentional.
Evidence
addImports(rela, relasz, relaEntrySize(relaent), relativeBytes(relacount, relaent, relasz), true);
addImports(rel, relsz, relent, relativeBytes(relcount, relent, relsz), true);React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🧞 Sphinx — automated review
| // Not SHN_UNDEF (defined elsewhere), reserved indices other than SHN_XINDEX (absolute | ||
| // value or alignment), STT_TLS (TLS offset) or STT_SECTION/STT_FILE. | ||
| static bool isDefinedInImageSymbol(const ElfSymbol& entry) { | ||
| if (entry.st_shndx == SHN_UNDEF || (entry.st_shndx >= SHN_LORESERVE && entry.st_shndx != SHN_XINDEX)) { |
There was a problem hiding this comment.
SHN_XINDEX is not itself evidence that a symbol is defined in the image: it signals that the actual section index is stored in the associated SHT_SYMTAB_SHNDX table.
This filter accepts every such symbol without resolving that index, including entries whose actual index is SHN_UNDEF or another special index, and can add a non-address value to the code cache.
Resolve SHN_XINDEX through the section's associated SHT_SYMTAB_SHNDX data before deciding whether the symbol is an in-image definition; if that table is unavailable or invalid, skip the symbol.
Evidence
if (entry.st_shndx == SHN_UNDEF || (entry.st_shndx >= SHN_LORESERVE && entry.st_shndx != SHN_XINDEX)) {React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🧞 Sphinx — automated review
| static size_t pltEntrySize(uint64_t pltrel, size_t relent, size_t relaent) { | ||
| if (pltrel == DT_REL) return sizeof(Elf64_Rel); | ||
| if (pltrel == DT_RELA) return sizeof(Elf64_Rela); | ||
| return relaent != 0 ? relaEntrySize(relaent) : relent; |
There was a problem hiding this comment.
No test in this PR would detect: using
relent instead of a valid relaent for the fallback stride in pltEntrySize() when DT_PLTREL is absent in pltEntrySize
Add a test with DT_PLTREL absent and a valid DT_RELAENT that differs from DT_RELENT, then assert the PLT import is parsed and its relocation table affects the fingerprint.
Evidence
return relaent != 0 ? relaEntrySize(relaent) : relent;React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🧞 Sphinx — automated review
What does this PR do?:
Makes
ElfParser(symbols_linux.cpp) follow the gABI in four places:loadSymbolTableskipsSHN_UNDEF, reserved section indices (exceptSHN_XINDEX),STT_TLS,STT_SECTIONandSTT_FILEsymbols. They no longer become code-cache entries.parseDynamicSectionstops at the firstDT_NULLand reads wholeElf64_Dynentries only.DT_JMPRELentry size comes fromDT_PLTREL, not fromDT_RELENT/DT_RELAENT.DT_RELAandDT_RELnow have separate size, entry-size and count variables.DT_RELAENTsmaller thansizeof(Elf64_Rela)skips the.rela.dyntable. WithoutDT_PLTREL, the same value skips the PLT table instead of falling back toDT_RELENT.hashImportLayout(the image fingerprint) uses the same tables and entry sizes, so the fingerprint covers what the parser records. The relative-relocation skip (DT_RELACOUNT× entry size) is clamped without overflow.Motivation:
Findings 1-4 of PROF-16674. Bogus code-cache entries, imports lost for libraries with only PLT relocations, and stale slots after
DT_NULLoverriding real tags. Checked against the TIS ELF 1.2 spec for the dynamic tags, special section indices and symbol types.Additional Notes:
relent == 0is gone. Images with no relocation entry-size tags (the vDSO, relocation-free DSOs) now load their.dynsyminto the code cache. This is the fix proposed in PROF-16641 and is tested.DT_RELAENTabove 24 is still accepted.DT_NULLstop is done. The parser still readsp_memszand the fingerprintp_filesz.PT_DYNAMICdereference and a zero fingerprint whenDT_STRSZis missing (PROF-16755). Both were already onmain.DT_PLTRELandDT_RELAENT, the PLT is read at theDT_RELENTstride. ADT_PLTRELvalue other than REL/RELA falls back silently. The parser and the fingerprint scan the tags separately.LibraryPatcheruses to tell a reloaded image apart./code-reviewon each fix range. No Critical or High findings.How to test the change?:
./.claude/commands/build-and-summarize :ddprof-lib:gtestDebug_elfparser_ut(Linux only; the file is#ifdef __linux__).SHN_LORESERVEboundary andSHN_XINDEX), PLT-only imports,DT_PLTRELoverDT_RELAENT, theDT_REL/DT_RELAPLT entry strides and theDT_RELAENT/DT_RELENTfallback strides (parse and fingerprint), theDT_NULLstop,.dynsymwithout relocation tags, and relative-count overflow forDT_RELAandDT_REL.eaee154de: therelentearly return, the unclamped count, theDT_RELAENTsize check and the PLT fallback. The stride tests added in review are not mutation-checked.eaee154de:elfparser_utpassed 43 of 43 on glibc, and the full:ddprof-lib:gtestDebugpassed on glibc and musl. Atbf600b474: theelfparser_uttask passed on glibc. All runs were in podman containers on aarch64 only; x86-64 has not been run locally.For Datadog employees:
credentials of any kind, I've requested a security review (run the
dd:platform-security-reviewskill, or file a request via the PSEC review form).
bewairealso runs automatically on every PR.Unsure? Have a question? Request a review!
🤖 Generated with Claude Code