aboutsummaryrefslogtreecommitdiff
path: root/tools/driver/EmbeddedRunner.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tools/driver/EmbeddedRunner.cc')
-rw-r--r--tools/driver/EmbeddedRunner.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/tools/driver/EmbeddedRunner.cc b/tools/driver/EmbeddedRunner.cc
index 3216882..742a6e4 100644
--- a/tools/driver/EmbeddedRunner.cc
+++ b/tools/driver/EmbeddedRunner.cc
@@ -1,6 +1,7 @@
#include "EmbeddedRunner.h"
#include "cps/CodeGen.h"
#include "llvm/ExecutionEngine/Orc/AbsoluteSymbols.h"
+#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h"
@@ -387,6 +388,19 @@ int runEmbedded(const cps::CodeGen &CG, const std::vector<std::string> &Objects)
<< llvm::toString(std::move(Err)) << "\n";
return 1;
}
+#ifdef _WIN32
+ // Process-wide lookup may find C functions in ucrtbase.dll, loaded by
+ // system DLLs, whose stdio buffers differ from the host's msvcrt. Prefer
+ // the host CRT so EXTERN calls such as puts share stdout with OUTPUT.
+ auto CRT = llvm::orc::DynamicLibrarySearchGenerator::Load(
+ "msvcrt.dll", J->getDataLayout().getGlobalPrefix());
+ if (!CRT) {
+ llvm::errs() << "error: cannot load the embedded C runtime: "
+ << llvm::toString(CRT.takeError()) << "\n";
+ return 1;
+ }
+ J->getMainJITDylib().addGenerator(std::move(*CRT));
+#endif
// Keep CodeGen's module and context alive; the JIT owns an independent copy.
llvm::orc::ThreadSafeContext TSCtx(std::make_unique<llvm::LLVMContext>());