Skip to main content

ELF Checker

ELF Checker visualises and checks where ELF sections are located in different types of binaries (ELF files, stripped ELF files, binary files).

It answers the questions that come up when a linker script, a post-processing step, or a flashing tool moves things around:

  • Which sections does each ELF file describe, at which address, length, and alignment?
  • Do the sections an ELF file describes match the bytes of a raw binary image at the addresses the ELF file expects?
  • Which gaps in a raw binary are padding, and is that padding really zero?
  • Which section differs between two builds, and where does the difference start?

Every run writes a text table to standard output and a JSON report to report.json, including SHA-256 hashes of section, binary, and padding data, so the same run can be read by a person and consumed by CI.

Installation

The latest release is published on PyPI. Install it with pipx, which keeps the tool in its own virtual environment:

pipx install elf-checker

pipx is packaged as pipx or python-pipx by most distributions. Plain pip works too, inside a virtual environment:

python3 -m venv .venv
. .venv/bin/activate
pip install elf-checker

ELF Checker requires Python 3.11 or newer.

Quick start

Inspect an ELF file

elf-checker -e test/artifacts/sparc-rtems6-qual-runner.elf
┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃                 ┃ ...parc-rtems6-qual-runner.el ┃                    ┃                  ┃        ┃
┃ Section Name    ┃ f                             ┃ Type               ┃ Flags            ┃ Errors ┃
┡━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│                 │ Address ┃   Length ┃ Alignme… │                    │                  │        │
│ ━━━━━━━━━━━━━━━ │ ━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━ │ ━━━━━━━━━━━━━━━━━━ │ ━━━━━━━━━━━━━━━━ │ ━━━━━━ │
│ .comment        │ 0x0     │     0x63 │      0x1 │ SHT_PROGBITS       │ MERGE, STRINGS   │ -      │
│ .debug_abbrev   │ 0x0     │  0x245C4 │      0x1 │ SHT_PROGBITS       │ -                │ -      │
│ .debug_aranges  │ 0x0     │   0x2930 │      0x8 │ SHT_PROGBITS       │ -                │ -      │
│ …               │         │          │          │                    │                  │        │
│ .data           │ 0x2A640 │   0x3C80 │      0x8 │ SHT_PROGBITS       │ ALLOC, WRITE     │ -      │
│ .bss            │ 0x2E2C0 │ 0x410C30 │     0x40 │ SHT_NOBITS         │ ALLOC, WRITE     │ -      │
└─────────────────┴───────────────────────────────┴────────────────────┴──────────────────┴────────┘

Compare ELF files side by side

Pass more than one ELF file to the same option. A section that is absent from an input is kept and reported with placeholders, which is what makes the comparison of an unstripped and a stripped ELF file readable:

elf-checker \
  -e test/artifacts/sparc-rtems6-qual-runner.elf \
  test/artifacts/sparc-rtems6-qual-runner-stripped.elf
┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃                 ┃ ...parc-rtems6-qual-runn ┃ ...s6-qual-runner-stripp ┃                    ┃                  ┃         ┃
┃ Section Name    ┃ er.elf                   ┃ ed.elf                   ┃ Type               ┃ Flags            ┃ Errors  ┃
┡━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━┩
│                 │ Addre… ┃ Length ┃ Align… │ Addre… ┃ Length ┃ Align… │                    │                  │         │
│ ━━━━━━━━━━━━━━━ │ ━━━━━━━╇━━━━━━━━╇━━━━━━━ │ ━━━━━━━╇━━━━━━━━╇━━━━━━━ │ ━━━━━━━━━━━━━━━━━━ │ ━━━━━━━━━━━━━━━━ │ ━━━━━━━ │
│ .comment        │ 0x0    │   0x63 │    0x1 │ 0x0    │   0x63 │    0x1 │ SHT_PROGBITS       │ MERGE, STRINGS   │ -       │
│ .debug_abbrev   │ 0x0    │ 0x245… │    0x1 │ -      │      - │      - │ SHT_PROGBITS       │ -                │ -       │
│ .debug_aranges  │ 0x0    │ 0x2930 │    0x8 │ -      │      - │      - │ SHT_PROGBITS       │ -                │ -       │
│ …               │        │        │        │        │        │        │                    │                  │         │
│ .data           │ 0x2A6… │ 0x3C80 │    0x8 │ 0x2A6… │ 0x3C80 │    0x8 │ SHT_PROGBITS       │ ALLOC, WRITE     │ -       │
│ .bss            │ 0x2E2… │ 0x410… │   0x40 │ 0x2E2… │ 0x410… │   0x40 │ SHT_NOBITS         │ ALLOC, WRITE     │ -       │
└─────────────────┴──────────────────────────┴──────────────────────────┴────────────────────┴──────────────────┴─────────┘

Stripping removes section names from .shstrtab, so a data mismatch there is expected: pass --ignore-sections .shstrtab together with --fail-on-errors to keep the mismatch visible in the reports without failing on it.

