LLVM 20.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"
21
22#include <future>
23#include <memory>
24#include <thread>
25#include <vector>
26
27namespace llvm {
28namespace orc {
29
30/// Bootstraps the vc runtime within jitdylibs.
32public:
33 /// Try to create a COFFVCRuntimeBootstrapper instance. An optional
34 /// RuntimePath can be given to specify the location of directory that
35 /// contains all vc runtime library files such as ucrt.lib and msvcrt.lib. If
36 /// no path was given, it will try to search the MSVC toolchain and Windows
37 /// SDK installation and use the found library files automatically.
38 ///
39 /// Note that depending on the build setting, a different library
40 /// file must be used. In general, if vc runtime was statically linked to the
41 /// object file that is to be jit-linked, LoadStaticVCRuntime and
42 /// InitializeStaticVCRuntime must be used with libcmt.lib, libucrt.lib,
43 /// libvcruntimelib. If vc runtime was dynamically linked LoadDynamicVCRuntime
44 /// must be used along with msvcrt.lib, ucrt.lib, vcruntime.lib.
45 ///
46 /// More information is on:
47 /// https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features
49 Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
50 const char *RuntimePath = nullptr);
51
52 /// Adds symbol definitions of static version of msvc runtime libraries.
54 loadStaticVCRuntime(JITDylib &JD, bool DebugVersion = false);
55
56 /// Runs the initializer of static version of msvc runtime libraries.
57 /// This must be called before calling any functions requiring c runtime (e.g.
58 /// printf) within the jit session. Note that proper initialization of vc
59 /// runtime requires ability of running static initializers. Cosider setting
60 /// up COFFPlatform.
62
63 /// Adds symbol definitions of dynamic version of msvc runtime libraries.
65 loadDynamicVCRuntime(JITDylib &JD, bool DebugVersion = false);
66
67private:
69 ObjectLinkingLayer &ObjLinkingLayer,
70 const char *RuntimePath);
71
73 ObjectLinkingLayer &ObjLinkingLayer;
74 std::string RuntimePath;
75
76 struct MSVCToolchainPath {
77 SmallString<256> VCToolchainLib;
78 SmallString<256> UCRTSdkLib;
79 };
80
81 static Expected<MSVCToolchainPath> getMSVCToolchainPath();
82 Error loadVCRuntime(JITDylib &JD, std::vector<std::string> &ImportedLibraries,
84};
85
86} // namespace orc
87} // namespace llvm
88
89#endif
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:160
Tagged union holding either a T or a Error.
Definition: Error.h:481
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
Bootstraps the vc runtime within jitdylibs.
static Expected< std::unique_ptr< COFFVCRuntimeBootstrapper > > Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer, const char *RuntimePath=nullptr)
Try to create a COFFVCRuntimeBootstrapper instance.
Expected< std::vector< std::string > > loadStaticVCRuntime(JITDylib &JD, bool DebugVersion=false)
Adds symbol definitions of static version of msvc runtime libraries.
Expected< std::vector< std::string > > loadDynamicVCRuntime(JITDylib &JD, bool DebugVersion=false)
Adds symbol definitions of dynamic version of msvc runtime libraries.
Error initializeStaticVCRuntime(JITDylib &JD)
Runs the initializer of static version of msvc runtime libraries.
An ExecutionSession represents a running JIT program.
Definition: Core.h:1339
Represents a JIT'd dynamic library.
Definition: Core.h:897
An ObjectLayer implementation built on JITLink.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18