2013-04-21 57 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.