Skip to content
alexander-srcPublic

About

Static ELF64 scanner in safe Rust for Linux GLIBC/GLIBCXX floors, ABI tags, hardening, distro presets, diffing, and SARIF CI gates

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

83 Commits

Folders and files

Repository files navigation

bincompat

Static ELF64 scanner in zero-dependency safe Rust (#![forbid(unsafe_code)]) that checks Linux GLIBC/GLIBCXX symbol version floors, linker ABI tags, binary hardening flags (PIE, RELRO, NX, stack canaries, _FORTIFY_SOURCE, DT_TEXTREL), hardware security and ISA notes (CET, BTI, PAC, x86-64-v1..v4), and binary or directory regressions.

demo

Why

A binary built on a newer Linux distro can fail to start on older LTS servers because one call pulled in arc4random@GLIBC_2.36, the linker emitted GLIBC_ABI_DT_RELR (-z pack-relative-relocs), or compiler flags bumped GNU_PROPERTY_X86_ISA_1_NEEDED past x86-64-v2. Release builds can also silently drop -fPIE, -z now, -fstack-protector-strong, or -fcf-protection=full across toolchain updates.

bincompat parses PT_INTERP, PT_LOAD, PT_DYNAMIC (including section-header-stripped e_shoff == 0 binaries via DT_HASH/DT_GNU_HASH), PT_GNU_RELRO, PT_GNU_STACK, PT_GNU_PROPERTY/.note.gnu.property, SHT_DYNAMIC, SHT_DYNSYM, SHT_SYMTAB, SHT_GNU_VERSYM (masking the 0x8000 hidden bit), SHT_GNU_VERNEED, and SHT_GNU_VERDEF/DT_VERDEF directly, then exits non-zero in CI with the exact library, version tag, offending symbols, exported ABI break, or missing hardening flag.

Usage

Build from source (cargo build --release, offline, ~1.7 MB stripped) or download a prebuilt archive (with bincompat.1 manpage) from Releases:

# Inspect DT_NEEDED, RPATH/RUNPATH, hardening flags, GNU properties, symbol versions, and distro compatibility
bincompat scan /usr/bin/env
bincompat scan --all-symbols /usr/bin/env
bincompat scan -r ./dist --exclude='*.debug' --exclude='**/build/**'

# Gate a release binary, directory tree, or transitive DT_NEEDED dependency tree
bincompat check -r ./dist --config=bincompat.toml --exclude='tests/*' --fail-fast
bincompat check --tree ./build/app --target=rhel-8 -L ./dist/lib --fail-on-missing
bincompat check ./build/libfoo.so.1 --target=rhel-8 --exports-baseline=v1-exports.json --format=junit -o report.xml
bincompat check ./build/static-app --target=alpine
bincompat check ./build/app \
  --target=rhel-8 \
  --forbid-rpath \
  --forbid-textrel \
  --forbid-needed=libssl.so \
  --allow-needed=libc.so.6 \
  --ignore-weak-symbols \
  --allow-symbol=arc4random@GLIBC_2.36 \
  --require-hardening \
  --require-fortify \
  --require-cet \
  --max-x86-isa=v2

# Or specify explicit version ceilings (overrides --target regardless of flag order)
bincompat check ./build/app \
  --max-glibc=2.28 \
  --max-glibcxx=3.4.28 \
  --max-cxxabi=1.3.11 \
  --forbid-abi-tag=GLIBC_ABI_DT_RELR \
  --require-pie \
  --require-relro=full \
  --require-bti \
  --require-pac

# Generate an annotated starter bincompat.toml policy file
bincompat init --target=rhel-8
bincompat init --target=alpine --stdout

# Evaluate one binary, a directory tree, or a transitive --tree closure against all 15 Linux distro targets in one pass
bincompat matrix ./build/app
bincompat matrix -r ./dist --targets=centos-7,rhel-8,ubuntu-22.04,alpine --require-hardening --format=html -o matrix.html
bincompat matrix -r ./dist --format=csv -o matrix.csv
bincompat matrix --tree ./build/app -L ./dist/lib --format=json

# Fail CI if a new build or release directory adds dependencies, raises symbol floors, changes PT_INTERP, or drops hardening
bincompat diff ./releases/v1/app ./build/app --quiet
bincompat diff -r ./releases/v1 ./releases/v2 --exclude='*.debug' --ignore-rpath

# Diff against a saved JSON baseline snapshot without keeping old release binaries in git
bincompat scan ./releases/v1/app --format=json -o baseline.json
bincompat diff baseline.json ./build/app --format=html -o diff-report.html

# Statically resolve recursive DT_NEEDED dependencies without executing the binary (safe ldd alternative)
bincompat tree ./build/app --search-path=./dist/lib --fail-on-missing
bincompat tree ./rootfs/usr/bin/app --sysroot=./rootfs --format=html -o deps.html
bincompat tree ./build/app --format=dot -o deps.dot

# Inspect exported shared-library ABI symbols, DT_VERDEF inventory summaries, and ABI breaks in diff
bincompat exports ./build/libfoo.so.1 --filter='foo_*' --format=html --theme=dark -o exports.html
bincompat exports -r ./dist/lib --summary --format=csv -o exports-summary.csv
bincompat diff ./releases/v1/libfoo.so.1 ./build/libfoo.so.1

# Explain any of the 26 rule codes (BC001..BC016, BC101..BC107, BC201..BC203) with compiler/linker fix flags
bincompat explain BC002
bincompat explain --list --format=csv

# Emit native GitHub Actions workflow annotations directly in CI
bincompat check ./build/app --target=rhel-8 --format=github

# Write SARIF or a self-contained dark/light HTML report for CI artifacts
bincompat check ./build/app --target=rhel-8 --format=sarif -o bincompat.sarif
bincompat check -r ./dist --target=rhel-8 --format=html -o bincompat-report.html

# List built-in Linux distro baselines (text, json, markdown, github, html, or csv)
bincompat targets --format=csv

# Generate shell completions (bash, zsh, fish, powershell) or a Unix man(1) roff page
bincompat completions bash > /etc/bash_completion.d/bincompat
bincompat completions powershell > bincompat.ps1
bincompat man -o /usr/local/share/man/man1/bincompat.1

GitHub Actions

Use the root composite action.yml to download a SHA-256-verified release binary, run check, scan, diff, tree, or exports, emit workflow annotations, and write optional SARIF, HTML, or JSON reports:

- uses: alexander-src/bincompat@v0.10.0
  with:
    command: check
    paths: ./dist/app
    target: rhel-8
    tree: 'true'
    search-path: ./dist/lib
    fail-on-missing: 'true'
    require-hardening: 'true'
    sarif-file: bincompat.sarif
    html-file: bincompat.html

All report commands accept --format text|json|markdown|sarif|github|html|junit|csv (with RFC 4180 csv supported on scan, check, matrix, diff, exports, explain, and targets), -o / --out <FILE>, --flag=value syntax for long options, and -- before filenames starting with -. scan, check, matrix, diff, and exports accept -r / --recursive and repeatable --exclude <GLOB> (*, ?, **). matrix parses each ELF64 binary (single file, -r directory tree, or --tree transitive dependency closure) once and evaluates compatibility across all 15 built-in targets (or a subset via --targets <t1,t2,...>), honoring --config, --allow-symbol, --ignore-weak-symbols, and hardening flags, reporting per-binary and overall supported_targets, oldest_glibc_target, and blocking BC001..BC016 rules in text, json, markdown, dark/light html (--theme auto|dark|light), or RFC 4180 csv. init [PATH] writes an annotated starter bincompat.toml (default ./bincompat.toml, --target <DISTRO>, --force to overwrite, --stdout to preview). Passing --tree to check (with optional -L / --search-path, --sysroot, --use-env, --no-default-paths, --max-depth, and --fail-on-missing) resolves every unique transitive DT_NEEDED shared library and enforces the policy across the full dependency closure; passing --exports-baseline <FILE> (or exports_baseline in bincompat.toml) adds BC201..BC203 DSO ABI-break gating against a saved exports or scan JSON snapshot (matching by SONAME first, then filename). diff accepts live ELF64 binaries, directories, or saved scan/exports --format json snapshots (single or batch) on either side, audits exported shared-library ABI breaks (BC201..BC203) automatically when both sides are DSOs (or with --check-exports, skippable via --ignore-exports), and supports --ignore-needed, --ignore-rpath, --ignore-interp, and --ignore-hardening. exports lists SONAMEs, DT_VERDEF parent version chains, and exported symbols (@@VER, @VER, unversioned) with optional --filter <GLOB>, --format text|json|html|csv, and --theme auto|dark|light; passing --summary aggregates exported ABI counts by version tag, symbol type, binding, and visibility across one or more binaries in text, json, markdown, or csv. tree resolves recursive DT_NEEDED libraries statically (expanding $ORIGIN and $LIB, inheriting DT_RPATH, checking -L / --search-path, opt-in --use-env LD_LIBRARY_PATH, DT_RUNPATH, and --sysroot system paths while verifying matching ELF64 class and e_machine), supports --no-default-paths, --max-depth, --fail-on-missing, and --format text|json|markdown|html|dot (Graphviz DOT digraphs), and summarizes merged transitive ABI floors and distro compatibility. scan and check accept --all-symbols and --summary (aggregating fleet-wide arch/kind/GLIBC/GLIBCXX histograms, pass/warn/fail totals, rule counts, and top offending symbols/DSOs in text, json, markdown, or csv across single, -r, and --tree runs), and check, diff, and tree accept -q / --quiet. SARIF 2.1.0, JUnit XML, and HTML findings emit rules BC001..BC016 and BC201..BC203 for check and BC101..BC107 / BC201..BC203 for diff; run bincompat explain <RULE_ID> or bincompat explain --list for ELF surface details and exact gcc/clang/rustc/ld fixes.

Built-in --target presets: centos-7 (manylinux2014, rhel-7), amazon-linux-2 (al2), rhel-8 (rocky-8, manylinux_2_28), ubuntu-20.04, debian-11, rhel-9, amazon-linux-2023 (al2023), ubuntu-22.04 (manylinux_2_35), debian-12 (manylinux_2_36), ubuntu-24.04, rhel-10 (rocky-10), debian-13, fedora-42, ubuntu-26.04, and alpine (musl). Pass -c / --config <FILE> on check to load policy rules (target, max_*, forbid_*, allow_*, require_*, ignore_weak_symbols, allow_symbols, exclude, exports_baseline, [max_versions]) from a TOML file; CLI flags override config settings.

Exit codes: 0 pass, 1 policy violation, diff regression, or tree --fail-on-missing unresolved library, 2 usage, I/O, or malformed ELF error.

Limitations

  • ELF64 only (no ELF32, PE, or Mach-O).
  • Static metadata scan only: does not catch symbols resolved at runtime via dlopen/dlsym.
  • Built-in distro presets check GLIBC, GLIBCXX, DT_RELR, and dynamic musl vs glibc ABI compatibility; non-glibc third-party library sonames should be checked with --max-version, --forbid-needed, --allow-needed, or diff.

License

MIT. See LICENSE.

About

Static ELF64 scanner in safe Rust for Linux GLIBC/GLIBCXX floors, ABI tags, hardening, distro presets, diffing, and SARIF CI gates

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages