Skip to content

Library not usable under ThreadSanitizer with clang < 5, gcc == 6 #1759

Description

@anarthal

The problem is that the sanitizer interface was added in a later version than the sanitizer flags themselves. Reproducer:

#if !defined(BOOST_ASIO_HAS_THREAD_SANITIZER)
#if defined(__SANITIZE_THREAD__)
#define BOOST_ASIO_HAS_THREAD_SANITIZER 1
#elif defined(__has_feature)
#if __has_feature(thread_sanitizer)
#define BOOST_ASIO_HAS_THREAD_SANITIZER 1
#endif // __has_feature(thread_sanitizer)
#endif // defined(__SANITIZE_THREAD__)
#endif // !defined(BOOST_ASIO_HAS_THREAD_SANITIZER)

#include <iostream>

#if defined(BOOST_ASIO_HAS_THREAD_SANITIZER)
#include <sanitizer/tsan_interface.h>
#endif // defined(BOOST_ASIO_HAS_THREAD_SANITIZER)

int main() {
#ifdef BOOST_ASIO_HAS_THREAD_SANITIZER
  std::cout << "Has tsan: true\n";
#else
  std::cout << "Has tsan: false\n";
#endif
}

Build under clang 4.0 (Docker container ubuntu:16.04) and gcc 7 (Docker container ubuntu:18.04). The problem is that BOOST_ASIO_HAS_THREAD_SANITIZER is true, but the header sanitizer/tsan_interface.h does not exist.

Note that gcc 6 and lower has -fsanitize=thread but is not detected by any of the checks above. Builds using it report (hopefully) false positives.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions