ptitSeb / box64

Box64 - Linux Userspace x86_64 Emulator with a twist, targeted at ARM64 Linux devices
https://box86.org
MIT License
3.71k stars 263 forks source link

8c5752de23ac421025032e405ca3168191ae7a33 dynarec breaks rkbin's boot_merger #1691

Open OPNA2608 opened 2 months ago

OPNA2608 commented 2 months ago

Attempting box64 bump downstream in https://github.com/NixOS/nixpkgs/pull/326034 showed a build failure for rkboot.

rockchip-linux/rkbin has a static x86_64 executable under /tools/boot_merger which our build runs via box64 on aarch64.

substituteInPlace RKBOOT/*.ini --replace 'PATH=' 'PATH=rkboot/'

mkdir rkboot
for i in $(ls ./RKBOOT/*.ini)
do
  # The proprietary, statically linked binaries to perform boot_merge are
  # x86_64 only. Though we use box64 to emulate if building on aarch64-linux
  /path/to/box64 ./tools/boot_merger "$i" || true
done

mkdir -p $out
if [ -z "$(ls -A rkboot)" ]; then
  echo "Error: The 'rkboot' directory is empty."
  exit 1
else
  mv rkboot $out/bin
fi

(Example of upstream code that mirrors this boot_merger usage)

8c5752de23ac421025032e405ca3168191ae7a33 (as present in v0.3.0) made the execution fail to use the argument correctly, even though it shows up in argv[1]?

Diff over outputs ``` Running phase: buildPhase Running phase: buildPhase Dynarec for ARM64, with extension: ASIMD AES CRC32 PMULL SHA1 SHA2sh: lscpu: not foun Dynarec for ARM64, with extension: ASIMD AES CRC32 PMULL SHA1 SHA2sh: lscpu: not foun sh: lscpu: not found sh: lscpu: not found PageSize:4096 Running on Unknown CPU with 6 Cores PageSize:4096 Running on Unknown CPU with 6 Cores Will use Hardware counter measured at 24.0 MHz emulating 3.0 GHz Will use Hardware counter measured at 24.0 MHz emulating 3.0 GHz Params database has 14 entries Params database has 14 entries Box64 with Dynarec v0.2.8 nogit built on Jan 1 1980 00:00:00 | Box64 with Dynarec v0.3.0 nogit built on Jan 1 1980 00:00:00 BOX64: Detected 48bits at least of address space BOX64: Detected 48bits at least of address space Counted 80 Env var Counted 80 Env var BOX64 LIB PATH: ./:lib/:lib64/:x86_64/:bin64/:libs64/ BOX64 LIB PATH: ./:lib/:lib64/:x86_64/:bin64/:libs64/ BOX64 BIN PATH: ./:bin/:/nix/store/5rfs2mv7aw8yfg0l013lzz2q7zc4ycsf-patchelf-0.15.0/b BOX64 BIN PATH: ./:bin/:/nix/store/5rfs2mv7aw8yfg0l013lzz2q7zc4ycsf-patchelf-0.15.0/b Looking for ./tools/boot_merger Looking for ./tools/boot_merger argv[1]="./RKBOOT/PX30MINIALL.ini" argv[1]="./RKBOOT/PX30MINIALL.ini" Rename process to "boot_merger" Rename process to "boot_merger" Redirecting overridden malloc from symtab function for /build/source/tools/boot_merge Redirecting overridden malloc from symtab function for /build/source/tools/boot_merge sh: lscpu: not found sh: lscpu: not found warning, call to unsupported arch_prctl(0x3001, 0xfffff79fe860) | warning, call to unsupported arch_prctl(0x3001, 0xfffff79fe850) ********boot_merger ver 1.34******** ********boot_merger ver 1.34******** Info:Pack loader ok. | NAME > boot_merger - Generating loader tool > SYNOPSIS > boot_merger pack [...] > boot_merger unpack [...] > boot_merger idb [...] > DESCRIPTION > This tool can support to pack and unpack format of rk loader > you can input boot_merger pack to get more help of pack > you can input boot_merger unpack to get more help of unpack > you can input boot_merger idb to get more help of idb ```
Bisect log ``` git bisect start # Status: warte auf guten und schlechten Commit # good: [8545d0505f274554561ca30e1839027dd7be783a] Bumped version to v0.2.8 git bisect good 8545d0505f274554561ca30e1839027dd7be783a # Status: warte auf schlechten Commit, 1 guter Commit bekannt # bad: [62695ceed4982c3fdf379b65cc4481c3656cd6ac] Bumped version to v0.3.0 git bisect bad 62695ceed4982c3fdf379b65cc4481c3656cd6ac # good: [537cb65f26afd07cbc2332f0a60c181f5c75c0d7] [ARM64_DYNAREC] Added BMI.0F38 F2, F3/1 opcodes git bisect good 537cb65f26afd07cbc2332f0a60c181f5c75c0d7 # good: [cbb3126b28d2987fd1c2aeaf963a86ecb1ffcf4b] [COSIM] Improved handling of AVX.66.0F38 3E/2F opcodes git bisect good cbb3126b28d2987fd1c2aeaf963a86ecb1ffcf4b # good: [7771a67abebdd09917a3278f2442ff85c730cb0b] Add missing func declarations: `get_first_jump_addr` (#1627) git bisect good 7771a67abebdd09917a3278f2442ff85c730cb0b # good: [267bffb0ec2b8afdea35cdc7f2d5983f7cd1566b] [ARM64_DYNAREC] More improvment on YMM handling git bisect good 267bffb0ec2b8afdea35cdc7f2d5983f7cd1566b # bad: [d6b9fd2860dc097de8aebf147b3aa6d1741ea550] [VULKAN] Added 1 more extension git bisect bad d6b9fd2860dc097de8aebf147b3aa6d1741ea550 # bad: [d7e8da632183e6ceece1230710f6dda722d2f8ae] [ARM64_DYNAREC] Fixed reflect cache for ymm0 git bisect bad d7e8da632183e6ceece1230710f6dda722d2f8ae # bad: [b4828477794a8e69a96f0ca7991ad0e619d1b2a3] [INTERPRETER] Added 64 66 8D opcode (#1648) git bisect bad b4828477794a8e69a96f0ca7991ad0e619d1b2a3 # bad: [8c5752de23ac421025032e405ca3168191ae7a33] [ARM64_DYNAREC] Made AVX/AVX2 enabled by default, but only for ARM64 Dynarec configs git bisect bad 8c5752de23ac421025032e405ca3168191ae7a33 # first bad commit: [8c5752de23ac421025032e405ca3168191ae7a33] [ARM64_DYNAREC] Made AVX/AVX2 enabled by default, but only for ARM64 Dynarec configs ```

BOX64_DYNAREC=0 at runtime gets recognised, but it's not enough to work around this. Only works again by rebuilding box64 with -DARM_DYNAREC=OFF or reverting 8c5752de23ac421025032e405ca3168191ae7a33. Issue is unresolved on current master.

ptitSeb commented 2 months ago

An "easy" workaround would be to create a box64rc (either in box64.box64rc file on github repo sit's global for everyone or in a local ~/.box64rc) entry like that:

[boot_merger]
BOX64_AVX=0

But that's just a workaround. There is, it seems, and error somewhere in AVX/AVX2 emulation in box64 that would be good to finx. Is this boot_merger available somewhere?

EDIT: ok, found it.

ptitSeb commented 2 months ago

Mmmm, I don't reproduce the issue on my side. Buy you can try declaring BOX64_AVX=0 env. var. in your shell script.

OPNA2608 commented 2 months ago

BOX64_AVX=0 also works, thanks.

Anything I can provide you with to debug this?

ptitSeb commented 2 months ago

I need a simple way to reproduce, so I can dump code and debug. I downloaded the binary, but I can't reproduce the issue, it just accept my input on command llne (but maybe it needs to be from a shell scipt).

OPNA2608 commented 2 months ago

Here are some instructions on how to use & debug with Nix. Maybe something is wrong with our build/environment specifically?

  1. Install Nix
  2. Download Nixpkgs (It's pretty large if you clone it, just a zip/tarball of master should be enough)
  3. In pkgs/applications/emulators/box64/default.nix, change src = fetchFromGitHub { ... }; to src = /path/to/your/box64/clone;
  4. env NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link /path/to/nixpkgs -A rkboot should attempt to build box64 + the failing package, code for the latter is in pkgs/by-name/rk/rkboot/package.nix

If you only need to run basic commands and look at their results, then add whatever commands you need to the appropriate package file, and build with --keep-failed to inspect the build environment afterwards. The kept location should be printed at or near the end of the output.

If you need to do something interactively, i.e. gdb:

  1. Add (or merge into if nativeBuildInputs is already present)
    nativeBuildInputs = [
    breakpointHook
    cntr
    # whatever packages you need inside the sandbox, i.e. gdb
    ];
  2. Add all of those into the { }: at the top of the file
  3. nix-build like earlier. On error, the build will halt with instructions on how to enter the sandbox with cntr. Should be smth like sudo cntr attach -t command cntr-... to enter the container, and cntr exec sh to enter a shell inside of it (might need a full path to cntr).