Homebrew/homebrew-games — pull request #184 by tomyun (2014-12-04 08:19:31+00:00)
Title: mame: disable LTO on OS X 10.7 and below

Recent addition of LTO (link time optimization) in the formula seems to be broken on older OS X. It builds without problem, but crashes on startup at least with my 10.7 (Lion). An exactly same issue found with 0.155 formula as well.

It's probably due to an obsolete version of clang which is no longer updated/supported as Xcode and OS itself are. As an workaround, the formula is updated to ensure that LTO is only enabled on 10.8 (Mountain Lion) and above.

FYI, here is a part of crash log from mame 0.156 with SDL2:

```
Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: 0x000000000000000d, 0x0000000000000000

VM Regions Near 0:
-->
__TEXT 00000001072ef000-000000010ac53000 [ 57.4M] r-x/rwx SM=COW /usr/local/Cellar/mame/0.156/bin/mame

Application Specific Information:
objc[5802]: garbage collection is OFF

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libunwind.dylib 0x00007fff8fd86fe6 libunwind::CompactUnwinder_x86_64::stepWithCompactEncodingFrameless(unsigned int, unsigned long long, libunwind::LocalAddressSpace&, libunwind::Registers_x86_64&, bool) + 630
1 libunwind.dylib 0x00007fff8fd8520c libunwind::CompactUnwinder_x86_64::stepWithCompactEncoding(unsigned int, unsigned long long, libunwind::LocalAddressSpace&, libunwind::Registers_x86_64&) + 52
2 libunwind.dylib 0x00007fff8fd85171 libunwind::UnwindCursor::step() + 69
3 libobjc.A.dylib 0x00007fff8e9b9294 objc_addExceptionHandler + 82
4 com.apple.CoreFoundation 0x00007fff91f1ca34 _CFDoExceptionOperation + 308
5 com.apple.AppKit 0x00007fff8ad21696 _NSAppKitLock + 73
6 com.apple.AppKit 0x00007fff8af1c0c3 +[NSScroller initialize] + 95
7 libobjc.A.dylib 0x00007fff8e9b4662 _class_initialize + 320
8 libobjc.A.dylib 0x00007fff8e9b4517 prepareForMethodLookup + 237
9 libobjc.A.dylib 0x00007fff8e9b42bb lookUpMethod + 63
10 libobjc.A.dylib 0x00007fff8e9b1f3c objc_msgSend + 188
11 com.apple.AppKit 0x00007fff8ad803c6 -[NSWindow _surfaceOrderedInWindow:] + 44
12 com.apple.AppKit 0x00007fff8b1fdb2e -[NSOpenGLContext setView:] + 885
13 libSDL2-2.0.0.dylib 0x000000010d3a3db8 -[SDLOpenGLContext setWindow:] + 217
14 libSDL2-2.0.0.dylib 0x000000010d3a453f Cocoa_GL_MakeCurrent + 84
15 libSDL2-2.0.0.dylib 0x000000010d3a4264 Cocoa_GL_CreateContext + 916
16 libSDL2-2.0.0.dylib 0x000000010d3a01ac SDL_GL_CreateContext_REAL + 84
17 mame 0x00000001094fc455 _ZL21drawogl_window_createP15sdl_window_infoii + 303
18 mame 0x000000010940dff8 _ZL18complete_create_wtPvi + 496
19 mame 0x000000010940be64 sdl_osd_interface::video_init() + 4350
20 mame 0x00000001092cc35a osd_interface::init_subsystems() + 18
21 mame 0x0000000108965446 sdl_osd_interface::init(running_machine&) + 1928
22 mame 0x00000001091f1722 running_machine::run(bool) + 1676
23 mame 0x0000000109061c6c machine_manager::execute() + 4688
24 mame 0x0000000107350038 main + 3511
25 mame 0x00000001072f39f4 start + 52
```

And here is a log from mame 0.155 with SDL 1.2:

