View Issue Details

IDProjectCategoryView StatusLast Update
0038055FPCCompilerpublic2021-01-22 03:30
ReporterChris Rorden Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformApple Developer Transition KitOSDarwin 
Product Version3.3.1 
Summary0038055: Compiling Lazarus for AArch64 with -O3 creates non-functional code
DescriptionThis may be related to issue 38053. The current SVN of FPC can build the latest SVN of Lazarus with default settings. However, the same compilation, but with an increased optimization level will compile without incident, but results in an application that will not launch.


Steps To Reproduce1.) Build Lazarus with an increased optimization level (here are the options in my Tools/ConfigureBuildLazarus menu item, note -O3 causes a failure while resulting code launches with -O2 or lower):


-O3 -FD/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin -XR/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

2.) Launch startlazarus from the terminal to see why the application crashes before a GUI is shown:

Hint: (lazarus) [TBuildManager.SetBuildTarget] Old=aarch64-darwin-cocoa New=aarch64-darwin-cocoa Changed: OS/CPU=True LCL=False
InitOpenedProjectFile select form in designer: GLForm1:TGLForm1 TDesigner
TApplication.HandleException: EBusError
Bus error or misaligned data access
  Stack trace:
  $6E7953454449541E
  $000000010555C06C
  $000000010555B9BC
  $00000001054F3BFC
  $00000001054F2BF0
  $00000001054F7820
  $0000000105502888
  $00000001054F7820
  $0000000105729884
  $00000001054F7820
  $0000000104FB2BD8
  $0000000104DE7FF0
  $0000000104DD1F08
  $0000000104DD5CB8
  $0000000104DE7F24
  $0000000104B89DF0
  $0000000104DDEC64
