27

I would like to use clang address sanitizer on OSX Mountain Lion, because Valgrind have problems with memory check on this platform. But when I had the -fsanitize=address during the compilation time (like I see on this page : http://clang.llvm.org/docs/AddressSanitizer.html), I got this error : clang: error: argument unused during compilation: '-fsanitize=address'

So, my question is how to use Clang Address Sanitizer on OS X ? If I can't use it, what tool I can use it?

I have download clang with Xcode and it's up-to-date. (maybe this version has not address sanitizer build with it)

3 Answers 3

13

Address Sanitizer has been added as a new feature in Xcode 7.

Use the Runtime Sanitization > Enable Address Sanitizer flag in your scheme to enable the option.

git will then shown this change to your .xcscheme file:

enableAddressSanitizer = "YES"

From the New Features in Xcode 7 document:

Address Sanitizer. Xcode 7 can build your app with instrumentation designed to catch and debug memory corruption using the address sanitizer.

Objective-C and C code is susceptible to memory corruption issues such as stack and heap buffer overruns and use-after-free issues. When these memory violations occur, your app can crash unpredictably or display odd behavior. Memory corruption issues are difficult to track down because the crashes and odd behavior are often hard to reproduce and the cause can be far from the origin of the problem.

Enable Address Sanitizer

You enable the address sanitizer in the build scheme. Once enabled, added instrumentation is built into the app to catch memory violations immediately, enabling you to inspect the problem right at the place where it occurs. Other diagnostic information is provided as well, such as the relationship between the faulty address and a valid object on the heap and allocation/deallocation information, which helps you pinpoint and fix the problem quickly.

Address sanitizer is efficient—fast enough to be used regularly, as well as with interactive applications. It is supported on OS X, in the Simulator, and on iOS devices.

Sign up to request clarification or add additional context in comments.

Comments

11

AddressSanitizer support in Xcode isn't fully fledged yet. Please consider using the trunk Clang (see http://code.google.com/p/address-sanitizer/wiki/HowToBuild for build instructions)

Comments

6

According to the source (in particular if you grab the clang-425.0.24 bundle from Apple's Open Source Site, the test file src/tools/clang/test/Driver/darwin-asan-nofortify.c:

// rdar://11496765, rdar://12417750
// -faddress-sanitizer is not currently supported.
// XFAIL: *

And, of course, there is an error using -faddress-sanitizer, so it looks like under OS X, you'll need to build clang yourself from more recent source in order to get the address sanitizer.

Command line option

Try using -faddress-sanitizer instead of -fsanitize=address. Apple's version appears to be based on an older version of CLANG, and if you run clang --help, the sanitizers are all of this form in this version.

5 Comments

I got an error too : clang: error: unsupported option '-faddress-sanitizer'. However, in clang --help I can see this option
@gaige: the problem is that Apple is deploying an older version of Clang, which used the old -faddress-sanitizer still. The newer -fsanitize=address joined later, when the other sanitizers where added.
@0xC0000022L Sorry, I thought I was making that point above when I said "you'll need to build clang yourself from a more recent source". Admittedly, it doesn't say explicitly that Apple's version is older, but it does suggest building from a newer version. I'll update the language to make it more clear.
@gaige: my main point was concerning this sentence For some reason, Apple's version appears to have changed that from what is in the CLANG documents which seems to suggest that Apple's Clang is newer. No offense intended, but it confused me and I thought a comment would be in order.
Xcode 5.1.1 says clang: error: argument '-faddress-sanitizer' is deprecated, use '-fsanitize=address' instead. However, it still doesn't appear to support fsanitize=address: clang: error: unsupported argument 'address' to option 'fsanitize='

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.