dyld: Symbol not found: ___darwin_check_fd_set_overflow

When I build my app in XCode 12.4 target device iOS 13.3, it will crash at launch with error message below. But works fine target device simulator.

dyld: Symbol not found: ___darwin_check_fd_set_overflow Referenced from: /private/var/containers/Bundle/Application/EBA2D824-6239-4E6A-BD10-1A3F945AECA3/MyAPP.app/MyAPP Expected in: /usr/lib/libSystem.B.dylib in /private/var/containers/Bundle/Application/EBA2D824-6239-4E6A-BD10-1A3F945AECA3/MyAPP.app/MyAPP dyld: launch, loading dependent libraries DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib:/Developer/Library/PrivateFrameworks/GPUTools.framework/libglInterpose.dylib:/usr/lib/libMTLCapture.dylib

The crash can be solved by weak linking to libSystem.B.dylib, but I just wonder why this happen. Any clue is appreciated

1 answer

  • answered 2021-06-24 00:24 bdash

    __darwin_check_fd_set_overflow, which is used as part of the implementation of FD_SET and related macros, is only available on iOS 14 and above. It is declared with an availability annotation that should result in it being weakly linked if you build with your deployment target set to a pre-iOS 14 version. This allows it to be used in code built for earlier iOS versions as the code that uses it checks at runtime whether a definition was found or not.

    int __darwin_check_fd_set_overflow(int, const void *, int) __API_AVAILABLE(macosx(11.0), ios(14.0), tvos(14.0), watchos(7.0));
    

    If your deployment target is not set to an older version then the symbol will not be weakly linked and you will see an error at runtime when the dynamic loader fails to find the symbol within libSystem as it expects.