Skip to content

feat(elf): inspect dynamic dependencies and required symbol versions - #7868

Merged
N0zoM1z0 merged 77 commits into
morluto:mainfrom
mvanhorn:feat/elf-dependencies
Nov 17, 2026
Merged

N0zoM1z0 merged 77 commits into
morluto:mainfrom
mvanhorn:feat/elf-dependencies

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add offline inspect-elf-dependencies / inspect_elf_dependencies for ELF32/ELF64 needed libraries, literal search paths, GNU symbol versions and undefined dynamic imports. Retained summaries/pages preserve source identity, uncertainty and coverage. The selected image is read without execution or host-library resolution.

GNU-hash decoding has a finite work allowance and cancellation checkpoints; decoder limits use the shared error algebra. CLI inputs, application-admitted MCP summaries and provider Evidence preserve omitted versus explicitly selected parameters. MCP captures selected names at canonical SDK validation without retaining raw input trees; SDK callbacks and delivery still receive parsed defaults. Execution defaults remain with their owning contracts, and help renders schema defaults once for both arguments and options.

The new tool raises the catalog to 256 entries. Grok verification now collects bounded native keyword-search results and checks their union against the complete catalog, retaining pending queries through partial readiness.

Validation

  • ELF parser/provider/view checks: 80 tests passed. Public CLI/MCP, retained-view, filesystem and decompile-all controls: 14 passed. Provider conformance: 75 passed; stable-artifact/finalization boundaries: 274 passed.
  • Shared CLI schema/help/delivery/input checks: 1105 passed. All 112 parity goldens passed unchanged; subsequent argument-help checks passed all 25 selected help goldens, 28 help/schema checks and 7 integrity-policy checks.
  • Real /usr/bin/ls CLI output matched readelf dependencies and required versions; actual stdio MCP summary/paging controls passed and the selected file digest stayed unchanged.
  • Official Grok Build 1.0.50 on Linux x64: real native chat and full call passed using a loopback model fixture. Two native searches validated all 256 input schemas, followed by analysis, offload and Evidence recovery. All 8 native verifier preflight ownership regressions passed.
  • The final provider-parameter fix passed adapter parity, SDK default/cancellation/capacity controls, real stdio MCP in full and hot-cold profiles, typecheck, changed-file lint/format, Knip, metadata, architecture and the runtime build. The rebuilt native Grok full call and real ELF CLI/MCP checks also passed. Final-head CI passed all required gates, all 12 test shards and the Windows capability/package lane; automated review passed with no unresolved threads.
  • One local launcher-registration test fails on both this branch and pinned main af062e7: equivalent Node executable symlink spellings differ. It is outside this change.

Full typed lint exceeded the local 6 GiB early-stop budget; a later whole-static run hit its time limit. Complete current-head local static coverage remains unverified; CI supplies the full gate. No OOM occurred. Live model APIs, native Windows Grok behavior, loader behavior and ABI compatibility were not verified.

Author readiness

Human owner: @mvanhorn

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Add inspect-elf-dependencies and inspect_elf_dependencies for ELF32/ELF64
ET_EXEC and ET_DYN images, read statically without executing them or
invoking the dynamic loader. Report ordered DT_NEEDED names with
duplicates preserved, DT_SONAME, DT_RPATH and DT_RUNPATH as written
including $ORIGIN/$LIB/$PLATFORM tokens, decoded DT_FLAGS and DT_FLAGS_1,
PT_INTERP, GNU version requirements and definitions, derived
per-namespace maxima, and undefined .dynsym imports joined to
library@version when known. A missing PT_DYNAMIC is an observed empty
inventory. Relocatable objects and core dumps are rejected toward the
matching workflows. Cyclic version chains and exhausted named budgets
return no partial success.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-28T16:18:27.154667Z
We couldn’t complete this review. Comment @codex review to try again.
2fc3824 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The latest change appears safe to merge; no new actionable issue was found.

Summary

