加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

是否有人使用Address-Sanitizer(称为asan或-fsanitize =地址)为i

发布时间:2020-12-14 17:22:31 所属栏目:百科 来源:网络整理
导读:地址 – 消毒剂 https://code.google.com/p/address-sanitizer/wiki/AddressSanitizer 我已经编译了自己的llvm(非常简单的编译)因为apple的llvm不支持这个功能. 我已经测试了mac命令行程序的clang,它可以工作(但没有显示源代码行). 对于iOS,仍然存在一些问题
地址 – 消毒剂 https://code.google.com/p/address-sanitizer/wiki/AddressSanitizer

我已经编译了自己的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 – 只是新的lib目标并使用我自己的clang而主要目标仍然使用apple的llvm.程序编译(可能需要链接到构建的llvm中的asan dylib),但不能正常工作,因为我需要在程序输入之前加载.

有这方面经验的人?

解决方法

在朋友的帮助下,我终于得到了asan的工作.

>将所有c / c代码移动到xcode项目的新目标(cocoa lib target).使项目构建并正常运行,因为它是一个单独的应用程序,然后单独的c / c代码到lib.
>构建llvm. ref http://blog.wadetregaskis.com/tot-clang-llvm-in-xcode/
>为xcode添加一个clang选项.为方便起见,您可以使用此模板:http://blog.wadetregaskis.com/tot-clang-llvm-in-xcode/.将clang路径更改为刚刚在上一步中构建的clang.
>更改xcode中的lib目标以使用新的clang / llvm,添加一个cflag -fsanitize =地址.然后构建,如果报告不支持某些api(例如opengl /系统视频功能),那么你可以把它放到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的工具生成包含源代码行的新报告.你可以goole asan_symbolize.py然后获取并修复此脚本以使用DWARF文件.您可以通过右键单击您的生产应用程序找到DWARF文件,选择show in finder,然后升级到获取iphone模拟器目录,打开名为your.app.dSYM的包,然后您可以在./Content中获取DWARF /资源/侏儒.

我没有在这里列出的唯一的东西是修改过的asan_symbolize.py,你可以自己修改它,它没有魔法,你只需要纠正一些路径就行了.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读