Two problems with targeted disinfectant
In a hobby project I am using sanitizer for address (-fsanitize = address) and g ++ - 6 (Homebrew GCC 6.3.0_1) 6.3.0.
I have an error that I don't understand, which is:
==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)
After playing around for a while, I noticed that I am using regex in two different classes and if I remove one of them the problem goes away. I want to understand why and what I can do about it.
So my next attempt is to create a minimal example of the problem, and I came up with the following:
// 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");
}
If I compile with "g ++ - 6 -fsanitize = address a.cpp m.cpp" and then run "./a.out" the program freezes forever, and "g ++ - 6 a.cpp m.cpp" and then " ./a.out "works as expected.
This is not exactly what I wanted to demonstrate here (since I am not getting the AddressSanitizer CHECK error), but could the problems be related?
I see some of them too, just to be complete:
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.
edit: Forgot to mention one detail that I also noticed. If I comment out the regex var 're' in m.cpp the problem disappears completely as well.
Thanks for any help!
source to share
No one has answered this question yet
Check out similar questions: