是否有人获得Address-Sanitizer(称为asan或-fsanitize = address)适用于iOS? [英] Is anyone get Address-Sanitizer (known as asan or -fsanitize=address) work for iOS?

查看:3074
本文介绍了是否有人获得Address-Sanitizer(称为asan或-fsanitize = address)适用于iOS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Address-Sanitizer https://code.google.com/p/address -sanitizer / wiki / AddressSanitizer



我编译了我自己的llvm(非常简单的编译),因为苹果的llvm不支持这个功能。



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



,仍然有一些问题:




  • 编译模拟器版本:预编译标题的报告错误:




在/Users/fluke/Documents/projects/tmp/testAsanNoARC/testAsanNoARC/testAsanNoARC-Prefix.pch:12中包含的文件中:
从/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:错误:UIAccelerometer不可用:在OS X上不可用
- (void)加速度计:(UIAccelerometer *)加速度计didAccelerate:(UIAcceleration *)加速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:声明已明确标记为不可用
@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:错误:UIAcceleration不可用:在OS X上不可用X
- ( void)加速度计:(UIAccelerometer *)加速度计didAccelerate:(UIAcceleration *)加速度NS_DEPRECATED_IOS(2_0,5_0);
...





  • 编译设备版本,报告缺少libarc我不启用ARC)




ld:未找到文件:/ Users / fluke / Documents / tools / asan / Debug + Asserts / lib / arc / libarclite_iphoneos.a
clang:error:linker命令失败,退出代码1(使用-v查看调用)





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



谁有这样的经验?

解决方案

我终于得到asan工作给我的朋友的帮助。




  • 将所有c / c ++代码移动到xcode项目的新目标(可可目标)。使项目构建和运行正常,因为它是一个单独的应用程序之前单独的c / c ++代码到lib。


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


  • 在xcode中添加一个clang选项。为方便起见,您可以使用此模板: http://blog.wadetregaskis.com/ tot-clang-llvm-in-xcode /


  • 更改xcode中的lib目标以使用新的clang / llvm,添加一个cflag - fsanitize =地址。然后构建,如果一些api(如opengl /系统视频功能)被报告不支持,那么你可以把它放入app项目,你的clang不支持编译它。


  • 如果你通过编译,它会报告__asan_xxx函数的链接问题,添加一个liblibclang_rt.asan_osx_dynamic.dylib到应用程序的连接依赖,它位于你的llvm的
    。 /Debug+Asserts/lib/clang/3.4/lib/darwin/文件夹。


  • 那么你需要指定out文件,到stdout与颜色的字符,这将困惑你。把这行写入你的main.m:



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


  • 那么你可以使你的程序出现一些内存错误,缓冲器溢出。 asan会让程序在第一个错误中崩溃,并生成/tmp/asan.txt.number报告。


  • show的错误堆栈与文件的偏移量。所有你需要做的是一个更多的步骤 - 解析地址到代码行。您需要找到您的项目的DWARF文件,然后使用一个名为asan_symbolize.py的工具生成带有源代码行的新报告。您可以goole asan_symbolize.py然后获取并修复此脚本以使用DWARF文件。你可以找到DWARF文件,右键单击你的生产应用程序,选择show in finder,然后到一个级别获得iphone模拟器目录,打开包名为your.app.dSYM,然后你可以得到DWARF在./Content / Resources / DWARF。




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


Address-Sanitizer https://code.google.com/p/address-sanitizer/wiki/AddressSanitizer

I have compile my own llvm (pretty straight forward compiling) because apple's llvm not support this function.

I have tested the clang for mac command line program, it works (but without showing the line the sourcecode).

for iOS, there is still some problems:

  • compile simulator version : report error for pre-compiled header:

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); ...

  • compile for device version, it reports lack of libarc (but actually I don't enable 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)

  • so I try use it for a separate lib - just new a lib target and use my own clang while the main target still use apple's llvm. the program compiles ( may need to link to the asan dylib in the built llvm), but not work because I asan need to be loaded before our program entry.

who have experience with doing this?

解决方案

I finally get the asan work for me with my friend's help.

  • move all c/c++ code to a new target (cocoa lib target) of xcode project. make the project build and run normally as it was a single app before separate c/c++ codes to a lib.

  • build llvm. ref http://blog.wadetregaskis.com/tot-clang-llvm-in-xcode/

  • add a clang option to xcode. for convenient you can use this template: http://blog.wadetregaskis.com/tot-clang-llvm-in-xcode/ . change clang path to the clang just build in the previous step.

  • change the lib target in the xcode to use the new clang/llvm, add a cflag -fsanitize=address. then build, if some api (such as opengl/system video function) is reported not supported, then you can put it into the app project, your clang doesn't support compiling it.

  • if you pass the compile, it will report linkage problem of __asan_xxx function, add a lib called "libclang_rt.asan_osx_dynamic.dylib" to the app's linkage dependency, and it's located in your llvm's ./Debug+Asserts/lib/clang/3.4/lib/darwin/ folder.

  • then you need to specified the out put file or else the report will goes to the stdout with color characters which will confuse you. put this lines into your main.m:

    extern void __sanitizer_set_report_path(const char *path); __sanitizer_set_report_path("/tmp/asan.txt");

  • then you can make your program some memory error such as use after free or heap buffer overflow. the asan will let the program crash in the first error, with /tmp/asan.txt.number report generated.

  • you're almost there, the report show's the error stack with the file's offset. all you need to do is one more step - resolve the address to code line. you need to find the DWARF file of your project, then use a tool called asan_symbolize.py to generate the new report with source code line. you can goole asan_symbolize.py then get and fix this script to use the DWARF file. you can find the DWARF file by right click your production app, select show in finder, then to up a level to get the iphone simulator directory, open the bundle called your.app.dSYM, then you can get the DWARF in ./Content/Resources/DWARF.

The only thing that I haven't list here is the modified asan_symbolize.py, you can modify it by your self, it has no magic, you just correct some path and it will work.

这篇关于是否有人获得Address-Sanitizer(称为asan或-fsanitize = address)适用于iOS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