Adds offline ELF dependency inspection through CLI and MCP, with retained summaries and selectable pages.

  • ELF reports show needed libraries and symbol versions without running the image.
  • CLI and MCP record caller choices separately from execution defaults.
  • Grok verification checks all tools across bounded searches.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[CLI or MCP request] --> B[Admit selected file and controls]
  B --> C[Read stable file without execution]
  C --> D[Decode bounded ELF tables]
  D --> E[Complete Evidence with identity and coverage]
  E --> F[Inline inventory]
  E --> G[Retained summary]
  G --> H[Selected pages from retained Evidence]
Loading

Reviews (65) · Last reviewed commit: "test(mcp): assert omitted and explicit o..." · Reviewed by Greptile

Comment thread src/native/elf/ElfDependencyParser.ts Resolved
Comment thread src/native/elf/ElfDependencyParser.ts Resolved
Comment thread src/native/elf/ElfDependencyParser.ts Resolved
Comment thread src/native/elf/ElfDependencyParser.ts Resolved
Comment thread src/native/elf/ElfDependencyParser.ts Resolved
Comment thread src/domain/native/elfDependencies.ts Resolved
Comment thread src/native/elf/ElfDependencyParser.ts Resolved
Comment thread src/native/elf/ElfDependencyParser.ts Resolved
# Conflicts:
#	.agents/skills/reverse-engineer-anything/SKILL.md
#	src/contracts/analysisViewToolContracts.ts
#	src/domain/analysisView/analysisView.ts
#	src/generatedPackageMetadata.ts
#	src/server/createServer.ts
- Keep DT_VERNEED/DT_VERDEF fallback reads and the GNU hash walk inside
  the admitting PT_LOAD mapping or section instead of EOF.
- Report a version table with no record count as unreadable.
- Keep the verneed/verdef prefix read before a failure and join imports
  only against fully read verneed entries.
- Leave imports unresolved when verneed entries reuse a version index.
- Record name_unreadable for empty PT_INTERP segments and paths.
- Compare version components as exact integers and skip empty
  namespaces when deriving maxima.
- Type the elf-dependencies view kinds for the refactored view registry.
@mvanhorn

Copy link
Copy Markdown
Contributor Author

This branch now has main merged in, with the conflicts resolved. Main split analysisView.ts into request, result and shape modules, so the elf-dependencies view now registers through analysisViewRequest.ts, analysisViewResult.ts and the retained projector map, the same way native-exports does. createServer.ts takes main's layout with the inspect_elf_dependencies registration added next to the kernel module tool. Skill version moves to 56 since main is at 55. Merge commit is 0873e42.

Comment thread src/native/elf/ElfDependencyParser.ts Resolved
Comment thread src/native/elf/ElfDependencyParser.ts Resolved
Comment thread src/native/elf/ElfDependencyParser.ts Resolved
Comment thread src/cli/binaryDiagnosticsCommands.ts Resolved
- Decode each dynamic string offset once and charge every retained
  reference, including import version names, against one scan and
  retained-text budget fixed by the admitted image length.
- Treat DT_* entries as the load-time facts. Use a section header only
  when it names the same address, maps to the same file bytes, and
  agrees on DT_STRSZ or DT_SYMENT; report a disagreeing section.
- Page version definitions and derived version maxima through their own
  view collections; summaries keep counts and table status.
- Keep the read file's path, SHA-256, and byte count as a partial
  observation when parsing fails after a completed read.
Comment thread src/native/elf/ElfDependencyParser.ts Resolved
Comment thread src/native/elf/ElfDependencyParser.ts Resolved
Comment thread src/native/elf/ElfDependencyParser.ts Resolved
Resolve the skill version conflict at 59, one past main's 58, and regenerate
package metadata.
asTag cut every ELF64 tag to 32 bits, so 0x100000001 read as DT_NEEDED and
0x100000000 read as DT_NULL and ended the walk. Keep the class-width value
and skip tags wider than any known DT_* tag.

A PT_INTERP outside the file kept its invalid range in the report location,
so the service rejected the whole inventory. Return a null location with the
existing issue, which still names the declared offset.
Comment thread src/native/elf/ElfDependencyParser.ts Resolved
A nonzero bucket below firstSymbol made the chain walk read before the
chain array, so a stripped image could report a short symbol count and
lose imports while coverage stayed complete. Treat the table as
unusable, matching the reader in DartElf.ts.
The walkers read vn_next, vna_next and vd_next only while the count said
another record was due, so a count that stopped short of the links dropped
the remaining records and still reported complete coverage. The dynamic
loader follows the links, so those records are real requirements.

