View Issue Details

IDProjectCategoryView StatusLast Update
0038189FPCCompilerpublic2020-12-18 16:51
ReporterIgor Kokarev Assigned ToJonas Maebe  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformApple M1OSmacOS 
Product Version3.2.1 
Fixed in Version3.2.1 
Summary0038189: App aarch64 crashes on Apple M1
DescriptionApp (aarch64) crashes on creating of NSWindow initWithContentRect_styleMask_backing_defer() on Mac with Apple M1 chip.

Dec 8 05:37:07 Toms-Mac-mini com.apple.xpc.launchd[1]: Coalition Cache Hit: app<application.SimpleApp.2109617.2109623(501)> [14248]
Dec 8 05:37:09 Toms-Mac-mini com.apple.xpc.launchd[1] (application.SimpleApp.2109617.2109623[14271]): Service exited with abnormal code: 217
Steps To ReproduceCompile the attached test project for aarch64-darwin target and run APP bundle on Apple M1 Mac. Normally you should see an empty white window. This doesn't occur on M1 Mac.
Additional InformationThis problem doesn't occur with x86-64 code executed via Rosetta emulation. Also native aarch64 code works fine on Apple DTK. The problem occurs only with Apple M1 Macs for aarch64 code.

FPC 3.2.1 fixes (2020/11/20), Lazarus 2.0.10, Intel Mac Big Sur 11.0.1, Xcode 12.2.
TagsNo tags attached.
Fixed in Revision47756
FPCOldBugId
FPCTarget-
Attached Files

Activities

Igor Kokarev

2020-12-09 07:24

reporter  

SimpleApp.zip (2,420 bytes)

Igor Kokarev

2020-12-09 16:07

reporter   ~0127483

This problem doesn't appear with fpc 3.3.1 trunk.

Jonas Maebe

2020-12-11 12:51

manager   ~0127532

Can you run the compiled program under lldb and post a backtrace when it crashes?

Igor Kokarev

2020-12-11 14:20

reporter   ~0127534

Last edited: 2020-12-11 14:21

View 2 revisions

I don't have M1 Mac yet. I asked a customer to run our test app.
skalogryz reproduced this problem, too. He sent me callstack with lldb:

