我正在尝试测试 gcc 的 -fsanitize=thread 的使用情况,它抱怨意外的内存映射,也许内核中可能发生了一些变化,这就是它的原因。我能做些什么来让它发挥作用吗?
这就是我正在做的...
mfrw@kp ...fpp/asgn/as2 %
mfrw@kp ...fpp/asgn/as2 % cat tiny.cpp
#include <pthread.h>
int global;
void *thread(void *x) {
global = 42;
return x;
}
int main() {
pthread_t t;
pthread_create(&t, NULL, thread, NULL);
global = 43;
pthread_join(t, NULL);
return global;
}
mfrw@kp ...fpp/asgn/as2 % g++ tiny.cpp -fsanitize=thread -pie -fPIC -g -O1 -o tinyrace -pthread
mfrw@kp ...fpp/asgn/as2 % uname -a
Linux kp 4.4.33-1-MANJARO #1 SMP PREEMPT Fri Nov 18 18:06:44 UTC 2016 x86_64 GNU/Linux
mfrw@kp ...fpp/asgn/as2 % gcc --version
gcc (GCC) 6.2.1 20160830
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
mfrw@kp ...fpp/asgn/as2 % ./tinyrace
FATAL: ThreadSanitizer: unexpected memory mapping 0x55e38776b000-0x55e38776c000
mfrw@kp ...fpp/asgn/as2 %