Compare an ELF file with a raw binary

Select the sections that are present in the raw image. ELF Checker maps their addresses onto file offsets, compares the bytes, and inspects the gaps between them:

elf-checker \
  -e test/artifacts/sparc-rtems6-qual-runner.elf \
  -b test/artifacts/sparc-rtems6-qual-runner.bin \
  -j .text .data
│ .text           │ 0x0     │   0x2… │     0x20 │ SHT_PROGBITS       │ ALLOC, EXECINSTR │ 0x0     │  0x2…   │     0x20 │ -        │
│ .rtemsstack     │ 0x28640 │ 0x2000 │     0x40 │ SHT_NOBITS         │ ALLOC, WRITE     │ -       │       - │        - │ -        │
│ padding         │ -       │      - │        - │ -                  │ -                │ 0x285C0 │  0x2080 │        - │ Not Zero │
│ .data           │ 0x2A640 │ 0x3C80 │      0x8 │ SHT_PROGBITS       │ ALLOC, WRITE     │ 0x2A640 │  0x3C80 │      0x8 │ -        │

The padding row reports bytes in the binary that no selected section claims, with its offset, length, and a Not Zero error when the padding is not filled with zeros. Use --binary-base when offset zero of the image stands for an address other than the lowest selected section.

Machine-readable report

--json-output writes the same data as JSON. Each ELF input is keyed by its resolved absolute path:

{
  "file_info": {
    "/home/build/sparc-rtems6-qual-runner.elf": [
      {
        "data_type": "elf_section",
        "address": 0,
        "size": 99,
        "data_sha256": "523dffd99785d2e7fc7bdcc69f4f85e737378c3f6588f3e020db31e34481c319",
        "name": ".comment",
        "alignment": 1,
        "type": "SHT_PROGBITS",
        "flags": "MERGE, STRINGS"
      }
    ]
  },
  "errors": []
}

Command-line options

Option Purpose
-e, --elffile One or more ELF files to inspect. Required.
-b, --binfile Raw binary image to compare with the selected sections.
-j, --only-section Sections expected in the raw binary. Needs --binfile.
--binary-base Address that maps to offset zero in the binary.
--strict-sections Report a section missing from one of the ELF inputs as an error.
--fail-on-errors Exit with status 1 when the report has non-ignored errors.
--ignore-sections Section names whose errors do not affect --fail-on-errors.
--json-output Path of the JSON report. Defaults to report.json.
-v, --version Print the version and exit.

The command-line reference documents every option, the report format, and worked CI examples.

Exit status

Status Meaning
0 The comparison completed. Mismatches do not change the status unless --fail-on-errors is given.
1 --fail-on-errors was given and the report contains non-ignored comparison or padding errors.
2 Invalid arguments, an unreadable input, or an ELF input the checker refuses to interpret.

Input validation

An ELF input that cannot be interpreted is rejected with status 2, a diagnostic naming the affected file and field on standard error, and no JSON report. The tool validates the ELF identification, the section header table and ELF extended section numbering, the section name string table, the stored range of every section, section links, the program header table, and the file range of every program segment. See Input validation for the full list and for what is deliberately outside the scope of the tool: ELF Checker is a section comparison tool, not a general ELF validator.

License

The ELF Checker source code implemented by Celeres is licensed under the Mozilla Public License 2.0, identified by the SPDX expression MPL-2.0. Third-party libraries remain subject to their own license terms.

Development

Setup for the development environment, the test suite, the pre-commit hooks, and the documentation build are described in CONTRIBUTING.md.

Metadata

Release files for elf-checker 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for elf-checker 2.0.0
File Size Uploaded Provenance Actions
elf_checker-2.0.0.tar.gz 2.6 MB Without provenance Details for elf_checker-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for elf-checker 2.0.0
File Interpreter ABI Platform Actions
elf_checker-2.0.0-py3-none-any.whl Python 3 none any Details for elf_checker-2.0.0-py3-none-any.whl

Total release size: 2.7 MB

Release files / elf_checker-2.0.0.tar.gz

Download URL elf_checker-2.0.0.tar.gz
Size 2.6 MB
Tags Source
SHA-256 checksum
How to use checksums
c25963d3aa8469fd5a691ed09a07febc4bf4828fcfe317786d0a091b11fad7c9
BLAKE2b-256 checksum
How to use checksums
ad091874b11a962e34b6f3738dda46bdbdb4d4ce8786b5e4df2dbf9db1bb7abd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.11.2 Linux/7.0.2-2-pve

Release files / elf_checker-2.0.0-py3-none-any.whl

Download URL elf_checker-2.0.0-py3-none-any.whl
Size 27.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
358d7a565ba6aec05e7f1d742ed7497cde73e171c10d5f548d102c700961a958
BLAKE2b-256 checksum
How to use checksums
e882ed1bbfd6a1bf387d4239e933d4fc8a6acb950e95e76c5e8ff8390f20df43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.11.2 Linux/7.0.2-2-pve

Security for elf-checker 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page