(lldb) bt
* thread 0000001, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=1, subcode=0x9e780008)
  * frame #0: 0x0000000182dc2b08 CoreFoundation`CFNumberCreate + 440
    frame 0000001: 0x0000000183ba59c8 Foundation`-[NSPlaceholderNumber initWithDouble:] + 60
    frame 0000002: 0x00000001890ad4e8 QuartzCore`+[CALayer defaultValueForKey:] + 912
    frame 0000003: 0x00000001890ac8fc QuartzCore`classDescription_locked(objc_class*) + 3152
    frame 0000004: 0x00000001890abde8 QuartzCore`classDescription_locked(objc_class*) + 316
    frame 0000005: 0x00000001890abde8 QuartzCore`classDescription_locked(objc_class*) + 316
    frame 0000006: 0x00000001890ab96c QuartzCore`classDescription(objc_class*) + 244
    frame 0000007: 0x00000001890ab530 QuartzCore`CA::Layer::class_state(objc_class*) + 60
    frame 0000008: 0x00000001890ab41c QuartzCore`-[CALayer init] + 104
    frame 0000009: 0x00000001890ab32c QuartzCore`+[CALayer layer] + 16
    frame 0000010: 0x000000018562c7ac AppKit`-[NSView(NSPrivateLayerSupport) _createLayer] + 36
    frame 0000011: 0x0000000185ea2a34 AppKit`-[NSView _createLayerAndInitialize] + 48
    frame 0000012: 0x000000018562bbb4 AppKit`-[NSView _updateLayerBackedness] + 744
    frame 0000013: 0x000000018562b808 AppKit`-[NSView didChangeValueForKey:] + 72
    frame 0000014: 0x000000018562b510 AppKit`-[NSTitlebarContainerView initWithFrame:] + 92
    frame 0000015: 0x000000018562ab44 AppKit`__49-[NSThemeFrame _floatTitlebarAndToolbarFromInit:]_block_invoke + 144
    frame 0000016: 0x000000018562a998 AppKit`+[NSAnimationContext runAnimationGroup:] + 72
    frame 0000017: 0x000000018562a828 AppKit`-[NSThemeFrame _floatTitlebarAndToolbarFromInit:] + 128
    frame 0000018: 0x0000000185625c8c AppKit`-[NSThemeFrame initWithFrame:styleMask:owner:] + 236
    frame 0000019: 0x00000001856239c4 AppKit`-[NSWindow _commonInitFrame:styleMask:backing:defer:] + 552
    frame 0000020: 0x00000001856232cc AppKit`-[NSWindow _initContent:styleMask:backing:defer:contentView:] + 752
    frame 0000021: 0x0000000185622fd0 AppKit`-[NSWindow initWithContentRect:styleMask:backing:defer:] + 56
    frame 0000022: 0x00000001000d1be8 SimpleApp`COCOAFORMMANAGER_$$_GETCOCOAWRAPPERINT$crcA211CC4D + 200
    frame 0000023: 0x00000001000d200c SimpleApp`COCOAFORMMANAGER_$$_GETCOCOAWRAPPER$crc01C47544 + 92
    frame 0000024: 0x00000001000c62f4 SimpleApp`COCOAFORMS$_$TCOCOAFORMCONTROLLER_$__$$_GETDEFAULTBOUNDSRECT$$TRECT + 100
    frame 0000025: 0x00000001000379b4 SimpleApp`WNFORMS$_$TFORMCONTROLLER_$__$$_CREATE$TWNFORM$$TFORMCONTROLLER + 212
    frame 0000026: 0x00000001000c4684 SimpleApp`COCOAFORMS$_$TCOCOAFORMCONTROLLER_$__$$_CREATE$TWNFORM$$TCOCOAFORMCONTROLLER + 132
    frame 0000027: 0x00000001000c3ee0 SimpleApp`COCOAFORMS_$$_ALLOCCOCOAFORMCONTROLLERPROC$TWNFORM$$TFORMCONTROLLER + 48
    frame 0000028: 0x0000000100035c24 SimpleApp`WNFORMS$_$TWNFORM_$__$$_CREATE$TALLOCFORMCONTROLLERPROC$$TWNFORM + 276
    frame 0000029: 0x00000001001364b0 SimpleApp`WNDRAWFORM$_$TDRAWFORM_$__$$_CREATE$TDEVDRAWMODE$$TDRAWFORM + 128
    frame 0000030: 0x0000000100157734 SimpleApp`WNDRAWFRAMEFORM$_$TDRAWFRAMEFORM_$__$$_CREATE$TDEVDRAWMODE$$TDRAWFRAMEFORM + 132
    frame 0000031: 0x00000001000e1d00 SimpleApp`WNDRAWFORMSERVICES$_$TDRAWFORMSERVICES_$__$$_CREATE$TFRAMEFORMSTYLE$$TDRAWFORMSERVICES + 176
    frame 0000032: 0x00000001000e1484 SimpleApp`WNDRAWFORMSERVICES_$$_ALLOCDRAWFRAMEFORM$TFRAMEFORMSTYLE$TFCOLOR$$TFORMSERVICES + 68
    frame 0000033: 0x000000010003ae0c SimpleApp`WNFORMSERVICES_$$_ALLOCFRAMEFORM$TFRAMEFORMSTYLE$BOOLEAN$$TFORMSERVICES + 124
    frame 0000034: 0x000000010000346c SimpleApp`PASCALMAIN + 60
    frame 0000035: 0x000000010002e880 SimpleApp`FPC_SysEntry + 32
    frame 0000036: 0x00000001000033c0 SimpleApp`FPC_SYSTEMMAIN + 80
    frame 0000037: 0x0000000100003418 SimpleApp`main + 40
    frame 0000038: 0x0000000182d5cf64 libdyld.dylib`start + 4

J. Gareth Moreton

2020-12-11 15:13

developer   ~0127536

