解决消毒剂警告

时间:2016-04-07 11:51:11

标签: clang sanitizer address-sanitizer

几天后,我在Xcode 7.3中启动Address Sanitizer时出现以下问题。当Sanitizer发现问题(实际上是由文件抑制)时,打印到Xcode控制台的错误消息:

  

== 13392 ==警告:不能在fd 55写入符号化器

     

== 13392 ==警告:不能在fd 55写入符号化器

     

== 13392 ==警告:不能在fd 55写入符号化器

     

== 13392 ==警告:不能在fd 55写入符号化器

     

== 13392 ==警告:无法使用并重新启动外部符号器!

我在存储库中找到了错误消息但仍无法解释发生了什么。显然内部写入功能失败但我不知道是什么导致这种情况。有什么想法吗?

https://github.com/Microsoft/compiler-rt/blob/master/lib/sanitizer_common/sanitizer_symbolizer_process_libcdep.cc#L100

1 个答案:

答案 0 :(得分:3)

您的路径中缺少ASAN。以下是在Xcode外部完成的,看看我是否可以显示错误,如果路径未定义则很容易。我的猜测是XCode无法找到它所在的位置,或者在下面的情况下,ASAN路径未定义。

当您尝试此操作时,如果您从路径中添加并删除它,则错误消失但行号也会消失,即如果您想再次看到实际的错误消息,则需要使用

unset ASAN_SYMBOLIZER_PATH

ASAN_SYMBOLIZER_PATH=

按如下方式创建一个c程序......

int main(void){
    int a[3];
    a[3] = 4;
    return 0;
}

编译它,请暂时忽略警告......

gcc -std=c11 -Wall -g3 -fno-omit-frame-pointer -fsanitize=address broken_asan_test.c
./a.out

你应该看到这样的东西......

=================================================================
==29192==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fff5ad1052c at pc 0x000104eefe78 bp 0x7fff5ad104f0 sp 0x7fff5ad104e8
WRITE of size 4 at 0x7fff5ad1052c thread T0
    #0 0x104eefe77 in atos[29193]: [fatal] 'pid_for_task' failed: (os/kern) failure (5) (+0x100000e77)
==29192==WARNING: Can't write to symbolizer at fd 3
    #1 0x7fff940495ac in atos[29206]: [fatal] 'pid_for_task' failed: (os/kern) failure (5) (+0x35ac)
    #2 0x0  (<unknown module>)

注意这一行

==29192==WARNING: Can't write to symbolizer at fd 3

更改以将符号程序添加到您的路径...

export ASAN_SYMBOLIZER_PATH=/usr/local/Cellar/llvm/3.6.2/bin/llvm-symbolizer

并且错误消失......

=================================================================
==29312==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fff55ac450c at pc 0x00010a13be78 bp 0x7fff55ac44d0 sp 0x7fff55ac44c8
WRITE of size 4 at 0x7fff55ac450c thread T0
    #0 0x10a13be77 in main (/git/ghub/doc/c/./a.out+0x100000e77)
    #1 0x7fff940495ac in start (/usr/lib/system/libdyld.dylib+0x35ac)
    #2 0x0  (<unknown module>)