xcode 在macOS 13.6(clang 15)上运行应用程序构建时崩溃,在macOS 11(dynamic_cast)上运行时崩溃

vatpfxk5  于 2023-11-21  发布在  Mac
关注(0)|答案(1)|浏览(348)

当我在构建服务器上将xcode升级到15时,出现了一个问题。
在“some time ago”(tm)构建的二进制文件链接的应用程序-现在在macOS 11或更早版本上运行时会崩溃。相同的二进制文件在macOS 12/13/14上运行良好。
罪魁祸首是任何dynamic_cast,下面是一个简化的示例(具有相同故障的最小单个文件应用程序):
OS目标是:10.14 c方言是:C11(-std=c++11..

  1. #import "AppDelegate.h"
  2. #import <osg/AnimationPath>
  3. #import <osg/ref_ptr>
  4. /*
  5. Define some subclass of osg::AnimationPath, so we have something to downcast to
  6. */
  7. class PanZoomAnimationPath : public osg::AnimationPath {
  8. public:
  9. PanZoomAnimationPath() {
  10. setLoopMode(osg::AnimationPath::NO_LOOPING);
  11. }
  12. };
  13. @interface AppDelegate () {
  14. osg::ref_ptr<osg::AnimationPath> _animationPath;
  15. }
  16. @property (strong) IBOutlet NSWindow *window;
  17. @end
  18. @implementation AppDelegate
  19. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
  20. // Try to do some dynamic cast
  21. // auto createdPath = new osg::AnimationPath();
  22. auto createdPath = new PanZoomAnimationPath();
  23. // shove into a ref_ptr that is on the class
  24. _animationPath = createdPath;
  25. NSLog(@"Ptr to path: %p", createdPath);
  26. NSLog(@"Ptr from _animationPath: %p", _animationPath.get());
  27. NSLog(@"Animation path ptr is: %p. Is it valid: %d", _animationPath.get(), _animationPath.valid());
  28. // try to dynamic cast. BOOM (at least, on macOS 11)
  29. PanZoomAnimationPath *pStudioPath = dynamic_cast<PanZoomAnimationPath * >(_animationPath.get());
  30. if(pStudioPath) {
  31. NSLog(@"Success!");
  32. } else {
  33. NSLog(@"createdPath is not of type PanZoomAnimationPath");
  34. }
  35. }
  36. @end