EXC_BAD_INSTRUCTION - that's concerning. Isn't that the same as SIGILL on POSIX systems? That signal should never be triggered unless a code pointer gets corrupted (I've only triggered it on i386 in custom assembly language when I forgot to preserve EBX).

Jonas Maebe

2020-12-11 16:21

manager   ~0127540

Last edited: 2020-12-11 16:22

View 2 revisions

Can someone with an M1 Mac print the values of $x19, $d0, and $fpcr at that point? My guess is that the M1 Mac has support for floating point hardware exceptions (the DTK doesn't), and that $d0 is +Inf at that point. There's a missing revision for fixing the initialisation of the fpsc register in trunk, I'll merge it (along with some other fixes).

Chris Rorden

2020-12-16 19:04

reporter   ~0127638

Last edited: 2020-12-16 19:05

View 2 revisions

Igor -
  I can not replicate the bug with FreePascal 3.2.1 with patches applied.

Jonas - Have you already applied your changes to the fixes branch? I installed the fixes branch today, recompiled it and then built Igor's project. It works without an error.
  Free Pascal Compiler version 3.2.1 [2020/12/16] for aarch64
Perhaps skalogryz who has observed this issue can retest. I made sure it was a clean build, and I am running Lazarus trunk, albeit a few days old as I do not want to update to the very latest due to this bug report (https://bugs.freepascal.org/view.php?id=38225)



$ ~/src/lazarus/lazbuild -B --compiler=/usr/local/lib/fpc/3.2.1/ppca64 --ws=cocoa SimpleApp.lpi
Hint: (lazarus) [RunTool] "/usr/local/lib/fpc/3.2.1/ppca64" "-iWTOTP"
Hint: (lazarus) [RunTool] "/usr/local/lib/fpc/3.2.1/ppca64" "-va" "compilertest.pas"
TProject.DoLoadStateFile Statefile not found: /Users/chrisrorden/Downloads/SimpleApp/lib/aarch64-darwin/SimpleApp.compiled
Hint: (11030) Start of reading config file /Users/chrisrorden/.fpc.cfg
Hint: (11030) Start of reading config file /etc/fpc.cfg
Hint: (11031) End of reading config file /etc/fpc.cfg
Hint: (11031) End of reading config file /Users/chrisrorden/.fpc.cfg
/Users/chrisrorden/Downloads/SimpleApp/lib/aarch64-darwin/SimpleApp.s:5973:10: warning: section "__datacoal_nt" is deprecated
.section __DATA, __datacoal_nt, coalesced
         ^ ~~~~~~~~~~~~~~
/Users/chrisrorden/Downloads/SimpleApp/lib/aarch64-darwin/SimpleApp.s:5973:10: note: change section name to "__data"
.section __DATA, __datacoal_nt, coalesced
         ^ ~~~~~~~~~~~~~~
/Users/chrisrorden/Downloads/SimpleApp/lib/aarch64-darwin/SimpleApp.s:6163:10: warning: section "__datacoal_nt" is deprecated
.section __DATA, __datacoal_nt, coalesced
         ^ ~~~~~~~~~~~~~~
/Users/chrisrorden/Downloads/SimpleApp/lib/aarch64-darwin/SimpleApp.s:6163:10: note: change section name to "__data"
.section __DATA, __datacoal_nt, coalesced
         ^ ~~~~~~~~~~~~~~
Free Pascal Compiler version 3.2.1 [2020/12/16] for aarch64
Copyright (c) 1993-2020 by Florian Klaempfl and others
(1002) Target OS: Darwin for AArch64
(3104) Compiling SimpleApp.lpr
/Users/chrisrorden/Downloads/SimpleApp/SimpleApp.lpr(7,13) Hint: (5023) Unit "MacOSAll" not used in SimpleApp
(9009) Assembling simpleapp
(9015) Linking /Users/chrisrorden/Downloads/SimpleApp/SimpleApp
(1008) 38 lines compiled, 0.7 sec
(1022) 5 hint(s) issued

Jonas Maebe

2020-12-16 19:57

manager   ~0127639

> Jonas - Have you already applied your changes to the fixes branch?
Yes, I have (r47756). Thanks for testing!

Igor Kokarev

2020-12-18 16:51

reporter   ~0127672

Jonas, I checked latest FPC 3.2.1 fixes (downloaded today) on Apple M1. This problem is solved. Many thanks!

I found a similar problem with system exception when macOS function called from another thread on M1:
https://bugs.freepascal.org/view.php?id=38230

Issue History

Date Modified Username Field Change
2020-12-09 07:24 Igor Kokarev New Issue
2020-12-09 07:24 Igor Kokarev File Added: SimpleApp.zip
2020-12-09 16:07 Igor Kokarev Note Added: 0127483
2020-12-11 12:51 Jonas Maebe Note Added: 0127532
2020-12-11 14:20 Igor Kokarev Note Added: 0127534
2020-12-11 14:21 Igor Kokarev Note Edited: 0127534 View Revisions
2020-12-11 15:13 J. Gareth Moreton Note Added: 0127536
2020-12-11 16:21 Jonas Maebe Note Added: 0127540
2020-12-11 16:22 Jonas Maebe Note Edited: 0127540 View Revisions
2020-12-16 19:04 Chris Rorden Note Added: 0127638
2020-12-16 19:05 Chris Rorden Note Edited: 0127638 View Revisions
2020-12-16 19:57 Jonas Maebe Note Added: 0127639
2020-12-16 19:57 Jonas Maebe Assigned To => Jonas Maebe
2020-12-16 19:57 Jonas Maebe Status new => resolved
2020-12-16 19:57 Jonas Maebe Resolution open => fixed
2020-12-16 19:57 Jonas Maebe Fixed in Version => 3.2.1
2020-12-16 19:57 Jonas Maebe Fixed in Revision => 47756
2020-12-16 19:57 Jonas Maebe FPCTarget => -
2020-12-18 16:51 Igor Kokarev Note Added: 0127672