Repository navigation
scripts: verify rust/libmacros.so ELF architecture compatibility - #872
Open
thomas7475 wants to merge 1 commit into
Open
thomas7475 wants to merge 1 commit into
thomas7475 wants to merge 1 commit into
Conversation
thomas7475
force-pushed
the
test-script
branch
3 times, most recently
from
August 23, 2026 20:04
8828c85 to
afce2b8
Compare
thomas7475
force-pushed
the
test-script
branch
2 times, most recently
from
August 31, 2026 14:27
55a3d52 to
8673013
Compare
thomas7475
force-pushed
the
test-script
branch
from
September 21, 2026 16:15
8673013 to
4a33841
Compare
When building the bcachefs DKMS module on a system where Rust is enabled, rustc dynamically loads the procedural macro shared library (rust/libmacros.so) directly into its host process at compile time. If kernel headers or prebuilt kernel artifacts were compiled on a host with a different architecture (e.g. cross-compiled on x86_64 and installed on an aarch64 system), rustc on the target host cannot load the alien libmacros.so. This causes the DKMS build to fall back to the C-only module. Add an ELF architecture compatibility check to rust-is-available-dkms.sh: - Add helper function elf_arch_name() to map ELF class, endianness, and e_machine bytes to human-readable architecture names (x86_64, aarch64, arm, riscv, etc.). - Inspect the ELF header of a native host binary ($HOSTRUSTC, $RUSTC, or /bin/sh) using od and compare its class, endianness, and machine type against rust/libmacros.so. - If a mismatch is found, trigger skip() with a clear diagnostic: "host architecture ($host_arch) does not match rust/libmacros.so ($macro_arch); native kernel headers required" This allows DKMS to catch cross-architecture header mismatches early and gracefully fall back to building the C-only bcachefs module while logging the exact reason in the build log. # Conflicts: # fs/scripts/rust-is-available-dkms.sh
thomas7475
force-pushed
the
test-script
branch
from
October 9, 2026 08:55
4a33841 to
d52ca1f
Compare
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.
Summary
Adds an ELF architecture compatibility check for
rust/libmacros.soto the DKMS Rust availability script (rust-is-available-dkms.sh).Problem
When building out-of-tree Rust modules via DKMS,
rustcdynamically loads procedural macro shared libraries (rust/libmacros.so) directly into its host process at compile time viadlopen().If kernel headers or prebuilt kernel artifacts were cross-compiled on a different host architecture (e.g., compiled on
x86_64and installed on anaarch64target system), hostrustccannot load the foreign.so. This causes DKMS builds to fail deep insiderustcwith cryptic dynamic linking or crate loading errors (E0463).This test catches architecture mismatches early and gracefully falls back to building the C-only module, logging the exact cause in the DKMS build log.
Implementation Details
get_elf_arch(): Reads the first 20 bytes of an ELF header in a single POSIXodcall, extracting ELF class, endianness, ande_machine(x86_64,aarch64,arm,riscv,loongarch64, etc.).get_host_arch(): Reusesget_elf_arch()on native host binaries ($HOSTRUSTC,$RUSTC,$CC, or/bin/sh). This guarantees 1:1 string parity between the running toolchain andlibmacros.so, preventing false positives on 32-bit platforms (armvsarmv7l) or in chroot/container environments.$host_arch != $macro_arch),skip()is triggered with a clear diagnostic: