Skip to content

Fixed module_converter_elf32 parsing on 64 bit hosts - #840

Open
bhargavaa-g wants to merge 9 commits into
eclipse-threadx:devfrom
bhargavaa-g:issue-585-elf32
Open

bhargavaa-g wants to merge 9 commits into
eclipse-threadx:devfrom
bhargavaa-g:issue-585-elf32

Conversation

@bhargavaa-g

Copy link
Copy Markdown

Summary

Fixes ELF32 parsing in the ThreadX module conversion utilities on 64-bit hosts.

Problem

The module conversion utilities read ELF metadata by copying file bytes directly into C structures. Some ELF32 fields were represented with host-dependent types such as unsigned long. On LP64 systems, these types can be wider than the corresponding ELF32 fields, so the in-memory structure no longer matches the file’s layout. As a result, the converters can read fields from incorrect offsets and fail to process ELF32 input correctly.

Changes

  • Added shared ELF32 decoding helpers and fixed-width records using uint8_t, uint16_t, and uint32_t.
  • Decode supported little-endian ELF header and section-header fields explicitly from raw bytes.
  • Validate the ELF identification, supported class and encoding, version fields, and expected record sizes.
  • Check requested reads against the input file size before seeking and reading.
  • Open the output only after validating the input header, and clean up allocated buffers and open files on error paths.
  • Keep the existing section processing and binary/C-array output flow for valid input.
  • Use C99-compatible compile-time size checks.
  • Add regression coverage for valid inputs, malformed headers, truncated and out-of-range tables, invalid indexes, file errors, and allocation failures.
  • Register the converter regression test with CTest using resolved executable paths.

Scope and limitations

The converters support ELF32 little-endian input. The e_machine field is decoded, but the implementation does not currently reject files based on target-machine value. The change does not modify ThreadX runtime or scheduler behavior.

VERIFICATION

  • Ran the full ThreadX test suite with scripts/test_tx.sh: [0 failed].
  • Ran the ELF converter regression test in the trace_build configuration.
  • The regression suite includes an independent readelf comparison: [passed].

PR checklist

  • Updated function header with a short description and version number
  • Added test case for bug fix or new feature
  • Validated on real hardware

The converters are host-side tools, so real-hardware validation is not applicable. They were tested with a host toolchain.

Related issue

Fixes #585

aniketkb28 and others added 9 commits November 8, 2026 12:37
Issue-specific tags described the task rather than the code.
Removed those tags while keeping the comments focused on behavior.

Assisted-by: Codex (GPT-6) <noreply@openai.com>
CTest passed the unexpanded TARGET_FILE expressions to the Python
test driver. Updated the test registration to use NAME and COMMAND.
The focused CMake harness passed 16 tests; the optional readelf check
was skipped because readelf was unavailable.

Assisted-by: Codex (GPT-6) <noreply@openai.com>
Added short descriptions and release identifiers to the modified
converter functions and ELF decoding helpers.
git diff --check passed; no tests were rerun because these are comment-only changes.

Assisted-by: Codex (GPT-6) <noreply@openai.com>

This branch has not been deployed

No deployments
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.

2 participants