Monday, October 17, 2016

Undocumented Xcode Sanitizer Settings

Peter Steinberger (tweet):

Here’s what I gobbled together based on Google; mostly thanks to WebKit being open source. (I only tested CLANG_ADDRESS_SANITIZER so far, but based on Google the other flags should work as well).

There are also CLANG_THREAD_SANITIZER and CLANG_MEMORY_SANITIZER. The address sanitizer seems most useful, though:

Since this flag is undocumented it might change without warning, and there are some hints that this might be renamed to ENABLE_ADDRESS_SANITIZER.

Using this flag makes it simpler to dynamically switch this on or off without having to create a separate Xcode configuration that would be much harder to maintain, and you can configure your CI to run tests both with and without ASan to both have a great assurance of memory correctness and testing the binary that you actually ship to customers.

Update (2017-02-18): Peter Steinberger:

The ASAN_OPTIONS hack is no longer needed, this now works as expected in Xcode 8.2+

4 Comments RSS · Twitter


While it is great to have Xcode build settings to enable sanitizer, all theses options can be as easily be enabled using additional compiler flags. So if you are afraid the build settings may change in the futur, just read the clang doc and use the corresponding flags.


@Jean-Daniel

Correct. However then you're also responsible for manually linking the required runtime libraries to your app, and it quickly gets tricky - I tried that at first.


[…] Running tests with Clang Address Sanitizer; Undocumented Xcode Sanitizer Settings […]


[…] Running tests with Clang Address Sanitizer; Undocumented Xcode Sanitizer Settings […]

Leave a Comment