https://bugs.winehq.org/show_bug.cgi?id=57700
Bug ID: 57700 Summary: NTDLL under-aligns implicit module TLS Product: Wine Version: 10.0-rc6 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: ntdll Assignee: wine-bugs@winehq.org Reporter: me@purplesyringa.moe Distribution: ---
Created attachment 77888 --> https://bugs.winehq.org/attachment.cgi?id=77888 Reproducer
alloc_tls_slot in dlls/ntdll/loader.c spells:
if (!(new_ptr = RtlAllocateHeap( GetProcessHeap(), 0, size + dir->SizeOfZeroFill ))) return -1;
This allocates the thread-local storage without an alignment. MSDN says that the correct alignment is specified in the Characteristics field of the TLS directory, which Wine promptly ignores. (https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#the-tls-dire...) This leads to unsatisfied alignment requirements in programs that expect it, often leading to crashes, as seen in https://github.com/rust-lang/rust/issues/135719.
For testing, I have attached a small example built with MSVC that allocates a page-aligned thread local and prints its address. The compiled executable is at https://mega.nz/file/AJhyVAyA#3JDbONv0-TIQPqLKpUW7zg9DLRjP9IqHsdOIpxUHSUs. The alignment specified in the TLS directory is 4096, matching the source code, as verified by `dumpbin /tls`.
If you'd like me to attach the executable to the ticket directly or need more information, please do tell.