Skip to content

Fixed module_converter_elf32 parsing on 64 bit hosts - #840

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

bhargavaa-g wants to merge 11 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>
@fdesbiens

Copy link
Copy Markdown
Contributor

Hi @bhargavaa-g.

I am on the road this week. I will do my best to review in the coming days or next week at the latest. I authorised the CI run, so please keep an eye on it.

@fdesbiens fdesbiens self-assigned this Nov 18, 2026
The Cortex-A35 and ELF32 changes added tests at the same location in
the Module Manager CMake file.

Kept both groups so the converter tests and all four Cortex-A35 port
variants register together.

The merged diff passed git diff --check.

Assisted-by: Codex (GPT-6.2-Sol) <noreply@openai.com>
The converter regression targets inherited the kernel suite's 32-bit
flags, and allocation failures ran through separate executables whose
coverage was not recorded.

Built both converters at native LP64 width and injected allocation and
I/O failures through their registered tests. Kept bounds checks at the
file reads and decoded complete records without redundant checks on
private buffers. Reject ELF files with no section headers before opening
the output.

GCC 14 passed all 20 converter cases in the default and trace profiles,
with 100% line and branch coverage for the changed production code. The
default Linux suite passed 136/136 tests and the trace Module Manager
and converter tests passed 18/18.

Assisted-by: Codex (GPT-6.2-Sol) <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.

3 participants