Bug 2257447 - MAME crashes with SIGILL on Apple M2
Summary: MAME crashes with SIGILL on Apple M2
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 39
Hardware: aarch64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2024-01-09 17:32 UTC by Yussef Dalton
Modified: 2024-11-27 22:36 UTC (History)
12 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2024-11-27 22:36:07 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Yussef Dalton 2024-01-09 17:32:33 UTC
Upon launching MAME on my M2 MacBook Air, it crashes with SIGILL (Illegal instruction). I suspect this is a BTI issue as booting with the "arm64.nobti" kernel parameter does not lead to this crash. I am using MAME version "0.261 (unknown)".

Reproducible: Always

Steps to Reproduce:
1. Install the application on an Apple M2.
2. Run it.
Actual Results:  
The application crashes with SIGILL.

Expected Results:  
The application to run with a fullscreen window.

Comment 1 Julian Sikorski 2024-01-09 19:32:14 UTC
Oh, this will be interesting to track down. Are you able to rebuild the package using lld or ld.gold as linker? This is how I did it recently:
https://src.fedoraproject.org/rpms/mame/c/fe3d4067666876f1cd5aa8a76ca92705c92e23f9?branch=rawhide

Comment 2 Yussef Dalton 2024-01-09 21:05:06 UTC
(In reply to Julian Sikorski from comment #1)
> Oh, this will be interesting to track down. Are you able to rebuild the
> package using lld or ld.gold as linker? This is how I did it recently:
> https://src.fedoraproject.org/rpms/mame/c/
> fe3d4067666876f1cd5aa8a76ca92705c92e23f9?branch=rawhide

I tried rebuilding the package to something similar as your commit, I reverted 
the latest commit and changed the required version to 39 like this:

# https://sourceware.org/bugzilla/show_bug.cgi?id=30930
%if 0%{?fedora} >= 39
%ifarch aarch64
BuildRequires:  lld
%endif
%endif

and

    TOOLS=1 \
    LDOPTS="$RPM_LD_FLAGS" \
%if 0%{?fedora} >= 39
%ifarch aarch64
    LDOPTS+="-fuse-ld=lld" \
%endif
%endif


Unfortunately at the end the build failed with the same illegal instruction:

DWARF-compressing 16 files
sepdebugcrcfix: Updated 16 CRC32s, 0 CRC32s did match.
Creating .debug symlinks for symlinks to ELF files
Copying sources found by 'debugedit -l' to /usr/src/debug/mame-0.260-1.fc39.aarch64
561634 blocks
find-debuginfo: done
+ '[' '%{buildarch}' = noarch ']'
+ QA_CHECK_RPATHS=1
+ case "${QA_CHECK_RPATHS:-}" in
+ /usr/lib/rpm/check-rpaths
+ /usr/lib/rpm/check-buildroot
+ /usr/lib/rpm/redhat/brp-ldconfig
+ /usr/lib/rpm/brp-compress
+ /usr/lib/rpm/redhat/brp-strip-lto /usr/bin/strip
+ /usr/lib/rpm/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/check-rpaths
+ /usr/lib/rpm/redhat/brp-mangle-shebangs
+ /usr/lib/rpm/brp-remove-la-files
+ env /usr/lib/rpm/redhat/brp-python-bytecompile '' 1 0 -j8
+ /usr/lib/rpm/redhat/brp-python-hardlink
Executing(%check): /bin/sh -e /var/tmp/rpm-tmp.2Jyo4a
+ umask 022
+ cd /home/pino/rpmbuild/BUILD
+ cd mame-mame0260
+ ./mame -validate
/var/tmp/rpm-tmp.2Jyo4a: line 37: 143413 Illegal instruction     (core dumped) ./mame -validate
error: Bad exit status from /var/tmp/rpm-tmp.2Jyo4a (%check)

RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.2Jyo4a (%check)

Comment 3 Julian Sikorski 2024-01-09 21:09:42 UTC
Thanks for checking. Another thing to try would be to try building with clang - it might help that it is gcc which puts the BTI instruction into the binary. I do not think it is a problem with mame, but it is mame exposing an issue elsewhere, similarly as the BTI veneer issue in ld.bfd which was fixed recently.

Comment 4 Yussef Dalton 2024-01-09 21:20:34 UTC
Running mame in gdb reveals the following stacktrace:

Starting program: /usr/bin/mame 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Program received signal SIGILL, Illegal instruction.
0x0000aaaaadd60620 in __cxa_guard_acquire@plt ()
(gdb) bt full
#0  0x0000aaaaadd60620 in __cxa_guard_acquire@plt ()
No symbol table info available.
#1  0x0000aaaab6f333e8 in image_category() ()
No symbol table info available.
#2  0x0000aaaaaeef38a0 [PAC] in _GLOBAL__sub_I__ZN26legacy_floppy_image_device17flopimg_get_imageEv ()
No symbol table info available.
#3  0x0000fffff5780b2c [PAC] in __libc_start_main_impl () from /lib64/libc.so.6
No symbol table info available.
#4  0x0000aaaaaef550f0 [PAC] in _start ()

Comment 5 Julian Sikorski 2024-01-09 21:24:14 UTC
My first guess would be a compiler issue. Let's see what gcc maintainers think.

Comment 6 Jakub Jelinek 2024-02-13 14:07:27 UTC
You didn't say which gcc, binutils, glibc versions were involved.
If the SIGILL is really in the PLT slot (created by the linker), then I believe relocation processing (in linker and dynamic linker) should make sure that
indirect calls call the function whose address has been taken directly rather than trhrough PLT slot, that should be for direct calls only, so I think
linker doesn't add any magic instructions to PLT slots for BTI/PAC.
Would be interesting to know disas $pc-64,$pc+32 in the caller (i.e. image_category), whether it is indeed an indirect call in there, and how it got to calling
a PLT slot.  At least looking at rawhide gcc build logs and debug info, seems everything in libstdc++.so.6 has been compiled with -mbranch-protection=standard,
but my suspection would be something wrong on the MAME side, or in binutils or glibc (dynamic linker), rather than something on the gcc side.

Comment 7 Aoife Moloney 2024-11-13 10:25:51 UTC
This message is a reminder that Fedora Linux 39 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora Linux 39 on 2024-11-26.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
'version' of '39'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, change the 'version' 
to a later Fedora Linux version. Note that the version field may be hidden.
Click the "Show advanced fields" button if you do not see it.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora Linux 39 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora Linux, you are encouraged to change the 'version' to a later version
prior to this bug being closed.

Comment 8 Aoife Moloney 2024-11-27 22:36:07 UTC
Fedora Linux 39 entered end-of-life (EOL) status on 2024-11-26.

Fedora Linux 39 is no longer maintained, which means that it
will not receive any further security or bug fix updates. As a result we
are closing this bug.

If you can reproduce this bug against a currently maintained version of Fedora Linux
please feel free to reopen this bug against that version. Note that the version
field may be hidden. Click the "Show advanced fields" button if you do not see
the version field.

If you are unable to reopen this bug, please file a new report against an
active release.

Thank you for reporting this bug and we are sorry it could not be fixed.


Note You need to log in before you can comment on or make changes to this bug.