-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
nixos/binfmt: Add QEMU wrapper to preserve argv[0] #143060
Conversation
Dup of #118926 |
Whoops, wasn't aware of that PR and GitHub wasn't returning good results for my searches. However, I still think the implementation here is more robust and only affects QEMU (not wine, for example). |
bc969b5
to
aed1cf6
Compare
I implemented the suggestion from @oxalica in #115406 (comment) and coreutils can now be built under binfmt. I did a |
Also we should update the PR title. |
aed1cf6
to
8631fff
Compare
5c65b40
to
724d53c
Compare
724d53c
to
463294c
Compare
Looks like To reproduce:
|
c45d694
to
5d0aa2a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just need more docs. It works pretty fine now.
I've started a build of riscv64 coreutils
with binfmt from this PR. Hope it could pass tests.
riscv64-linux |
5d0aa2a
to
9e5d0a9
Compare
True to your word this does appear to fix the
|
@ofborg test systemd-binfmt (I want to see what happens when this runs on an aarch64 machine) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests successfully run against rebased master.
LGTM
Motivation for this change
This PR enables argv[0] preservation for the QEMU binfmt-misc rules generated by
boot.binfmt.emulatedSystems
. It allows certain packages that rely on argv[0] in their build process (e.g., coreutils for its tests) to correctly build under binfmt.Traditionally, the emulator invoked by
binfmt-misc
doesn't know what the original argv[0] is when running an executable, because only the absolute path to the foreign executable is passed. Currently, the emulator will simply use the full path as argv[0]. This leads to problems with multi-call executables as well as diff-based test methodologies used in various packages. For example, coreutils relies on output comparison in many test cases:binfmt-misc
now has the "P" flag that, when enabled, will add an extra argument after the absolute path to the foreign binary containing the original argv[0]. However, this also means that CLI compatibility with existing emulator executables is broken. SUSE has been carrying a patch since 2011 to add-binfmt
wrappers that translate the new arguments into ones that regular QEMU accepts (-0
for overriding argv[0]). There have been attempts to resolve this issue upstream, but so far there seems to be no consensus.This PR adds a statically-linked wrapper for QEMU that translates the arguments. It's possible to rewrite the arguments in the wrapper script that we use (#118926), but that still leaves some remaining issues (e.g., extraneous output when setting LD_PRELOAD).
Tested by building coreutils for riscv64-linux on x86_64-linux under binfmt (before, after).
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)