[cfe-dev] ThreadSanitizer in 3.5 nightly appears to incorrectly schedule calls to atexit handlers
Andrew C. Morrow
andrew.c.morrow at gmail.com
Thu Aug 21 12:03:49 PDT 2014
Hi -
I'm using the clang 3.5 builds from http://llvm.org/apt/ on Ubuntu 14.04:
$clang --version
Ubuntu clang version 3.5-1ubuntu1 (trunk) (based on LLVM 3.5)
Target: x86_64-pc-linux-gnu
Thread model: posix
The following program calls the Logger destructor after calling the
registered atexit handler, since the logger object was constructed before
the call to atexit:
$ cat ./tsan_vs_atexit.cpp
#include <cstdio>
#include <cstdlib>
class Logger {
public:
Logger() {
std::printf("Logger ctor\n");
}
void log(const char* msg) {
std::printf("%s", msg);
}
~Logger() {
std::printf("Logger dtor\n");
}
};
Logger logger;
void log_from_atexit() {
logger.log("In log_from_atexit\n");
}
int main(int argc, char* argv[]) {
std::atexit(log_from_atexit);
return EXIT_SUCCESS;
}
$ clang++ -std=c++03 -fPIE -pie ./tsan_vs_atexit.cpp
$ ./a.out
Logger ctor
In log_from_atexit
Logger dtor
However, if I enable the thread sanitizer, now the atexit call is sequenced
after the call to destroy logger.
$ clang++ -std=c++03 -fPIE -pie -fsanitize=thread ./tsan_vs_atexit.cpp
$ ./a.out
Logger ctor
Logger dtor
In log_from_atexit
Unless I've misunderstood the C++03 language around std::atexit that
ordering is incorrect.
A quick google search didn't find much. Is this a known issue, or is the
ordering not specified in C++03 as I thought?
Thanks,
Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140821/d4c8c57e/attachment.html>
More information about the cfe-dev
mailing list