Skip to content

containertool: Add basic ELF file type detection #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 26, 2025

Conversation

euanh
Copy link
Collaborator

@euanh euanh commented Feb 25, 2025

Motivation

The container's architecture metadata field should match the architecture of the executable it contains. The plugin can't currently tell which architecture the SDK targets, but containertool can infer the architecture by reading the ELF headers.

Modifications

  • Adds basic ELF header reader. Reading the whole ELF header is not required - the necessary information is provided by the first few fields of the header.
  • Changes containertool to use the detected architecture unless overridden by command line flags or environment variables.

Result

Adding ELF detection reduces the risk of building a mismatched container image, where the architecture of the packaged binary does not match the architecture of the underlying Linux distribution.

Test Plan

  • New unit tests exercise ELF header parsing
  • A new integration test checks that containertool selects the correct base image architecture for different cross-compiled binaries
  • All previous tests continue to pass

Fixes #49

@euanh euanh added kind/enhancement New feature or request semver/minor Adds new public API. area/interoperability Improvements to compatibility with other systems. labels Feb 25, 2025
@euanh euanh force-pushed the feature/elf-detection branch 7 times, most recently from 66c1923 to 5fb809f Compare February 26, 2025 12:31
@euanh euanh marked this pull request as ready for review February 26, 2025 12:49
@euanh euanh force-pushed the feature/elf-detection branch 2 times, most recently from 9baa59a to 5ebe3e0 Compare February 26, 2025 14:21
@euanh euanh force-pushed the feature/elf-detection branch from 5ebe3e0 to bc49ef9 Compare February 26, 2025 14:27
@euanh euanh merged commit 42fa39e into apple:main Feb 26, 2025
19 checks passed
@euanh euanh deleted the feature/elf-detection branch February 26, 2025 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/interoperability Improvements to compatibility with other systems. kind/enhancement New feature or request semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

containertool should detect the executable's architecture and set the container's architecture automatically
1 participant