Skip to content

Commit

Permalink
[llvm-lit] copy CRT/STL DLLs into the output directory
Browse files Browse the repository at this point in the history
It turns out that the STL requires you to place the DLLs into the
directory of the executable; else, msvcp140.dll will be taken from
C:\Windows\System32 (which is unsupported).

This was discovered because of the recent constexpr mutex change;
see [microsoft/STL#3824][]. Especially the fuzzer unit tests fail
completely with the mutex changes.

[microsoft/STL#3824]: microsoft/STL#3824

Differential Revision: https://reviews.llvm.org/D158221
  • Loading branch information
strega-nil committed Aug 17, 2023
1 parent 1e7f592 commit f620022
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 13 additions & 1 deletion llvm/utils/lit/lit/TestRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import shutil
import tempfile
import threading
from pathlib import Path

import io

Expand Down Expand Up @@ -2066,7 +2067,18 @@ def runOnce(execdir):
return out, err, exitCode, timeoutInfo, status

# Create the output directory if it does not already exist.
lit.util.mkdir_p(os.path.dirname(tmpBase))
outputDir = os.path.dirname(tmpBase)
lit.util.mkdir_p(outputDir)

# On Windows, copy the required DLLs from PATH into the test directory
# This avoids the loader finding DLLs in C:\Windows\System32
if litConfig.isWindows:
toolsetDirectory = Path(lit.util.which("cl.exe")).parent
for dllToCopy in itertools.chain(\
toolsetDirectory.glob('msvcp*.dll'),\
toolsetDirectory.glob('vcruntime*.dll'),\
toolsetDirectory.glob('ucrtbase*.dll')):
shutil.copyfile(dllToCopy, os.path.join(outputDir, dllToCopy.name))

# Re-run failed tests up to test.allowed_retries times.
execdir = os.path.dirname(test.getExecPath())
Expand Down
6 changes: 3 additions & 3 deletions llvm/utils/lit/lit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ def which(command, paths=None):

# Get suffixes to search.
# On Cygwin, 'PATHEXT' may exist but it should not be used.
if os.pathsep == ";":
pathext = os.environ.get("PATHEXT", "").split(";")
if os.path.splitext(command)[-1] != '' or os.pathsep != ';':
pathext = ['']
else:
pathext = [""]
pathext = os.environ.get('PATHEXT', '').split(';')

# Search the paths...
for path in paths.split(os.pathsep):
Expand Down

0 comments on commit f620022

Please sign in to comment.