Move the chain step into one helper that also requires the final link to
be zero. A conflict keeps the records already read, marks the table
unreadable, and leaves coverage partial.
Nothing imports the alias, so knip fails the repository check.
Comment thread src/native/elf/ElfDependencyParser.ts Resolved
Every count limit failed as the same capacity boundary, so recovery text
could not tell a caller budget from a fixed ceiling. An image over the
dynamic-symbol ceiling was told to raise max_imports, which the schema caps
at that same value. The failure now carries the limit that was hit. Budget
failures name only that budget and its maximum. Ceiling failures, including
the input-size ceiling, say this release has no runtime override and name
what does not raise them.

DT_FLAGS and DT_FLAGS_1 were cut to 32 bits before decoding, so ELF64 bits
above the low word vanished from raw and unrecognized. The decoder now
keeps the whole word and the output schema allows safe integers. Words past
that range stay refused rather than cut.

The fixture's 64-bit writer cut values the same way, and its concatenation
overflowed the stack on a table large enough to reach the ceiling.
tableFromSection copied a section's declared size into the table and its
report location without checking it fits the file. A .gnu.version_r or
.gnu.version_d section with a valid start and an oversized size still parsed,
then ElfDependenciesService.validReport rejected the published range and the
whole inventory was lost.

Clamp section tables to the file and report malformed_entry. A table starting
past the end has no usable part, so the dynamic declaration is used instead.
locateSymbolCount no longer takes a count from such a section, which dropped
every import or hit the dynamic symbol ceiling when the size was a multiple of
the entry size.
Comment thread src/native/elf/ElfDependencyParser.ts Resolved
Rejecting an oversized .dynsym now reaches the hash fallback, which read
the count at hash.offset + 4 without checking the section range. With no
DT_HASH tag and a .hash offset past the file, agreedSection keeps the
section and the read throws, so the provider loses the whole inventory.

A .hash section that does not fit the file now gives a malformed_entry
issue and no count, and the walk moves on to DT_HASH and GNU hash. If
none of them gives a count, the existing table_unavailable issue reports
it and the libraries and versions stay in the report.
Resolve conflicts with the capability binding refactor: register the ELF dependencies service and provider through the capability declarations and services instead of the old createServer wiring.
Comment thread src/domain/native/elfDependencies.ts Resolved
@mvanhorn

mvanhorn commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged current main into this branch to clear the conflicts. main moved ELF service wiring into the capability declarations and services, so inspect_elf_dependencies is now registered there (the old createServer and catalog-builders edits were dropped). Typecheck, the composition and conformance tests, the ELF and server unit tests, and the architecture and module boundary checks pass locally.

…ports

DT_NEEDED and DT_SONAME offsets that pass the safe-integer check were
rejected by the uint schema, which failed the whole report. Allow any safe
integer so readable dependencies, versions and imports survive.
…revisions

inspect-elf-dependencies dropped the caller's path spelling from Evidence
because it never passed callerInputPath. Pass it as the other one-shot
commands do.

parseVerneed and parseVerdef read every record with revision 1's layout, so
a damaged header could resolve imports while coverage stayed complete. Both
now check the header revision first and report the table as unreadable.
gensokyo-dev and others added 2 commits November 17, 2026 04:21
Produce named decoder limits through the shared parse-failure algebra and project their facts at the provider boundary. Remove the superseded count-limit carrier and reuse the shared error-message projection.

Check nested Evidence identity, caller path and digest in normal completion and late cancellation, and align the MCP architecture assertion.

Co-authored-by: gensokyo-dev <[email protected]>
Register the public CLI and MCP cases for the provider capability, and regenerate the advertised output-schema summary after the Evidence identity migration.

Co-authored-by: gensokyo-dev <[email protected]>

