<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW " title="NEW --- - Local static variable initialization is not thread safe" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D23817&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=h9IV9UbaIIDbCFLfnUFdj4K6xxO_Nvyw0WCvEbW5DdE&s=NJdfNZ_Fvn_gpQvfb_lZXVK-ls7lF5i2JxcyyGyBZcg&e=">23817</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Local static variable initialization is not thread safe
</td>
</tr>
<tr>
<th>Product</th>
<td>compiler-rt
</td>
</tr>
<tr>
<th>Version</th>
<td>3.6
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>release blocker
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>compiler-rt
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>ali.demiroz@sap.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>llvm-3.6.0rc4.src\lib\Support\Windows\Memory.inc at line 81, there is a local
static variable usage to ensure calling "getAllocationGranularity" function
only once.
But unlike GCC, MSVC does not use any barrier to provide synchronization for
local-scoped static variables.
So as a consequence, this code causes a division by zero at line 82 in
Memory.inc when second thread sees that cs:dword_143A26070 is set but
cs:off_143A26068 is initialized yet.
Generated assembly:
mov eax, cs:dword_143A26070
test al, 1
jnz short loc_14251B165
or eax, 1
lea rcx, [rsp+88h+var_38]
mov cs:dword_143A26070, eax
call cs:__imp_GetSystemInfo
mov eax, [rsp+88h+var_34]
mov ecx, [rsp+88h+var_10]
cmp eax, ecx
jbe short loc_14251B159
mov ecx, eax
loc_14251B159:
mov cs:off_143A26068, rcx
xor r8d, r8d
jmp short loc_14251B16C
loc_14251B165:
mov rcx, cs:off_143A26068
loc_14251B16C:
xor edx, edx
lea rax, [rbp-1]
add rax, rcx
div rcx
mov qword ptr [rsp+88h+var_58], rax
test rdi, rdi
jz short loc_14251B1C0
...</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>