Repository navigation
perf(viv): optimize elf symbol resolution - #3182
Open
tryhard-26 wants to merge 1 commit into
Open
tryhard-26 wants to merge 1 commit into
tryhard-26 wants to merge 1 commit into
Conversation
tryhard-26
force-pushed
the
perf/viv-elf-symbol-lookup-and-type-validation
branch
2 times, most recently
from
September 26, 2026 03:35
b974f17 to
0232db1
Compare
Vishrut2403
approved these changes
Sep 26, 2026
Author
williballenthin
requested changes
Sep 27, 2026
| STT_FUNC = 0x2 | ||
| if sym_value == fh.address and sym_info & STT_FUNC != 0: | ||
| yield FunctionName(sym_name), fh.address | ||
| funcs = get_elf_symbol_functions(fh.ctx["cache"], fh.inner.vw.parsedbin) |
Collaborator
There was a problem hiding this comment.
i'd prefer to split fetching the items from setting the cache, otherwise looks good!
tryhard-26
force-pushed
the
perf/viv-elf-symbol-lookup-and-type-validation
branch
from
September 28, 2026 04:42
0232db1 to
8e88e01
Compare
Author
|
btw @williballenthin heads up, this will trip the |
Collaborator
|
good point, thanks for calling that out. would you please open that PR @tryhard-26? |
tryhard-26
force-pushed
the
perf/viv-elf-symbol-lookup-and-type-validation
branch
from
September 28, 2026 13:09
8e88e01 to
122f201
Compare
tryhard-26
added a commit
to tryhard-26/capa-testfiles
that referenced
this pull request
Sep 28, 2026
mandiant/capa#3182 checks elf symbol types with (st_info & 0xf) in (STT_FUNC, STT_GNU_IFUNC) instead of st_info & 0x2, which wrongly let unnamed STT_SECTION (type 3) symbols through. this drops 5 empty-name false positives from the snapshot: api("") at 0x4088e0 and function-name("") at 0x4016d8, 0x4016f0, 0x401c50 and 0x408988. no other features change.
tryhard-26
force-pushed
the
perf/viv-elf-symbol-lookup-and-type-validation
branch
from
September 28, 2026 13:11
122f201 to
5fd2901
Compare
Author
This branch has not been deployed
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.
in vivisect elf feature extraction (
viv/function.pyandviv/insn.py), symbol types were checked usingsym_info & 0x2 != 0in a linear loop over all symbols on every call instruction and function. because elf encodes symbol types in the lower 4 bits ofst_infoas an enum not a bitmask, testing bit 1 falsely treated section headers (0x3) and thread-local storage variables (0x6) as callable functions and apis, since both have bit 1 set. repeatedly re-scanning the entire symbol table and callingget_name()on every instruction also created a quadratic bottleneck, causing over 2.3 million redundant string decodings across small test binaries.this pr adds
get_elf_symbol_functionsinviv.helpersto validate symbol types using(symbol.info & 0xf) in (2, 10)and pre-indexes callable symbols by address into the workspace cache. this converts instruction and function symbol lookups into o(1) dictionary lookups, safely skips malformed symbol names instead of crashing, and stops non-function symbols from leaking into extracted features.benchmarked against 5 elf fixtures already in
tests/data:call counts and false positive counts above are deterministic, timings are single-run on my machine [macbook air m4 16gigs] and will vary by environment.
all tests pass, new unit tests covering symbol type filtering, corrupt symbol recovery, and caching have been added
ruff check,ruff format, anddeptryall pass cleanly.no linked gh issue as such
used gemini a bit to help debug the type masking logic
idk whether changelog update is needed or not
checklist