flathub / io.github.dosbox-staging

https://flathub.org/apps/details/io.github.dosbox-staging
4 stars 4 forks source link

version 0.81.0 doesn't work on old CPUs (AVX2 missing) #44

Closed mateusza closed 7 months ago

mateusza commented 7 months ago

I have updated to following version of Dosbox-staging:

$ flatpak info io.github.dosbox-staging 

DOSBox Staging - DOS/x86 emulator with advanced features

          ID: io.github.dosbox-staging
         Ref: app/io.github.dosbox-staging/x86_64/stable
        Arch: x86_64
      Branch: stable
     Version: 0.81.0
     License: GPL-2.0-or-later
      Origin: flathub
  Collection: org.flathub.Stable
Installation: system
   Installed: 19.4 MB
     Runtime: org.freedesktop.Platform/x86_64/23.08
         Sdk: org.freedesktop.Sdk/x86_64/23.08

      Commit: a33a782c6bd7193edd23c74ac9394ff9bab58d958192c692345bd2d6b10ba6f7
      Parent: 2650be3f5701bd0856a96361c4caa9673640c0ca097c8532de99957610a5a07b
     Subject: 0.81.0 (#43) (00b2655f)
        Date: 2024-02-14 22:55:52 +0000

My CPU is:

$ lscpu
Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         36 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  4
  On-line CPU(s) list:   0-3
Vendor ID:               GenuineIntel
  Model name:            Intel(R) Core(TM) i3-2350M CPU @ 2.30GHz
    CPU family:          6
    Model:               42
    Thread(s) per core:  2
    Core(s) per socket:  2
    Socket(s):           1
    Stepping:            7
    CPU(s) scaling MHz:  35%
    CPU max MHz:         2300.0000
    CPU min MHz:         800.0000
    BogoMIPS:            4589.29
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ht tm pbe syscall nx rdtscp lm constant_t
                         sc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm p
                         cid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer xsave avx lahf_lm epb pti tpr_shadow vnmi flexpriority ept vpid xsaveopt dtherm arat pln pts

Dosbox staging fails to start:

[ 3049.553094] traps: dosbox[21680] trap invalid opcode ip:55cd74e83bc6 sp:7ffc17b472c0 error:0 in dosbox[55cd74e52000+442000]
[ 3066.191006] traps: dosbox[22052] trap invalid opcode ip:558420670bc6 sp:7ffd74980c60 error:0 in dosbox[55842063f000+442000]
[ 3318.712840] traps: dosbox[23625] trap invalid opcode ip:56455bcc5bc6 sp:7ffde8cc5940 error:0 in dosbox[56455bc94000+442000]
$ flatpak run --command=bash --devel  io.github.dosbox-staging
$ gdb /app/bin/dosbox 
GNU gdb (GDB) 13.2
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /app/bin/dosbox...
(No debugging symbols found in /app/bin/dosbox)
(gdb) run
Starting program: /app/bin/dosbox 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGILL, Illegal instruction.
0x000055555564ebc6 in ?? ()
(gdb) x/i 0x000055555564ebc6
=> 0x55555564ebc6:  vinserti128 $0x1,%xmm3,%ymm4,%ymm5

https://en.wikipedia.org/wiki/Advanced_Vector_Extensions#Advanced_Vector_Extensions_2

$ objdump -S /app/bin/dosbox | grep vinserti128
   fabc6:   c4 e3 5d 38 eb 01       vinserti128 $0x1,%xmm3,%ymm4,%ymm5
  114d13:   c4 e3 4d 38 fc 01       vinserti128 $0x1,%xmm4,%ymm6,%ymm7
  115e53:   c4 e3 55 38 f3 01       vinserti128 $0x1,%xmm3,%ymm5,%ymm6
  115f02:   c4 43 25 38 e1 01       vinserti128 $0x1,%xmm9,%ymm11,%ymm12
  1169f5:   c4 63 45 38 c5 01       vinserti128 $0x1,%xmm5,%ymm7,%ymm8
  11ab53:   c4 43 25 38 f5 01       vinserti128 $0x1,%xmm13,%ymm11,%ymm14
  11ab8b:   c4 e3 65 38 e2 01       vinserti128 $0x1,%xmm2,%ymm3,%ymm4
  11aba3:   c4 63 3d 38 ce 01       vinserti128 $0x1,%xmm6,%ymm8,%ymm9
  11b111:   c4 e3 65 38 f5 01       vinserti128 $0x1,%xmm5,%ymm3,%ymm6
  11bcdf:   c4 e3 65 38 ec 01       vinserti128 $0x1,%xmm4,%ymm3,%ymm5
  11c143:   c4 e3 5d 38 fe 01       vinserti128 $0x1,%xmm6,%ymm4,%ymm7
  11c1aa:   c4 43 35 38 e3 01       vinserti128 $0x1,%xmm11,%ymm9,%ymm12
  11c369:   c4 e3 6d 38 e0 01       vinserti128 $0x1,%xmm0,%ymm2,%ymm4
  11cd04:   c4 c3 75 38 d6 01       vinserti128 $0x1,%xmm14,%ymm1,%ymm2
  11cdbd:   c4 43 1d 38 ea 01       vinserti128 $0x1,%xmm10,%ymm12,%ymm13
  11cdd5:   c4 63 45 38 c5 01       vinserti128 $0x1,%xmm5,%ymm7,%ymm8
  11ceef:   c4 e3 55 38 f0 01       vinserti128 $0x1,%xmm0,%ymm5,%ymm6
  11cff6:   c4 63 1d 38 6c 24 40    vinserti128 $0x1,0x40(%rsp),%ymm12,%ymm13
  11d4f4:   c4 e3 5d 38 f5 01       vinserti128 $0x1,%xmm5,%ymm4,%ymm6
  11d9b5:   c4 43 25 38 f5 01       vinserti128 $0x1,%xmm13,%ymm11,%ymm14
  11db26:   c4 e3 65 38 e2 01       vinserti128 $0x1,%xmm2,%ymm3,%ymm4
  11dda5:   c4 43 4d 38 c8 01       vinserti128 $0x1,%xmm8,%ymm6,%ymm9
  11e376:   c4 e3 5d 38 c3 01       vinserti128 $0x1,%xmm3,%ymm4,%ymm0
mateusza commented 7 months ago

I updated the original issue, it seems it's actually not AVX but AVX2

mateusza commented 7 months ago

As a workaround I downgraded to 0.80.0 and it works fine

rderooy commented 7 months ago

I think this may be a consequence of the new release requiring features found only in newer hardware.

Your CPU was after all released in Q4'11, more than 12 years ago.

I think your best bet, other then upgrading your hardware or running an old release, is to ask the question on the github page or discord server of dosbox staging itself.

Grounded0 commented 7 months ago

SSSE3 is now required that was first available on Intel Core 2 CPUs released in 2006. Not sure whats happening here but you could try compiling it yourself from scratch and see if that helps.

Eonfge commented 7 months ago

Your best option, is to stick with 0.80. You can roll back to an older version like this:

https://github.com/flatpak/flatpak/issues/3097#issuecomment-530583469

And then you can use flatpak mask to prevent it from updating

Eonfge commented 7 months ago

Here are the commands:

$ flatpak install flathub io.github.dosbox-staging
$ sudo flatpak update --commit=2650be3f5701bd0856a96361c4caa9673640c0ca097c8532de99957610a5a07b io.github.dosbox-staging
$ sudo flatpak mask io.github.dosbox-staging

Should we add this to the readme?

jonathan-teh commented 7 months ago

I ran into this issue on an AMD Athlon 5350 (has AVX but not AVX2). Using objdump on the binary, it's not just AVX2 but also other instructions from x86-64-v3 as though -march=x86-64-v3 was specified. Trying a build of the upstream source with the same config options -Dbuildtype=release -Ddefault_library=shared, it indicates the built-in zlib-ng is used:

  Build Summary
    Build type            : release
    Install prefix        : /usr/local
    SIMD instruction sets : SSE2, SSSE3
    Host page size (bytes): 4096

    zlib-ng provider      : built-in
    zlib provider         : built-in (zlib-ng)

and checking build.ninja, ARGS includes -march=native. Building on an AMD Ryzen 5 2400G (which supports x86-64-v3), the resulting binary does indeed use instructions from that microarchitecture level such as AVX2. In meson_options:

# The meson.build either uses zlib-ng if its found as a system library or
# compiles it as a built-in (provided CMake is available and Meson is at
# least version 1.3.0), in that order.
#
# The built-in will use native SIMD instructions by default, however if you're
# targeting a range of hardware then set this to the most conservative set of
# SIMD instructions for your needs. For example, if you want to be sure your
# binary runs on Intel's Core 2 Duo, set: meson setup -Duse_zlib_ng=sse2,ssse3

so adding -Duse_zlib_ng=sse2,ssse3 as suggested restricts the binary to SSSE3. It appears this bit in meson.build:

if is_optimized_buildtype and zlib_ng_is_native
    extra_flags += '-march=native'
    simd_instruction_sets += 'native'
    message('Enabling native SIMD optimizations')
endif

results in -march=native added to the general build flags and affects all files, not just zlib-ng. Options would be:

Eonfge commented 7 months ago

@jonathan-teh Thanks for delving into this. I've prepared a test version that hopefully works well on older hardware: https://github.com/flathub/io.github.dosbox-staging/pull/45

Eonfge commented 7 months ago

@mateusza If you have any time, please let me know if this package works for you:

flatpak install --user https://dl.flathub.org/build-repo/84198/io.github.dosbox-staging.flatpakref
mateusza commented 7 months ago

@mateusza If you have any time, please let me know if this package works for you:

flatpak install --user https://dl.flathub.org/build-repo/84198/io.github.dosbox-staging.flatpakref

This one works!