是否有人使用Address-Sanitizer(称为asan或-fsanitize =地址)为iOS工作?

是否有人使用Address-Sanitizer(称为asan或-fsanitize =地址)为iOS工作?,第1张

概述地址 – 消毒剂 https://code.google.com/p/address-sanitizer/wiki/AddressSanitizer 我已经编译了自己的llvm(非常简单的编译)因为apple的llvm不支持这个功能. 我已经测试了mac命令行程序的clang,它可以工作(但没有显示源代码行). 对于iOS,仍然存在一些问题: >编译模拟器版本:预编译头的报告错误: In file 地址 – 消毒剂 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,你可以自己修改它,它没有魔法,你只需要纠正一些路径就行了.

总结

以上是内存溢出为你收集整理的是否有人使用Address-Sanitizer(称为asan或-fsanitize =地址)为iOS工作?全部内容,希望文章能够帮你解决是否有人使用Address-Sanitizer(称为asan或-fsanitize =地址)为iOS工作?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1004737.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存