CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
118 lines
2.9 KiB
Python
118 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
ELF verification CLI tool.
|
|
|
|
Validates ELF binaries using both internal structural checks and external tools
|
|
(readelf, strip, gdb, ldd).
|
|
|
|
Usage:
|
|
python -m rocm_kpack.tools.verify_elf <binary> [--verbose]
|
|
"""
|
|
|
|
import argparse
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from rocm_kpack.elf import (
|
|
verify_all,
|
|
verify_with_readelf,
|
|
verify_with_strip,
|
|
verify_with_gdb,
|
|
verify_with_ldd,
|
|
ElfVerifier,
|
|
VerificationResult,
|
|
)
|
|
|
|
|
|
def verify_binary(binary: Path, verbose: bool = False) -> VerificationResult:
|
|
"""Run all verification checks on a binary.
|
|
|
|
Args:
|
|
binary: Path to ELF binary
|
|
verbose: Whether to show warnings
|
|
|
|
Returns:
|
|
Combined VerificationResult
|
|
"""
|
|
print(f"Verifying: {binary}")
|
|
print("-" * 60)
|
|
|
|
result = VerificationResult()
|
|
|
|
# Internal structural checks
|
|
print(" internal: ", end="")
|
|
internal = ElfVerifier.verify(binary)
|
|
result.merge(internal)
|
|
print("PASS" if internal.passed else "FAIL")
|
|
if internal.errors:
|
|
for e in internal.errors:
|
|
print(f" ERROR: {e}")
|
|
if verbose and internal.warnings:
|
|
for w in internal.warnings:
|
|
print(f" WARN: {w}")
|
|
|
|
# External tool checks
|
|
tools = [
|
|
("readelf", verify_with_readelf),
|
|
("strip", verify_with_strip),
|
|
("gdb", verify_with_gdb),
|
|
("ldd", verify_with_ldd),
|
|
]
|
|
|
|
for name, func in tools:
|
|
print(f" {name}: ", end="")
|
|
if name == "strip":
|
|
tool_result = func(binary, tmp_dir=None)
|
|
else:
|
|
tool_result = func(binary)
|
|
result.merge(tool_result)
|
|
print("PASS" if tool_result.passed else "FAIL")
|
|
|
|
if tool_result.errors:
|
|
for e in tool_result.errors:
|
|
print(f" ERROR: {e}")
|
|
if verbose and tool_result.warnings:
|
|
for w in tool_result.warnings:
|
|
print(f" WARN: {w}")
|
|
|
|
print("-" * 60)
|
|
overall = "PASSED" if result.passed else "FAILED"
|
|
print(f"Overall: {overall}")
|
|
|
|
if result.errors:
|
|
print("\nAll errors:")
|
|
for e in result.errors:
|
|
print(f" {e}")
|
|
|
|
if verbose and result.warnings:
|
|
print("\nAll warnings:")
|
|
for w in result.warnings:
|
|
print(f" {w}")
|
|
|
|
return result
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="Verify ELF binary integrity using structural checks and external tools"
|
|
)
|
|
parser.add_argument("binary", type=Path, help="Path to ELF binary to verify")
|
|
parser.add_argument(
|
|
"--verbose",
|
|
"-v",
|
|
action="store_true",
|
|
help="Show verbose output including warnings",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
if not args.binary.exists():
|
|
print(f"Error: {args.binary} does not exist", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
result = verify_binary(args.binary, args.verbose)
|
|
sys.exit(0 if result.passed else 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|