Skip to content

fix(elf): detect imports via SHN_UNDEF instead of st_value (fixes #419)#534

Open
wyf027 wants to merge 2 commits into
m4b:masterfrom
wyf027:fix/mips-is-import-shndx-419
Open

fix(elf): detect imports via SHN_UNDEF instead of st_value (fixes #419)#534
wyf027 wants to merge 2 commits into
m4b:masterfrom
wyf027:fix/mips-is-import-shndx-419

Conversation

@wyf027

@wyf027 wyf027 commented May 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Change Sym::is_import() to treat symbols with st_shndx == SHN_UNDEF as imports instead of relying on st_value == 0.
  • Update the standalone is_import() helper to take shndx rather than st_value.
  • Add unit tests covering MIPS-style undefined globals with non-zero st_value.

Fixes #419.

On MIPS ELF, undefined dynamic symbols (e.g. memcpy@GLIBC_2.0) can have a non-zero st_value while still being imports. The previous heuristic incorrectly classified them as defined exports.

As suggested by @philipc in the issue, checking st_shndx == SHN_UNDEF is the reliable indicator.

Test plan

  • cargo test is_import
  • cargo test --lib

wyf027 and others added 2 commits May 25, 2026 15:27
On MIPS, undefined dynamic symbols can have a non-zero st_value while
still referencing SHN_UNDEF. Using st_shndx fixes false positives when
filtering exported symbols (fixes m4b#419).

Co-authored-by: Cursor <cursoragent@cursor.com>
@wyf027

wyf027 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Resolved the rustfmt CI failure in commit 2b42a39 by applying the formatter to src/elf/sym.rs. Local verification: cargo fmt -- --check.

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.

is_import is wrong on MIPS ELF

1 participant