https://llvm.org/bugs/show_bug.cgi?id=23817

            Bug ID: 23817
           Summary: Local static variable initialization is not thread
                    safe
           Product: compiler-rt
           Version: 3.6
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: compiler-rt
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

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
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to