You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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_localunsignedint rage = 1;
std::mutex cout_mutex;
voidincrease_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';
}
intmain()
{
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:
f:\Temp>tls
Rage counter for a: 2
Rage counter for b: 2
Rage counter for main: 1
mingw32-g++ output:
f:\Temp>tls_mingw.exe
Rage counter for main: 1
Rage counter for a: 2
Rage counter for b: 2
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 #[thread_local] statics in Rust. The NX compatible bit does not indicate ASLR, rather it needs to have the Dynamic base bit.
Activity
steveklabnik commentedon Dec 31, 2015
Triage: I am not sure if there has been any change, nor steps to reproduce.
brson commentedon Feb 6, 2016
If this was a mingw-specific bug, we may be able to reactivate it on the msvc builds.
retep998 commentedon Feb 6, 2016
According to MSDN
By default, /DYNAMICBASE is on.
so we've already been effectively using ASLR with-msvc
targets.[-]ASLR on Windows breaks TLS[/-][+]ASLR on Windows breaks thread-local variables[/+]Mark-Simulacrum commentedon May 6, 2017
Can someone comment on whether thread locals are broken on Windows MinGW-w64 today? What are the reproduction steps?
sipsorcery commentedon Oct 2, 2017
I've done a cursory check of TLS with 64 bit binaries compiled with msvc and mingw32-g++ and both are working correctly.
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.
retep998 commentedon Oct 2, 2017
@sipsorcery The key thing is
#[thread_local]
statics in Rust. The NX compatible bit does not indicate ASLR, rather it needs to have the Dynamic base bit.8 remaining items