```
Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: 0x000000000000000d, 0x0000000000000000

VM Regions Near 0:
-->
__TEXT 000000010ca23000-000000011032e000 [ 57.0M] r-x/rwx SM=COW /usr/local/Cellar/mame/0.155/bin/mame

Application Specific Information:
objc[41468]: garbage collection is OFF

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libunwind.dylib 0x00007fff940affe6 libunwind::CompactUnwinder_x86_64::stepWithCompactEncodingFrameless(unsigned int, unsigned long long, libunwind::LocalAddressSpace&, libunwind::Registers_x86_64&, bool) + 630
1 libunwind.dylib 0x00007fff940ae20c libunwind::CompactUnwinder_x86_64::stepWithCompactEncoding(unsigned int, unsigned long long, libunwind::LocalAddressSpace&, libunwind::Registers_x86_64&) + 52
2 libunwind.dylib 0x00007fff940ae171 libunwind::UnwindCursor::step() + 69
3 libobjc.A.dylib 0x00007fff92ce2294 objc_addExceptionHandler + 82
4 com.apple.CoreFoundation 0x00007fff96245a34 _CFDoExceptionOperation + 308
5 com.apple.AppKit 0x00007fff8f04a696 _NSAppKitLock + 73
6 com.apple.AppKit 0x00007fff8f04a5d4 _NSCursorLock + 62
7 com.apple.AppKit 0x00007fff8f1fa58a +[NSCursor pointingHandCursor] + 15
8 com.apple.AppKit 0x00007fff8f1fa127 -[NSTextViewSharedData _commonInit] + 774
9 com.apple.AppKit 0x00007fff8f1f9e17 -[NSTextViewSharedData init] + 65
10 com.apple.AppKit 0x00007fff8f1f9d9d _getAndCacheSharedData + 108
11 com.apple.AppKit 0x00007fff8f1f9d1b -[NSTextView(NSSharing) typingAttributes] + 42
12 com.apple.AppKit 0x00007fff8f1f9c08 -[NSTextView(NSPrivate) _addToTypingAttributes:value:] + 43
13 com.apple.AppKit 0x00007fff8f1f9bd0 -[NSTextView(NSPrivate) _commonInitState] + 253
14 com.apple.AppKit 0x00007fff8f1f9938 -[NSTextView initWithFrame:textContainer:] + 159
15 com.apple.AppKit 0x00007fff8f1f83b1 -[NSTextView initWithFrame:] + 477
16 libSDL-1.2.0.dylib 0x00000001129eecb8 QZ_VideoInit + 396
17 libSDL-1.2.0.dylib 0x00000001129e6091 SDL_VideoInit + 509
18 libSDL-1.2.0.dylib 0x00000001129c93ed SDL_InitSubSystem + 113
19 libSDL-1.2.0.dylib 0x00000001129c94a1 SDL_Init + 23
20 mame 0x000000010e45d87c sdl_osd_interface::init(running_machine&) + 654
21 mame 0x000000010e8e5b84 running_machine::run(bool) + 1676
22 mame 0x000000010e75e400 machine_manager::execute() + 4688
23 mame 0x000000010e07a1b6 -[SDLMain applicationDidFinishLaunching:] + 3552
24 com.apple.Foundation 0x00007fff94f1cd0e __-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_1 + 47
25 com.apple.CoreFoundation 0x00007fff961fe7ba _CFXNotificationPost + 2634
26 com.apple.Foundation 0x00007fff94f08fc3 -[NSNotificationCenter postNotificationName:object:userInfo:] + 65
27 com.apple.AppKit 0x00007fff8f053e2b -[NSApplication _postDidFinishNotification] + 212
28 com.apple.AppKit 0x00007fff8f053b91 -[NSApplication _sendFinishLaunchingNotification] + 78
29 com.apple.AppKit 0x00007fff8f052858 -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 242
30 com.apple.AppKit 0x00007fff8f0525b9 -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 330
31 com.apple.CoreFoundation 0x00007fff96248541 -[NSObject performSelector:withObject:withObject:] + 65
32 com.apple.Foundation 0x00007fff94f3f7c7 __-[NSAppleEventManager setEventHandler:andSelector:forEventClass:andEventID:]_block_invoke_1 + 101
33 com.apple.Foundation 0x00007fff94f3e74e -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 283
34 com.apple.Foundation 0x00007fff94f3e5dc _NSAppleEventManagerGenericHandler + 105
35 com.apple.AE 0x00007fff918c1c25 aeDispatchAppleEvent(AEDesc const*, AEDesc*, unsigned int, unsigned char*) + 200
36 com.apple.AE 0x00007fff918c1b03 _ZL25dispatchEventAndSendReplyPK6AEDescPS_ + 38
37 com.apple.AE 0x00007fff918c19f7 aeProcessAppleEvent + 250
38 com.apple.HIToolbox 0x00007fff94387b69 AEProcessAppleEvent + 102
39 com.apple.AppKit 0x00007fff8f04f9c5 _DPSNextEvent + 1247
40 com.apple.AppKit 0x00007fff8f04f07d -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 135
41 com.apple.AppKit 0x00007fff8f04b9b9 -[NSApplication run] + 470
42 mame 0x000000010ca82629 main + 1280
43 mame 0x000000010ca27a54 start + 52
```