Repository navigation
Read ELF metadata without elftools - #24423
Merged
Merged
Conversation
- `ELFShim::Metadata` built a `PatchELF::Patcher`, and so an elftools `ELFFile` that parses every header through BinData, to read a few fields from the program headers and the dynamic section. Read them with `String#unpack` instead: the linkage check, relocation and `brew bottle` read them for every ELF file in a keg. - Return exactly what patchelf.rb returned, string encodings included, and leave anything unusual, such as a truncated file, to patchelf.rb as before. - Reading metadata no longer loads elftools, BinData and patchelf.rb.
Contributor
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Direct ELF parsing Library/Homebrew/os/linux/elf.rb |
Adds format constants, a fields structure and a direct reader for ELF headers, program headers and dynamic-section data. Bounded readers handle fields and null-terminated strings. |
Fallback selection and validation Library/Homebrew/os/linux/elf.rb, Library/Homebrew/test/os/linux/pathname_spec.rb |
Metadata initialisation selects fields from the direct reader or patchelf. PIE and NODEFLIB checks use local flag constants. Specs cover fallback selection, 32-bit little-endian and 64-bit big-endian files, and files without program headers. |
Merge Risk: 
Minimal · up to 032cb
-
No actionable issue remains from this review; the PR is ready for normal merge checks.
Pre-merge checks: 
4
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
8 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELFShim::Metadatabuilt aPatchELF::Patcher, and so an elftoolsELFFilethat parses every header through BinData, to read a few fields from the program headers and the dynamic section. Read them withString#unpackinstead: the linkage check, relocation andbrew bottleread them for every ELF file in a keg.brew benchmarkresults.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?Opus 5.5 xhigh with manual review and testing. The new reader was compared with
main's on 3,363 ELF files (arm64 and x86_64 bottles, system libraries and 32-bit and big-endian builds) and on 19,929 truncated or overwritten copies of 1,418 of them: every value, string encoding and exception matched.Details
Fedora 44 aarch64 VM,
hyperfine -Nwithbrew benchmark's environment, bottles cached.brew linkage util-linux($(brew --cache)/linkage.jsonremoved before each run, 20 runs)maina687be2brew linkage perl($(brew --cache)/linkage.jsonremoved before each run, 20 runs)maina687be2brew install util-linux(one pour, dependencies installed, 10 runs)maina687be2brew install python@3.15(one pour, dependencies installed, 10 runs)maina687be2brew install wget(one pour, dependencies installed, 20 runs)maina687be2brew install jq wget git tmux htop python3(39 bottles poured, warm cache, 10 runs)maina687be2Reading the metadata of 3,354 ELF files through
ELFShimalone takes 2,295 ms onmainand 182 ms on the branch (12.6 ± 0.6×). Pours gain less because relocation still rewrites each file through patchelf.rb.