字符串
当在macOS 13/14上运行时,它可以工作并产生正确的输出,正确地向下转换,并且根据指针是否为NULL。
在macOS 11上,如果失败(segfault 11)
下面是堆栈跟踪:

  1. Path: /Users/USER/TestOld.app/Contents/MacOS/TestOld
  2. Identifier: com.shinywhitebox.TestOld
  3. Version: 1.0 (1)
  4. Code Type: X86-64 (Native)
  5. Parent Process: bash [62750]
  6. User ID: 504
  7. Date/Time: 2023-09-28 20:50:19.100 +1300
  8. OS Version: macOS 11.7.8 (20G1351)
  9. Report Version: 12
  10. Anonymous UUID: 86319E29-4169-27B2-C19A-1C7378984637
  11. Sleep/Wake UUID: D03F977E-2B4B-443D-8EB9-8478E632ECBD
  12. Time Awake Since Boot: 790000 seconds
  13. Time Since Wake: 1500 seconds
  14. System Integrity Protection: enabled
  15. Crashed Thread: 0 Dispatch queue: com.apple.main-thread
  16. Exception Type: EXC_BAD_ACCESS (SIGSEGV)
  17. Exception Codes: KERN_INVALID_ADDRESS at 0x0000000007e6b008
  18. Exception Note: EXC_CORPSE_NOTIFY
  19. Termination Signal: Segmentation fault: 11
  20. Termination Reason: Namespace SIGNAL, Code 0xb
  21. Terminating Process: exc handler [63209]
  22. VM Regions Near 0x7e6b008:
  23. -->
  24. __TEXT 107e6b000-107e73000 [ 32K] r-x/r-x SM=COW /Users/*/TestOld.app/Contents/MacOS/TestOld
  25. Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
  26. 0 libc++abi.dylib 0x00007fff20543d16 __dynamic_cast + 393
  27. 1 com.shinywhitebox.TestOld 0x0000000107e6ea2f -[AppDelegate applicationDidFinishLaunching:] + 255
  28. 2 com.apple.CoreFoundation 0x00007fff2066d463 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
  29. 3 com.apple.CoreFoundation 0x00007fff20708ed9 ___CFXRegistrationPost_block_invoke + 49
  30. 4 com.apple.CoreFoundation 0x00007fff20708e54 _CFXRegistrationPost + 496
  31. 5 com.apple.CoreFoundation 0x00007fff2063e6ce _CFXNotificationPost + 736
  32. 6 com.apple.Foundation 0x00007fff213b1c18 -[NSNotificationCenter postNotificationName:object:userInfo:] + 59
  33. 7 com.apple.AppKit 0x00007fff22e88d80 -[NSApplication _postDidFinishNotification] + 305
  34. 8 com.apple.AppKit 0x00007fff22e88ad2 -[NSApplication _sendFinishLaunchingNotification] + 208
  35. 9 com.apple.AppKit 0x00007fff22e85c71 -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 541
  36. 10 com.apple.AppKit 0x00007fff22e858c7 -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 665
  37. 11 com.apple.Foundation 0x00007fff213dd366 -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 308
  38. 12 com.apple.Foundation 0x00007fff213dd1d6 _NSAppleEventManagerGenericHandler + 80
  39. 13 com.apple.AE 0x00007fff2645b853 0x7fff2644f000 + 51283
  40. 14 com.apple.AE 0x00007fff2645af6e 0x7fff2644f000 + 49006
  41. 15 com.apple.AE 0x00007fff26453cd3 aeProcessAppleEvent + 448
  42. 16 com.apple.HIToolbox 0x00007fff288d3012 AEProcessAppleEvent + 54
  43. 17 com.apple.AppKit 0x00007fff22e7ff70 _DPSNextEvent + 2046
  44. 18 com.apple.AppKit 0x00007fff22e7e2a5 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1364
  45. 19 com.apple.AppKit 0x00007fff22e705c9 -[NSApplication run] + 586
  46. 20 com.apple.AppKit 0x00007fff22e447cc NSApplicationMain + 816
  47. 21 com.shinywhitebox.TestOld 0x0000000107e6e81f main + 47
  48. 22 libdyld.dylib 0x00007fff2059af3d start + 1
  49. Thread 1:: Dispatch queue: com.apple.CFVolumeObserver.0x7fad90e1fe60


从macOS 14运行时,您将获得:

  1. Ptr from _animationPath: 0x60000039a7d0
  2. Animation path ptr is: 0x60000039a7d0. Is it valid: 1
  3. Success!


macOS 11:

  1. 2023-09-28 21:10:10.997 TestOld[63675:8470300] Ptr from _animationPath: 0x7fe879e2c3b0
  2. 2023-09-28 21:10:10.997 TestOld[63675:8470300] Animation path ptr is: 0x7fe879e2c3b0. Is it valid: 1
  3. Segmentation fault: 11


我也试过重新编译旧的库,但没有成功。它在不同的dynamic_cast上崩溃。
我不是ABI相关问题的Maven,所以在这里寻求任何帮助/指针。

20jt8wwn

20jt8wwn1#

这是由于Xcode 15中的链接器发生了变化。它在发行说明中有记录,但如果你不知道去哪里找,很容易错过,也不容易找到。你可能会认为当你的项目包含受影响的符号并针对旧的macOS版本时,他们会添加一个构建时警告。
无论如何,发行说明还记录了一个解决方案:
在iOS 14/macOS 12或更早版本上,使用弱定义符号的二进制文件在运行时崩溃。由于C项目广泛使用弱符号,这主要影响C项目。(114813650)(FB 13097713)

解决方法:将最低部署目标提升到iOS 15、macOS 12、watchOS 8或tvOS 15,或者-Wl,-ld_classic添加到OTHER_LDFLAGS构建设置中。

(强调我的)

相关问题