地址防御器崩溃GCC 4.8

时间:2012-11-26 22:16:01

标签: gcc segmentation-fault instrumentation memory-corruption

我刚刚尝试了GCC 4.8的新功能AddressSanitizer。

该计划

#include <iostream>
int main(int argc, const char * argv[], const char * envp[]) {
    int *x = nullptr;
    int y = *x;
    std::cout << y << std::endl;
    return 0;
}

使用

编译查找
g++-4.8 -std=gnu++0x -g -fsanitize=address -fno-omit-frame-pointer -Wall ~/h.cpp -o h

但是当我运行程序时,我得到了

ASAN:SIGSEGV
=================================================================
==7531== ERROR: AddressSanitizer crashed on unknown address 0x000000000000 (pc 0x000000400aac sp 0x7fff11ce0fd0 bp 0x7fff11ce1000 T0)
AddressSanitizer can not provide additional info.
    #0 0x400aab (/home/per/h+0x400aab)
    #1 0x7fc432e1b76c (/lib/x86_64-linux-gnu/libc-2.15.so+0x2176c)
Stats: 0M malloced (0M for red zones) by 0 calls
Stats: 0M realloced by 0 calls
Stats: 0M freed by 0 calls
Stats: 0M really freed by 0 calls
Stats: 0M (0 full pages) mmaped in 0 calls
  mmaps   by size class: 
  mallocs by size class: 
  frees   by size class: 
  rfrees  by size class: 
Stats: malloc large: 0 small slow: 0

这似乎是一种报告内存错误的错误方法。我错过了一些编译或链接标记吗?

2 个答案:

答案 0 :(得分:4)

这是报告NULL解除引用的预期方式。 您可以通过asan_symbolize.py(应存在于GCC树中)运行程序输出,以获取源文件中的符号名称和行号。

答案 1 :(得分:2)

我在gcc 4.8和4.9上找不到任何asan_symbolize.py。 我在https://code.google.com/p/address-sanitizer/issues/detail?id=223

添加了一个解决方法