1 llvm
我想知道如何在内存访问时禁用地址清理器插入检查功能。据我所知,地址清理程序通过插入检查功能来检测访问权限或缓冲区溢出等。[(https://github.com/llvm/llvmproject/blob/main/llvm/lib/Transforms/Instrumentation/AddressSanitizer .cpp)]
我想禁用该地址清理程序插入检查功能。是否有任何标志可以禁用插入检查功能?或者,如何禁用地址清理代码进行检查?
谢谢你!祝你今天过得愉快 :)
我希望检查 AddressSanitizer.cpp 中的代码行
您无法独立禁用检测的不同部分- 检测是整体完成的,既检查内存访问又维护相关元数据。如果您想跟踪类似于 Address Sanitizer 的元数据,但不进行检查,则必须编写一个新的 sanitizer 传递来实现它。
但是,您可以更精细地禁用 Address Sanitizer。例如,您可以将文件链接在一起,其中有些文件已编译-fsanitize=address,有些则未编译。您还可以使用函数属性禁用它:
您可以在此处查看此操作: https://cpp.compiler-explorer.com/z/rj95nKMY8
#include <iostream>
__attribute__((no_sanitize("address")))
int uninstrumented_access(int* array, int index) {
return array[index];
}
int access(int* array, int index) {
return array[index];
}
int main() {
int *array = new int[10]();
(void)uninstrumented_access(array, 42);
std::cerr << "No ASan error from un-instrumented access due to attribute!\n";
(void)access(array, 42);
std::cerr << "No ASan error even from instrumented access!\n";
}
Run Code Online (Sandbox Code Playgroud)
此处uninstrumented_access禁用所有 ASan 检查。如果您查看 Compiler Explorer 输出,您会发现该函数没有 ASan 错误,但它的正常版本确实会产生错误。
| 归档时间: |
|
| 查看次数: |
1477 次 |
| 最近记录: |