-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
ASLR on Windows breaks thread-local variables #17684
Comments
Triage: I am not sure if there has been any change, nor steps to reproduce. |
If this was a mingw-specific bug, we may be able to reactivate it on the msvc builds. |
According to MSDN |
Can someone comment on whether thread locals are broken on Windows MinGW-w64 today? What are the reproduction steps? |
I've done a cursory check of TLS with 64 bit binaries compiled with msvc and mingw32-g++ and both are working correctly. // http://en.cppreference.com/w/cpp/language/storage_duration
// msvc on win64: cl tls.cpp /link
// mingw on linux64: x86_64-w64-mingw32-g++ tls.cpp -static -static-libstdc++
#include <iostream>
#include <string>
#include <thread>
#include <mutex>
thread_local unsigned int rage = 1;
std::mutex cout_mutex;
void increase_rage(const std::string& thread_name)
{
++rage; // modifying outside a lock is okay; this is a thread-local variable
std::lock_guard<std::mutex> lock(cout_mutex);
std::cout << "Rage counter for " << thread_name << ": " << rage << '\n';
}
int main()
{
std::thread a(increase_rage, "a"), b(increase_rage, "b");
{
std::lock_guard<std::mutex> lock(cout_mutex);
std::cout << "Rage counter for main: " << rage << '\n';
}
a.join();
b.join();
getchar();
} msvc output:
mingw32-g++ output:
64 bit binaries on Windows use ASLR by default unless explicitly disabled with a linker option. Both binaries in this test had the NX Compatible flag set in the executable image header. Happy to test further if anyone has a pointer to the problem code. |
@sipsorcery The key thing is |
Does anybody have reproducer? |
This appears to be a MinGW-w64 linker bug.
The text was updated successfully, but these errors were encountered: