Errors running with ASAN when targeting iOS Devices

I'm unable to run my app with ASAN enabled when targeting a physical iOS device. Simulator targets do work.

With Xcode 12 and an iPad mini 4 running iOS 14 beta 1 I get the following error during app launch


==750==ERROR: AddressSanitizer failed to allocate 0xffffffffff9fc000 (-6307840) bytes at address 2db624000 (errno: 22)
==750==ReserveShadowMemoryRange failed while trying to map 0xffffffffff9fc000 bytes. Perhaps you're using ulimit -v

With Xcode 11.5 and an iPad Air 2 running OS 12.4.1 the error is


==2177==Unable to find a memory range after restricting VM.
==2177==AddressSanitizer CHECK failed: /BuildRoot/Library/Caches/com.apple.xbs/Sources/clangcompilerrt/clang-1103.0.32.62/compiler-rt/lib/asan/asanmac.cc:92 "((0 && "cannot place shadow after restricting vm")) != (0)" (0x0, 0x0)
<empty stack>==2177==AddressSanitizer CHECK failed: /BuildRoot/Library/Caches/com.apple.xbs/Sources/clang
compilerrt/clang-1103.0.32.62/compiler-rt/lib/asan/../sanitizercommon/sanitizermallocmac.inc:143 "((!asaninitisrunning)) != (0)" (0x0, 0x0)
warning: could not execute support code to read Objective-C class data in the process. This may reduce the quality of type information available.
AddressSanitizer report breakpoint hit. Use 'thread info -s' to get extended information about the report.
(lldb) thread info -s
thread #1: tid = 0x1076c2, 0x000000011531e984 libclang
rt.asaniosdynamic.dylib`__asan::AsanDie()

My coworker is able to use ASAN with the same App using iPad Pro 10.5, iPadOS 13.5.1, Xcode 11.5

Are there any configuration changes I need to make to be able to use ASAN on my devices?

Replies

Are there any configuration changes I need to make to be able to use ASAN on my devices?

Unfortunately this sounds like a bug in ASan's runtime. The only configuration change you could do right now unfortunately is to use a different iOS device with a different configuration that avoids this bug (like the iPad Pro used by your co-worker).

I'd really like to get this bug fixed so could you file a report using Feedback assistant (run the Feedback assistant on your mac or visit http://feedbackassistant.apple.com )? Could you include the following in your report:

For each configuration (you listed two in your original post):
  1. Please set the ASAN_OPTIONS environment variable with value verbosity=3 (you can do this in Xcode's scheme editor) and launch your app with ASan in Xcode with debugger attached. Setting the environment variable will cause ASan to print out more information about what it's doing when the app starts. When ASan crashes the debugger should still be attached. In the debugger console type bt all and press enter. This should print the stacktrace of the all the running threads in the program. Please attach the entire output to the report.

  2. Report the Xcode version including the build number (e.g. 12A6159)

  3. Report information about the device (including the OS version and device model name). You can get this information by going to the "Devices and Simulators" window in Xcode (⇧⌘2).

  4. Collect a sysdiagnose from the device and attach it to the report. There are instructions to do this here.

Once you've filed a report on feedback assistant please reply to this post with the feedback number (e.g. FB<number>).

Please let me know if you have any questions.
  • I got this with Xcode Version 12.5 (12E262) run app on iPad (6th generation) Model Number MR7K2CH/A. iOS 14.4.1

    ==1249==AddressSanitizer: libc interceptors initialized

    ==1249==FindDynamicShadowStart, space_size = 0x00005b003fff

    || [0x0002db020000, 0x0002d7ffffff] || HighMem    ||

    || [0x0002db624000, 0x0002db01ffff] || HighShadow ||

    || [0x0002d0024000, 0x0002db623fff] || ShadowGap  ||

    || [0x000280020000, 0x0002d0023fff] || LowShadow  ||

    || [0x000000000000, 0x00028001ffff] || LowMem     ||

    MemToShadow(shadow): 0x0002d0024000 0x0002da0247ff 0x0002db6e4800 0x0002db623fff

    redzone=16

    max_redzone=2048

    quarantine_size_mb=16M

    thread_local_quarantine_size_kb=64K

    malloc_context_size=30

    SHADOW_SCALE: 3

    SHADOW_GRANULARITY: 8

    SHADOW_OFFSET: 0x280020000

    ==1249==ERROR: AddressSanitizer failed to allocate 0xffffffffff9fc000 (-6307840) bytes at address 2db624000 (errno: 22)

    ==1249==ReserveShadowMemoryRange failed while trying to map 0xffffffffff9fc000 bytes. Perhaps you're using ulimit -v

    (lldb) bt all

    thread #1, stop reason = signal SIGABRT

      * frame #0: 0x00000001cffa684c libsystem_kernel.dylib`__pthread_kill + 8

        frame #1: 0x00000001ec3809e8 libsystem_pthread.dylib`pthread_kill + 212

        frame #2: 0x00000001ad50a8f4 libsystem_c.dylib`abort + 100

        frame #3: 0x000000010ff16134 libclang_rt.asan_ios_dynamic.dylib`__sanitizer::Abort() + 64

        frame #4: 0x000000010ff01f58 libclang_rt.asan_ios_dynamic.dylib`__asan::ReserveShadowMemoryRange(unsigned long, unsigned long, char const*) + 244

        frame #5: 0x000000010ff02014 libclang_rt.asan_ios_dynamic.dylib`__asan::InitializeShadowMemory() + 188

        frame #6: 0x000000010ff0143c libclang_rt.asan_ios_dynamic.dylib`__asan::AsanInitInternal() + 336

        frame #7: 0x000000010fef84d4 libclang_rt.asan_ios_dynamic.dylib`wrap_malloc_default_zone + 60

        frame #8: 0x00000001b3bc3814 libsystem_malloc.dylib`__malloc_init + 600

        frame #9: 0x00000001d2a18868 libSystem.B.dylib`libSystem_initializer + 176

        frame #10: 0x000000010fde8810 dyld`ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) + 424

        frame #11: 0x000000010fde8bd8 dyld`ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) + 52

        frame #12: 0x000000010fde3600 dyld`ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 536

        frame #13: 0x000000010fde356c dyld`ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 388

        frame #14: 0x000000010fde356c dyld`ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 388

        frame #15: 0x000000010fde1878 dyld`ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 184

        frame #16: 0x000000010fde1940 dyld`ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 92

        frame #17: 0x000000010fdd2688 dyld`dyld::initializeMainExecutable() + 136

        frame #18: 0x000000010fdd7928 dyld`dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 5216

        frame #19: 0x000000010fdd1208 dyld`dyldbootstrap::start(dyld3::MachOLoaded const*, int, char const**, dyld3::MachOLoaded const*, unsigned long*) + 396

        frame #20: 0x000000010fdd1038 dyld`_dyld_start + 56

    (lldb) 

Add a Comment
Many thanks for the response, I've filed FB7786282.
Thank you for taking the time to file this. We really appreciate it. I've routed your report directly to the developers that work on ASan inside Apple. We will follow up in the Feedback Assistant if we need more information.
I'm facing similar issue when turn on ASN and "Detect use of stack after return" as well (doesn't fails when "detect" is off).
I just run the same base code from Xcode 12 on real iOS14 device and after a while I get the following log:

==3408==ERROR: AddressSanitizer: allocator is out of memory trying to allocate 0x717c5c bytes
==3408==FATAL: AddressSanitizer: internal allocator is out of memory trying to allocate 0x50 bytes

But I don't get it when run from Xcode11.5.1 and iOS13 device.
Is it a bug?
I run into the same problem. Followed the steps from the previous post by Developer Tools Engineer and reported it as FB8994561.
same problem, reported it as FB9070971

Stacktrace:
==9900==AddressSanitizer: libc interceptors initialized
==9900==FindDynamicShadowStart, space_size = 0x00005b003fff
|| [0x0002db020000, 0x0002d7ffffff] || HighMem ||
|| [0x0002db624000, 0x0002db01ffff] || HighShadow ||
|| [0x0002d0024000, 0x0002db623fff] || ShadowGap ||
|| [0x000280020000, 0x0002d0023fff] || LowShadow ||
|| [0x000000000000, 0x00028001ffff] || LowMem ||
MemToShadow(shadow): 0x0002d0024000 0x0002da0247ff 0x0002db6e4800 0x0002db623fff
redzone=16
max_redzone=2048
quarantine_size_mb=16M
thread_local_quarantine_size_kb=64K
malloc_context_size=30
SHADOW_SCALE: 3
SHADOW_GRANULARITY: 8
SHADOW_OFFSET: 0x280020000
==9900==ERROR: AddressSanitizer failed to allocate 0xffffffffff9fc000 (-6307840) bytes at address 2db624000 (errno: 22)
==9900==ReserveShadowMemoryRange failed while trying to map 0xffffffffff9fc000 bytes. Perhaps you're using ulimit -v

(lldb) bt all
  • thread #1, stop reason = signal SIGABRT

frame #0: 0x00000001c880584c libsystem_kernel.dylib__pthread_kill + 8 frame #1: 0x00000001e3d499e8 libsystem_pthread.dylibpthread_kill + 212
frame #2: 0x00000001a63e98f4 libsystem_c.dylibabort + 100 frame #3: 0x000000010e4028c8 libclang_rt.asan_ios_dynamic.dylib__sanitizer::Abort() + 64
frame #4: 0x000000010e3ee918 libclang_rt.asan_ios_dynamic.dylib__asan::ReserveShadowMemoryRange(unsigned long, unsigned long, char const*) + 244 frame #5: 0x000000010e3ee9d4 libclang_rt.asan_ios_dynamic.dylib__asan::InitializeShadowMemory() + 188
frame #6: 0x000000010e3ede7c libclang_rt.asan_ios_dynamic.dylib__asan::AsanInitInternal() + 336 frame #7: 0x000000010e3e5144 libclang_rt.asan_ios_dynamic.dylibwrap_malloc_default_zone + 60
frame #8: 0x00000001ac15d814 libsystem_malloc.dylib__malloc_init + 600 frame #9: 0x00000001cb255870 libSystem.B.dyliblibSystem_initializer + 176
frame #10: 0x000000010e2d4810 dyldImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) + 424 frame #11: 0x000000010e2d4bd8 dyldImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) + 52
frame #12: 0x000000010e2cf600 dyldImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 536
  • frame #13: 0x000000010e2cf56c dyld

ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 388 frame #14: 0x000000010e2cf56c dyldImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 388 frame #15: 0x000000010e2cd878 dyldImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 184
frame #16: 0x000000010e2cd940 dyldImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 92 frame #17: 0x000000010e2be688 dylddyld::initializeMainExecutable() + 136
frame #18: 0x000000010e2c3928 dylddyld::_main(macho_header const*, unsigned long, int, char const, char const, char const**, unsigned long*) + 5216 frame #19: 0x000000010e2bd208 dylddyldbootstrap::start(dyld3::MachOLoaded const*, int, char const**, dyld3::MachOLoaded const*, unsigned long*) + 396
frame #20: 0x000000010e2bd038 dyld`_dyld_start + 56

reported as FB9603464

Getting this problem on Xcode 12 or Xcode 13 on an iPad mini running the GM of iOS 15. Reported as FB9641325.

==423==AddressSanitizer: libc interceptors initialized

==423==FindDynamicShadowStart, space_size = 0x00005b003fff

|| `[0x0002db020000, 0x0002d7ffffff]` || HighMem    ||

|| `[0x0002db624000, 0x0002db01ffff]` || HighShadow ||

|| `[0x0002d0024000, 0x0002db623fff]` || ShadowGap  ||

|| `[0x000280020000, 0x0002d0023fff]` || LowShadow  ||

|| `[0x000000000000, 0x00028001ffff]` || LowMem     ||

MemToShadow(shadow): 0x0002d0024000 0x0002da0247ff 0x0002db6e4800 0x0002db623fff

redzone=16

max_redzone=2048

quarantine_size_mb=16M

thread_local_quarantine_size_kb=64K

malloc_context_size=30

SHADOW_SCALE: 3

SHADOW_GRANULARITY: 8

SHADOW_OFFSET: 0x280020000

==423==ERROR: AddressSanitizer failed to allocate 0xffffffffff9fc000 (-6307840) bytes at address 2db624000 (errno: 22)

==423==ReserveShadowMemoryRange failed while trying to map 0xffffffffff9fc000 bytes. Perhaps you're using ulimit -v

dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=@executable_path/Frameworks/libclang_rt.asan_ios_dynamic.dylib:/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib