LLVM 22.0.0git
COFFVCRuntimeSupport.h
Go to the documentation of this file.
1//===----- COFFVCRuntimeSupport.h -- VC runtime support in ORC --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Utilities for loading and initializaing vc runtime in Orc.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_COFFCRUNTIMESUPPORT_H
14#define LLVM_EXECUTIONENGINE_ORC_COFFCRUNTIMESUPPORT_H
15
16#include "llvm/ADT/StringRef.h"
22
23#include <future>
24#include <memory>
25#include <thread>
26#include <vector>
27
28namespace llvm {
29namespace orc {
30
31/// Bootstraps the vc runtime within jitdylibs.
32class COFFVCRuntimeBootstrapper {
33public:
34 /// Try to create a COFFVCRuntimeBootstrapper instance. An optional
35 /// RuntimePath can be given to specify the location of directory that
36 /// contains all vc runtime library files such as ucrt.lib and msvcrt.lib. If
37 /// no path was given, it will try to search the MSVC toolchain and Windows
38 /// SDK installation and use the found library files automatically.
39 ///
40 /// Note that depending on the build setting, a different library
41 /// file must be used. In general, if vc runtime was statically linked to the
42 /// object file that is to be jit-linked, LoadStaticVCRuntime and
43 /// InitializeStaticVCRuntime must be used with libcmt.lib, libucrt.lib,
44 /// libvcruntimelib. If vc runtime was dynamically linked LoadDynamicVCRuntime
45 /// must be used along with msvcrt.lib, ucrt.lib, vcruntime.lib.
46 ///
47 /// More information is on:
48 /// https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features
50 Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
51 const char *RuntimePath = nullptr);
52
53 /// Adds symbol definitions of static version of msvc runtime libraries.
55 loadStaticVCRuntime(JITDylib &JD, bool DebugVersion = false);
56
57 /// Runs the initializer of static version of msvc runtime libraries.
58 /// This must be called before calling any functions requiring c runtime (e.g.
59 /// printf) within the jit session. Note that proper initialization of vc
60 /// runtime requires ability of running static initializers. Cosider setting
61 /// up COFFPlatform.
63
64 /// Adds symbol definitions of dynamic version of msvc runtime libraries.
66 loadDynamicVCRuntime(JITDylib &JD, bool DebugVersion = false);
67
68private:
69 COFFVCRuntimeBootstrapper(ExecutionSession &ES,
70 ObjectLinkingLayer &ObjLinkingLayer,
71 const char *RuntimePath);
72
74 ObjectLinkingLayer &ObjLinkingLayer;
75 std::string RuntimePath;
76
77 struct MSVCToolchainPath {
78 SmallString<256> VCToolchainLib;
79 SmallString<256> UCRTSdkLib;
80 };
81
82 static Expected<MSVCToolchainPath> getMSVCToolchainPath();
83 Error loadVCRuntime(JITDylib &JD, std::vector<std::string> &ImportedLibraries,
85};
86
87} // namespace orc
88} // namespace llvm
89
90#endif
#define LLVM_ABI
Definition Compiler.h:213
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
static LLVM_ABI Expected< std::unique_ptr< COFFVCRuntimeBootstrapper > > Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer, const char *RuntimePath=nullptr)
Try to create a COFFVCRuntimeBootstrapper instance.
LLVM_ABI Expected< std::vector< std::string > > loadStaticVCRuntime(JITDylib &JD, bool DebugVersion=false)
Adds symbol definitions of static version of msvc runtime libraries.
LLVM_ABI Expected< std::vector< std::string > > loadDynamicVCRuntime(JITDylib &JD, bool DebugVersion=false)
Adds symbol definitions of dynamic version of msvc runtime libraries.
LLVM_ABI Error initializeStaticVCRuntime(JITDylib &JD)
Runs the initializer of static version of msvc runtime libraries.
An ExecutionSession represents a running JIT program.
Definition Core.h:1355
Represents a JIT'd dynamic library.
Definition Core.h:902
An ObjectLayer implementation built on JITLink.
This is an optimization pass for GlobalISel generic memory operations.