2013-04-21 59 views
27

我想在OSX Mountain Lion上使用clang address sanitizer,因为Valgrind在此平台上有内存检查问题。 但是,当我在编译时有-fsanitize=address(像我这个页面上看见:http://clang.llvm.org/docs/AddressSanitizer.html),我得到这个错误:clang: error: argument unused during compilation: '-fsanitize=address'Clang在OS X上的地址Sanitizer

所以,我的问题是如何使用锵地址消毒剂在OS X?如果我不能使用它,我可以使用什么工具?

我用Xcode下载了clang,它是最新的。 (也许这个版本并没有消毒地址与其建立)

回答

6

据有关人士(特别是如果你从Apple's Open Source Siteclang-425.0.24包,测试文件src/tools/clang/test/Driver/darwin-asan-nofortify.c

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

,当然,还有是使用-faddress-sanitizer一个错误,所以它看起来像在OS X,你将需要建立,以获得地址消毒剂从更近的源铛自己。

命令行选项

尝试使用-faddress-sanitizer而不是-fsanitize=address。苹果公司的版本似乎基于CLANG的旧版本,如果你运行clang --help,这个版本中的杀菌剂都是这种形式。

+4

我得到了一个错误太:'铛:错误:不支持的选项'-faddress-sanitizer'。然而,在'clang --help'中,我可以看到这个选项 – Guillaume 2013-04-21 11:17:55

+0

@gaige:问题在于苹果正在部署**旧的**版本的Clang,它仍然使用旧的“-faddress-sanitizer”。稍后加入新的'-fsanitize = address',当添加其他杀菌剂时。 – 0xC0000022L 2014-02-25 14:43:09

+0

@ 0xC0000022L对不起,当我说“你需要从一个更新的源代码构建clang”时,我认为我在上面提到了这点。无可否认,它并没有明确表示苹果的版本较旧,但它确实建议从较新版本开始构建。我会更新语言以使其更清楚。 – gaige 2014-02-25 20:20:46

12

地址消毒剂已添加的新功能在Xcode 7

使用Runtime Sanitization>Enable Address Sanitizer标志在你的计划,启用该选项。然后

git会显示此更改您的.xcscheme文件:

enableAddressSanitizer = "YES" 

New Features in Xcode 7文件:

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.