Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThreadSanitizer SEGFAULT #843

Closed
jbayardo opened this issue Aug 7, 2017 · 4 comments
Closed

ThreadSanitizer SEGFAULT #843

jbayardo opened this issue Aug 7, 2017 · 4 comments

Comments

@jbayardo
Copy link

jbayardo commented Aug 7, 2017

I wrote the following code:

#include <iostream>
#include <thread>
#include <atomic>
#include <functional>
#include <chrono>

void dekker(std::atomic<int> &x, std::atomic<int> &y, std::atomic<int> &r) {
    std::this_thread::sleep_for(std::chrono::milliseconds(5));
    x.store(1, std::memory_order_release);
    r.store(y.load(std::memory_order_acquire), std::memory_order_relaxed);
}

int main() {
    std::atomic<int> x, y, r1, r2;
    while (true) {
        x = y = r1 = r2 = 0;

        std::thread t1(dekker, std::ref(x), std::ref(y), std::ref(r1));
        std::thread t2(dekker, std::ref(y), std::ref(x), std::ref(r2));
        t2.join();
        t1.join();

        if (r1.load() == 0 && r2.load() == 0) {
            std::cout << "ERROR! Found forbidden condition." << std::endl;
            exit(-1);
        }
    }

    return 0;
}

When compiling with clang++ -fsanitize=thread --std=c++11 -lpthread file.cc and running, I get the following:

FATAL: ThreadSanitizer CHECK failed: /build/buildd/llvm-toolchain-3.4-3.4/projects/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc:462 "((IsOneOf(*current_, 's', 'p'))) != (0)" (0x0, 0x0)
[1] 24515 segmentation fault (core dumped) ./a.out

This is using Ubuntu 14.04.5 LTS (Trusty Tahr) and:

» clang++ --version
Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)
Target: x86_64-pc-linux-gnu
Thread model: posix

@dvyukov
Copy link
Contributor

dvyukov commented Aug 8, 2017

Does this reproduce with a newer clang? 3.4 is more than 3 years old, lots of bugs was fixed since then.

@jbayardo
Copy link
Author

jbayardo commented Aug 9, 2017

Still happens when installing it from the official repos:

clang version 6.0.0-svn310059-1~exp1 (trunk)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Gives out the following:

FATAL: ThreadSanitizer CHECK failed: /build/llvm-toolchain-snapshot-6.0~svn310059/projects/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_linux.cc:47 "((IsOneOf(current_, 's', 'p'))) != (0)" (0x0, 0x0)
#0 __tsan::TsanCheckFailed(char const
, int, char const*, unsigned long long, unsigned long long) ??:? (a.out+0x48bb9f)
#1 __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) ??:? (a.out+0x4a7385)
#2 __sanitizer::MemoryMappingLayout::Next(__sanitizer::MemoryMappedSegment*) ??:? (a.out+0x4a3139)
#3 __tsan::CheckAndProtect() ??:? (a.out+0x492ada)
#4 __tsan::InitializePlatform() ??:? (a.out+0x4925d4)
#5 __tsan::Initialize(__tsan::ThreadState*) ??:? (a.out+0x48036c)
#6 _dl_init /build/eglibc-SvCtMH/eglibc-2.19/elf/dl-init.c:111 (discriminator 2) (ld-linux-x86-64.so.2+0x10429)
#7 (ld-linux-x86-64.so.2+0x1299)

@dvyukov
Copy link
Contributor

dvyukov commented Aug 10, 2017

Need to understand what's different in your environment. It generally works for other people.

What version of linux do you use? uname -a output?
Does it happen with int main(){} program?
Does -fsanitize=address work?

@jbayardo
Copy link
Author

I'm sorry, I just realized I was running this under a Windows Subsystem for Linux environment by mistake; it seems to have strange effects on how memory is allocated and so on. I'm closing this issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants