2013-06-28 36 views
4

Address-Sanitizer https://code.google.com/p/address-sanitizer/wiki/AddressSanitizer是否有人在iOS上使用Address-Sanitizer(称为asan或-fsanitize = address)?

我已经编译了我自己的llvm(很直接的编译),因为apple的llvm不支持这个函数。

我已经测试了mac命令行程序的clang,它的工作原理(但没有显示源代码行)。

适用于iOS,仍有一些问题:

  • 编译模拟器版本:预编译头报错:

In file included from /Users/fluke/Documents/projects/tmp/testAsanNoARC/testAsanNoARC/testAsanNoARC-Prefix.pch:12: In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h:9: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAccelerometer.h:53:24: error: 'UIAccelerometer' is unavailable: not available on OS X - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration NS_DEPRECATED_IOS(2_0, 5_0); ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAccelerometer.h:33:12: note: declaration has been explicitly marked unavailable here @interface UIAccelerometer : NSObject { ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAccelerometer.h:53:71: error: 'UIAcceleration' is unavailable: not available on OS X - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration NS_DEPRECATED_IOS(2_0, 5_0); ...

  • 编译器版本,它报告缺乏libarc(但实际上我不启用ARC)

ld: file not found: /Users/fluke/Documents/tools/asan/Debug+Asserts/lib/arc/libarclite_iphoneos.a clang: error: linker command failed with exit code 1 (use -v to see invocation)

  • 所以我尝试使用它作为一个单独的库 - 只是新的lib目标和使用我自己的铛,而主要目标仍然使用苹果的llvm。程序编译(可能需要链接到构建的llvm中的asan dylib),但不起作用,因为我们需要在我们的程序入口之前加载。

谁有这样做的经验?

回答

1

我终于在朋友的帮助下获得了asan的工作。

  • 将所有c/C++代码移动到xcode项目的新目标(cocoa lib目标)。使项目生成并正常运行,因为它是一个单独的应用程序,然后将单独的c/C++代码添加到lib中。

  • build llvm。编号http://blog.wadetregaskis.com/tot-clang-llvm-in-xcode/

  • 给xcode添加一个clang选项。为了方便您可以使用此模板:http://blog.wadetregaskis.com/tot-clang-llvm-in-xcode/。在上一步中改变clang路径。

  • 更改xcode中的lib目标以使用新的clang/llvm,添加一个cflag -fsanitize =地址。然后构建,如果某些API(如opengl/system video函数)不被支持,那么你可以把它放到app项目中,你的clang不支持编译它。

  • 如果你通过编译,它将报告__asan_xxx功能的联动问题,添加一个名为“libclang_rt.asan_osx_dynamic.dylib”到应用程序的联动依赖lib和它位于您的LLVM的 ./Debug+Asserts/ lib/clang/3.4/lib/darwin /文件夹。

  • 然后您需要指定输出文件,否则报告将转到带有颜色字符的标准输出,这会让您感到困惑。把这行写入main.m:

    extern void __sanitizer_set_report_path(const char * path); __sanitizer_set_report_path(“/ tmp/asan。txt“);

  • 然后你可以让你的程序出现一些内存错误,比如在释放或堆缓冲区溢出后使用,asan会让程序在第一个错误中崩溃,使用/tmp/asan.txt.number报告生成

  • 你几乎在那里,报告显示错误堆栈和文件的偏移量,你需要做的只是多一步 - 将地址解析为代码行,你需要找到你的DWARF文件项目,然后使用名为asan_symbolize.py的工具来生成带有源代码行的新报告,您可以使用asan_symbolize.py,然后获取并修复此脚本以使用DWARF文件,右键单击您的生产应用程序即可找到DWARF文件,在Finder中选择show,然后升级以获得iphone模拟器目录ectory,打开名为your.app.dSYM的包,然后您可以在./Content/Resources/DWARF中获得DWARF。

,我这里就不一一列举的唯一的事情是修改asan_symbolize.py,你可以通过你自己修改它,它没有魔法,你只是纠正一些路径,它会工作。

0

原帖中列出的错误与ASan本身无关。当然,如果没有-sanitize = address标志,你会得到它们。 目前还不支持针对iOS构建和运行,但是您可以构建针对iOS模拟器的应用程序 - 它应该可以正常工作。 请不要犹豫,以进一步问题[email protected]

相关问题