• Bruce Dawson's avatar
    Avoid Windows kernel bug using Python hack · 052a0901
    Bruce Dawson authored
    On about 3-4% of Chrome builds on my workstation one of the executables
    generated and then used during the build will crash. The binary on disk
    is always fine but the loader sometimes maps in pages of zeroes where it
    should be mapping in pages from the just-generated binary. Having a page
    of zeroes where you are expecting useful instructions tends to lead to
    crashes.
    
    This appears to be a bug in the OS disk cache. My suspicion is that this
    kernel bug only happens on multi-socket systems, but this is
    speculation.
    
    This bug happens regardless of which compiler or linker is used, and
    appears to happen on multiple Windows versions. The best reproes have
    been on Windows 10 Creators Update, or at least that is where I have
    done most of my testing.
    
    Extensive testing - hundreds of overnight builds - has shown that the
    problem goes away if FlushFileBuffers is called on the output file
    after linking is finished. Eventually this fix/hack will be coded into
    lld-link.exe, but for now it is put in tool_wrapper.py to fix the bug
    for both link.exe and lld-link.exe.
    
    Earlier versions of this fix only applied it to files with .exe
    extensions. However the bug is believed to have happened with DLLs, and
    may also affect .lib files created by the linkers, so now it is done
    always. The belief is that the performance impact will be negligible.
    
    Importing of win32file required some trickiness because in the context
    of ninja builds of Chrome the depot_tools python.bat file is apparently
    not called. This means that the python directory is not added to the
    system path. The python runtime correctly finds win32file.pyd and calls
    LoadLibrary on it but the OS then finds its dependencies in another
    version of python installed on the system and the DLL load fails if
    those are 64-bit instead of 32-bit.
    
    Bug: 644525
    Change-Id: I71d63b47050385e2e5ba46ced9c8018220370ba7
    Reviewed-on: https://chromium-review.googlesource.com/876683
    Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
    Reviewed-by: default avatarZachary Turner <zturner@chromium.org>
    Reviewed-by: default avatarScott Graham <scottmg@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#533137}
    052a0901
tool_wrapper.py 10.9 KB