Skip to content
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

Processes started by cross emulator can't exec other binaries (?) #119885

Open
sternenseemann opened this issue Apr 19, 2021 · 4 comments
Open

Processes started by cross emulator can't exec other binaries (?) #119885

sternenseemann opened this issue Apr 19, 2021 · 4 comments
Labels
0.kind: bug 6.topic: cross-compilation Building packages on a different sort platform than than they will be run on

Comments

@sternenseemann
Copy link
Member

Describe the bug

Consider the following expression where koka is a shell script created using wrapProgram:

{ pkgs ? import <nixpkgs> {} }:

with pkgs;

let
  kokaHelloWorld = writeText "hello.kk" ''
    fun main() {
      println("Hello, World!");
    }
  '';

  crossTest = crossPkgs:
    crossPkgs.runCommand "koka-cross-test" {} ''
      ${crossPkgs.stdenv.hostPlatform.emulator crossPkgs.buildPackages} \
        ${crossPkgs.koka}/bin/koka ${kokaHelloWorld} \
        > $out
    '';
in

crossTest pkgsCross.aarch64-multiplatform

This will fail with the following error message:

Error while loading /nix/store/dnv68agszwxm9rw4njsjl2di3fvvvzph-koka-2.1.1-aarch64-unknown-linux-gnu/bin/koka: Exec format error

At first I suspected that qemu can't deal with shebang scripts for some reason since swapping out koka for .koka-wrapped
works (at least the binary runs, but fails due to missing certain environment variables). But the issue seems to be even worse than that:

  • Using ${crossPkgs.bash} -c ${crossPkgs.koka}/bin/koka doesn't work
  • Using ${crossPkgs.bash} -c ${crossPkgs.koka}/bin/.koka-wrapped doesn't work

Seems like it's pretty much impossible for a process started by the emulator to call exec without running into executable format issues. Not sure if this is fixable without launching a full VM?!

Note that this makes most sense to test against #119468.

Notify maintainers

cc @Ericson2314 @matthewbauer @siraben

@sternenseemann sternenseemann added 0.kind: bug 6.topic: cross-compilation Building packages on a different sort platform than than they will be run on labels Apr 19, 2021
@Ericson2314
Copy link
Member

Well, can't say I'm too surprised. I googled "binfmt_misc" and "child"/"fork" and didn't see anything obvious either.

@domenkozar
Copy link
Member

According to Qemu docs we're using qemu-${arch} which is user emulation, but you could try with qemu-system-${arch} which is full emulation but slower.

I'm new to all this so I might be wrong :)

@r-burns
Copy link
Contributor

r-burns commented Oct 22, 2021

Basically the execve call goes straight to the kernel, which doesn't know it's supposed to be emulating.

Unfortunately there is no upstream support for this, but there are downstream patches which fix this:
https://github.com/pld-linux/qemu/blob/9793852df1b6132791fd7995b4eedd04d6c7948e/qemu-user-execve.patch

@Mindavi
Copy link
Contributor

Mindavi commented Apr 19, 2022

I don't think we can really solve this in nixpkgs. However, there's a new tool called makeBinaryWrapper in our toolbox which may help with this situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug 6.topic: cross-compilation Building packages on a different sort platform than than they will be run on
Projects
None yet
Development

No branches or pull requests

5 participants