2020-11-09 07:18:08.268 lazarus[39125:973553] *** Terminating app due to uncaught exception 'NSGenericException', reason: '-[NSAlert runModal] may not be invoked inside of transaction begin/commit pair, or inside of transaction commit (usually this means it was invoked inside of a view's -drawRect: method.)'
*** First throw call stack:
(
    0 CoreFoundation 0x0000000181611320 __exceptionPreprocess + 240
    1 libobjc.A.dylib 0x000000018133fc04 objc_exception_throw + 60
    2 CoreFoundation 0x000000018161116c +[NSException exceptionWithName:reason:userInfo:] + 0
    3 AppKit 0x000000018447f24c _NSRunModal + 164
    4 AppKit 0x0000000183f3a9c8 -[NSAlert runModal] + 272
    5 lazarus 0x0000000104d942b0 COCOAINT_$$_COCOAPROMPTUSER$crcF62BAB40 + 1168
    6 lazarus 0x0000000104d944c4 COCOAINT$_$TCOCOAWIDGETSET_$__$$_PROMPTUSER$crc484A2DB2 + 52
    7 lazarus 0x0000000104d1b47c LCLINTF_$$_PROMPTUSER$crc484A2DB2 + 76
    8 lazarus 0x0000000104d1bc88 LCLINTF_$$_PROMPTUSER$crcB76EAC20 + 120
    9 lazarus 0x0000000104becccc FORMS$_$TAPPLICATION_$__$$_SHOWEXCEPTION$EXCEPTION + 556
    10 lazarus 0x0000000104fa7b84 LCLEXCEPTIONSTACKTRACE$_$TEVENTCONTAINER_$__$$_HANDLEAPPLICATIONEXCEPTION$TOBJECT$EXCEPTION + 292
    11 lazarus 0x0000000104bebe88 FORMS$_$TAPPLICATION_$__$$_HANDLEEXCEPTION$TOBJECT + 376
    12 lazarus 0x0000000104dc0a94 LCLMESSAGEGLUE_$$_DELIVERMESSAGE$TOBJECT$formal$$INT64 + 324
    13 lazarus 0x0000000104dc1338 LCLMESSAGEGLUE_$$_LCLSENDPAINTMSG$TCONTROL$HDC$PPAINTSTRUCT$$INT64 + 72
    14 lazarus 0x0000000104dbec28 COCOAWSCOMMON$_$TLCLCOMMONCALLBACK_$__$$_DRAW$NSGRAPHICSCONTEXT$CGRECT$CGRECT + 456
    15 lazarus 0x0000000104d96210 -[TCocoaCustomControl drawRect:] + 528
    16 AppKit 0x0000000183d4a224 _NSViewDrawRect + 148
    17 AppKit 0x000000018447609c -[NSView _recursive:displayRectIgnoringOpacity:inContext:stopAtLayerBackedViews:] + 1300
    18 AppKit 0x0000000183d499a4 -[NSView(NSLayerKitGlue) _drawViewBackingLayer:inContext:drawingHandler:] + 676
    19 QuartzCore 0x000000018769e2dc CABackingStoreUpdate_ + 180
    20 QuartzCore 0x00000001876f9d5c ___ZN2CA5Layer8display_Ev_block_invoke + 64
    21 QuartzCore 0x000000018769d68c -[CALayer _display] + 1732
    22 AppKit 0x0000000183d495fc -[_NSBackingLayer display] + 372
    23 AppKit 0x0000000183cba7f8 -[_NSViewBackingLayer display] + 644
    24 QuartzCore 0x000000018769c7b4 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 768
    25 QuartzCore 0x00000001877bfc08 _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 432
    26 QuartzCore 0x000000018767af5c _ZN2CA11Transaction6commitEv + 732
    27 AppKit 0x0000000183d5e664 __62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke + 304
    28 AppKit 0x00000001844acc4c ___NSRunLoopObserverCreateWithHandler_block_invoke + 64
    29 CoreFoundation 0x0000000181592df8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36
    30 CoreFoundation 0x0000000181592c44 __CFRunLoopDoObservers + 576
    31 CoreFoundation 0x000000018159219c __CFRunLoopRun + 768
    32 CoreFoundation 0x0000000181591730 CFRunLoopRunSpecific + 600
    33 HIToolbox 0x0000000188f10f0c RunCurrentEventLoopInMode + 292
    34 HIToolbox 0x0000000188f10bcc ReceiveNextEventCommon + 320
    35 HIToolbox 0x0000000188f10a6c _BlockUntilNextEventMatchingListInModeWithFilter + 76
    36 AppKit 0x0000000183bdfdb0 _DPSNextEvent + 868
    37 AppKit 0x0000000183bde730 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1312
    38 lazarus 0x0000000104d8a24c -[TCocoaApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 60
    39 lazarus 0x0000000104d8a80c COCOAINT$_$TCOCOAWIDGETSET_$__$$_APPRUNMESSAGES$BOOLEAN$NSDATE + 124
    40 lazarus 0x0000000104d8a894 COCOAINT$_$TCOCOAWIDGETSET_$__$$_APPPROCESSMESSAGES + 20
    41 lazarus 0x0000000104bebfd4 FORMS$_$TAPPLICATION_$__$$_HANDLEMESSAGE + 52
    42 lazarus 0x0000000104bec4b4 FORMS$_$TAPPLICATION_$__$$_RUNLOOP + 68
    43 lazarus 0x0000000104d89904 -[TCocoaApplication run] + 52
    44 lazarus 0x0000000104d8a780 COCOAINT$_$TCOCOAWIDGETSET_$__$$_APPRUN$TAPPLICATIONMAINLOOP + 64
    45 lazarus 0x0000000104bec458 FORMS$_$TAPPLICATION_$__$$_RUN + 88
    46 lazarus 0x0000000104b76a88 PASCALMAIN + 664
    47 lazarus 0x0000000104b9e10c FPC_SysEntry + 28
    48 lazarus 0x0000000104b767b0 FPC_SYSTEMMAIN + 80
    49 libdyld.dylib 0x00000001814b4f54 start + 4
)
libc++abi.dylib: terminating with uncaught exception of type NSException
TagsNo tags attached.
Fixed in Revision48310
FPCOldBugId
FPCTarget-
Attached Files

Relationships

related to 0038129 feedbackFlorian Wrong code generated on x86-64 
related to 0038053 assignedJ. Gareth Moreton AArch64 -O2 bug not seen with -O1 

Activities

Florian

2020-11-15 21:06

administrator   ~0126976

Do you have any additional information e.g. an assembler dump and registers where it crashes?

Chris Rorden

2020-11-25 20:02

reporter   ~0127182

Florian, Happy to provide more data. However, I think the best approach is for Kit to fix issue 38053 first. That issue with the peephole optimizer is elicited with a much simpler example. If we are lucky the patch for that bug will also resolve this one. If not, I will try to work out a method to elicit this bug in a simpler manner.

J. Gareth Moreton

2020-11-25 20:49

developer   ~0127184

Looks like I got my work cut out! I'll get right on it, Chris.

J. Gareth Moreton

2021-01-11 22:30

developer   ~0128274

So I'm able to develop for AArch64 again. The bug has evolved somewhat and, as of r48131, instead of producing non-functional code, I get "Internal Error 200108231" instead. I'll see if I can discover anything.

J. Gareth Moreton

2021-01-12 05:02

developer   ~0128277

Well, kind of a false alarm - the Internal Error happens under 3.0.4, rather than the trunk. I'm having problems getting the make script to point to the freshly-built compiler. I'm working on it though.

J. Gareth Moreton

2021-01-19 05:01

developer   ~0128404

Okay, got my configuration issues sorted and built Lazarus. If Lazarus is not configured, it asks for the source directory and compiler location, but once it reaches the GUI, it draws some windows but then crashes with an EBusError exception. So I've confirmed it at long last.

J. Gareth Moreton

2021-01-19 11:11

developer   ~0128405

I've got it narrowed down to a bug in RedundantMovProcess. It looks like it's removing an allocation to a register that the peephole optimiser thinks is not in use, when it really is. I'll see if I can narrow down the fault.

J. Gareth Moreton

2021-01-20 05:37

developer   ~0128442

This patch should fix the issue - it fixes some register tracking sp the optimizer doesn't remove instructions erroneously, thinking they're superfluous.
aarch64-o3-mov-fix.patch (873 bytes)   
Index: compiler/armgen/aoptarm.pas
===================================================================
--- compiler/armgen/aoptarm.pas	(revision 48186)
+++ compiler/armgen/aoptarm.pas	(working copy)
@@ -531,6 +531,11 @@
                               { Instruction will become mov r1,r1 }
                               DebugMsg('Peephole Optimization: Mov2None 2 done', next_hp);
 
+                              { Allocate r1 between the instructions; not doing
+                                so may cause problems when removing superfluous
+                                MOVs later (i38055) }
+                              AllocRegBetween(taicpu(p).oper[1]^.reg, p, next_hp, UsedRegs);
+
                               if (next_hp = hp1) then
                                 { Don't let hp1 become a dangling pointer }
                                 hp1 := nil;
aarch64-o3-mov-fix.patch (873 bytes)   

Florian

2021-01-21 21:15

administrator   ~0128471

Forgot to add: I applied the patch yesterday.

J. Gareth Moreton

2021-01-22 03:30

developer   ~0128478

This issie is now fixed... hopefully!

Issue History

Date Modified Username Field Change
2020-11-09 13:28 Chris Rorden New Issue
2020-11-15 21:06 Florian Note Added: 0126976
2020-11-25 20:02 Chris Rorden Note Added: 0127182
2020-11-25 20:49 J. Gareth Moreton Assigned To => J. Gareth Moreton
2020-11-25 20:49 J. Gareth Moreton Status new => assigned
2020-11-25 20:49 J. Gareth Moreton Note Added: 0127184
2020-11-25 20:50 J. Gareth Moreton Relationship added related to 0038053
2020-11-28 16:00 J. Gareth Moreton Relationship added related to 0038129
2021-01-11 22:30 J. Gareth Moreton Note Added: 0128274
2021-01-12 05:02 J. Gareth Moreton Note Added: 0128277
2021-01-19 05:01 J. Gareth Moreton Note Added: 0128404
2021-01-19 11:11 J. Gareth Moreton Note Added: 0128405
2021-01-20 05:37 J. Gareth Moreton Note Added: 0128442
2021-01-20 05:37 J. Gareth Moreton File Added: aarch64-o3-mov-fix.patch
2021-01-20 05:37 J. Gareth Moreton Status assigned => feedback
2021-01-20 05:37 J. Gareth Moreton FPCTarget => -
2021-01-20 05:38 J. Gareth Moreton Assigned To J. Gareth Moreton =>
2021-01-21 21:15 Florian Note Added: 0128471
2021-01-22 03:30 J. Gareth Moreton Status feedback => resolved
2021-01-22 03:30 J. Gareth Moreton Resolution open => fixed
2021-01-22 03:30 J. Gareth Moreton Fixed in Revision => 48310
2021-01-22 03:30 J. Gareth Moreton Note Added: 0128478