@gensokyo-dev gensokyo-dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The offline scope fits REA. Validated the refreshed implementation with 90 focused source tests, 274 public CLI/MCP/filesystem/finalization tests, 75 conformance tests, serial static checks, docs checks, and a real ELF/readelf comparison. Named parser limits, canonical Evidence identity, and retained views are covered.

Full typed lint remains unverified under the local memory budget; current required CI must pass before merge.

Comment thread src/native/elf/ElfDependencyParser.ts Resolved
Keep application-owned input defaults at the application boundary. CLI option schemas retain help defaults without inserting omitted values; MCP summary bindings distinguish SDK-owned defaults from raw application requests, including nested selections. Record only the caller-selected ELF dependency controls.

Cover omitted, explicit-default and nondefault budgets through the real CLI/MCP, SDK admission, nested application input, and help rendering.

Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)
Co-authored-by: gensokyo-dev <[email protected]>
Comment thread src/cli/contractCliDescription.ts Resolved
gensokyo-dev and others added 3 commits November 17, 2026 05:11
Preserve shared reader checkpoints in the provider driver, keep named CPU limits, and verify cancellation identity and retry. Scope focused contract imports and align CLI omission assertions.

Co-authored-by: gensokyo-dev <[email protected]>
Check a separate input using canonical defaults while retaining caller omission and deferred JSON text. Cover capture, signal and SQLite registrations alongside existing cleanup and admission workflows.

Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)

Co-authored-by: gensokyo-dev <[email protected]>
@N0zoM1z0
N0zoM1z0 enabled auto-merge (squash) November 17, 2026 05:24
@N0zoM1z0
N0zoM1z0 disabled auto-merge November 17, 2026 05:30
Keep defaults in schema metadata and let help render one annotation. Preserve existing parity goldens and distinguish omitted from explicit defaults in CLI admission assertions.

Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)

Co-authored-by: gensokyo-dev <[email protected]>
Comment thread src/cli/contractCliDescription.ts Resolved
Render positional and option defaults through one metadata-aware owner. Verify keyed-archive help, preserve parity goldens, and assert the integrity-policy default as schema metadata.

Co-authored-by: gensokyo-dev <[email protected]>
@N0zoM1z0
N0zoM1z0 enabled auto-merge (squash) November 17, 2026 05:54
@N0zoM1z0
N0zoM1z0 disabled auto-merge November 17, 2026 06:05
Collect actual bounded keyword-search results until the complete advertised catalog is covered. Preserve pending queries across partial readiness and diagnostics, check duplicate schemas, and retain query provenance. Verify 256 schemas with the official Grok1.0.50 client and all native preflight cleanup regressions.

Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)

Co-authored-by: gensokyo-dev <[email protected]>
@N0zoM1z0
N0zoM1z0 enabled auto-merge (squash) November 17, 2026 06:16
@N0zoM1z0
N0zoM1z0 disabled auto-merge November 17, 2026 06:20
Preserve omitted caller input and verify the declared default without inventing a description.

Co-authored-by: gensokyo-dev <[email protected]>
@N0zoM1z0
N0zoM1z0 enabled auto-merge (squash) November 17, 2026 06:25
@N0zoM1z0
N0zoM1z0 disabled auto-merge November 17, 2026 06:43
gensokyo-dev and others added 2 commits November 17, 2026 07:43
Capture selected parameter names at canonical SDK validation and apply them to provider admission without retaining raw input trees. Reuse the application selection owner and verify omitted and explicit defaults through real MCP provider calls.

Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)

Co-authored-by: gensokyo-dev <[email protected]>
Compare equal CLI and MCP caller selections, including omitted controls and explicitly selected defaults, instead of requiring MCP to invent selections.

Co-authored-by: gensokyo-dev <[email protected]>
@N0zoM1z0
N0zoM1z0 enabled auto-merge (squash) November 17, 2026 07:59
@N0zoM1z0
N0zoM1z0 merged commit e9c72db into morluto:main Nov 17, 2026
58 checks passed
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks for merging this, @N0zoM1z0. Having inspect_elf_dependencies report DT_NEEDED order, RUNPATH tokens and GNU symbol versions offline should make ELF load-time questions a lot quicker to answer.

@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants