Address Sanitizer

时间:2017-04-21 14:53:15

标签: c++ address-sanitizer

在一个爱好项目中,我使用地址清理程序(-fsanitize = address) 和g ++ - 6(Homebrew GCC 6.3.0_1)6.3.0。

我收到一个我不理解的错误,即:

==94266==AddressSanitizer CHECK failed: ../../../../libsanitizer/asan/asan_globals.cc:146 "((AddrIsAlignedByGranularity(g->size_with_redzone))) != (0)" (0x0, 0x0) #0 0x10b60cd3d in __asan::AsanCheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (libasan.3.dylib+0x5dd3d) #1 0x10b612be3 in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (libasan.3.dylib+0x63be3)

在玩了一会儿之后,我注意到我在两个不同的类中使用正则表达式,如果我删除其中任何一个,问题就会消失。我想了解为什么以及我能做些什么。

所以,我的下一次尝试是建立一个问题的最小例子,我想出了以下内容:

// a.cpp

#include <iostream>
#include <regex>
#include <string>

using namespace std;

void a(const std::string &s)
{
    regex re_a("foo (.+)");
    smatch pieces;

    if (regex_match(s, pieces, re_a))
    {
        cout << "foo with " << pieces[1].str() << endl;
    }
}

// m.cpp
#include <string>
#include <regex>

void a(const std::string &s);

int main(int argc, char** argv)
{
    std::regex re("123");

    a("foo test 123");
}

如果我使用“g ++ - 6 -fsanitize = address a.cpp m.cpp”编译然后运行“./a.out”,程序将永远挂起,而“g ++ - 6 a.cpp m.cpp”接着是“./a.out”,按预期工作。

这不是我想在这里展示的(因为我没有得到AddressSanitizer CHECK失败错误),但问题可能是相关的?

我确实也看到了其中一些,只是为了完成: ld: warning: direct access in function '__GLOBAL__sub_D_00099_0_a.cpp' from file '/var/folders/lq/t18hc5bn0c5bxf7h7nn609f40000gp/T//ccTC4rgj.o' to global weak symbol 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > std::__cxx11::regex_traits<char>::lookup_collatename<char const*>(char const*, char const*) const::__collatenames' from file '/var/folders/lq/t18hc5bn0c5bxf7h7nn609f40000gp/T//ccTC4rgj.o' means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.

编辑:忘了提一个细节我也注意到了。如果我在m.cpp中注释掉regex var're',问题也会完全消失。

感谢您的帮助!

0 个答案:

没有答案