Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:52

0001 //===----- COFFVCRuntimeSupport.h -- VC runtime support in ORC --*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Utilities for loading and initializaing vc runtime in Orc.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_EXECUTIONENGINE_ORC_COFFCRUNTIMESUPPORT_H
0014 #define LLVM_EXECUTIONENGINE_ORC_COFFCRUNTIMESUPPORT_H
0015 
0016 #include "llvm/ADT/StringRef.h"
0017 #include "llvm/ExecutionEngine/Orc/Core.h"
0018 #include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
0019 #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
0020 #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
0021 
0022 #include <future>
0023 #include <memory>
0024 #include <thread>
0025 #include <vector>
0026 
0027 namespace llvm {
0028 namespace orc {
0029 
0030 /// Bootstraps the vc runtime within jitdylibs.
0031 class COFFVCRuntimeBootstrapper {
0032 public:
0033   /// Try to create a COFFVCRuntimeBootstrapper instance. An optional
0034   /// RuntimePath can be given to specify the location of directory that
0035   /// contains all vc runtime library files such as ucrt.lib and msvcrt.lib. If
0036   /// no path was given, it will try to search the MSVC toolchain and Windows
0037   /// SDK installation and use the found library files automatically.
0038   ///
0039   /// Note that depending on the build setting, a different library
0040   /// file must be used. In general, if vc runtime was statically linked to the
0041   /// object file that is to be jit-linked, LoadStaticVCRuntime and
0042   /// InitializeStaticVCRuntime must be used with libcmt.lib, libucrt.lib,
0043   /// libvcruntimelib. If vc runtime was dynamically linked LoadDynamicVCRuntime
0044   /// must be used along with msvcrt.lib, ucrt.lib, vcruntime.lib.
0045   ///
0046   /// More information is on:
0047   /// https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features
0048   static Expected<std::unique_ptr<COFFVCRuntimeBootstrapper>>
0049   Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
0050          const char *RuntimePath = nullptr);
0051 
0052   /// Adds symbol definitions of static version of msvc runtime libraries.
0053   Expected<std::vector<std::string>>
0054   loadStaticVCRuntime(JITDylib &JD, bool DebugVersion = false);
0055 
0056   /// Runs the initializer of static version of msvc runtime libraries.
0057   /// This must be called before calling any functions requiring c runtime (e.g.
0058   /// printf) within the jit session. Note that proper initialization of vc
0059   /// runtime requires ability of running static initializers. Cosider setting
0060   /// up COFFPlatform.
0061   Error initializeStaticVCRuntime(JITDylib &JD);
0062 
0063   /// Adds symbol definitions of dynamic version of msvc runtime libraries.
0064   Expected<std::vector<std::string>>
0065   loadDynamicVCRuntime(JITDylib &JD, bool DebugVersion = false);
0066 
0067 private:
0068   COFFVCRuntimeBootstrapper(ExecutionSession &ES,
0069                             ObjectLinkingLayer &ObjLinkingLayer,
0070                             const char *RuntimePath);
0071 
0072   ExecutionSession &ES;
0073   ObjectLinkingLayer &ObjLinkingLayer;
0074   std::string RuntimePath;
0075 
0076   struct MSVCToolchainPath {
0077     SmallString<256> VCToolchainLib;
0078     SmallString<256> UCRTSdkLib;
0079   };
0080 
0081   static Expected<MSVCToolchainPath> getMSVCToolchainPath();
0082   Error loadVCRuntime(JITDylib &JD, std::vector<std::string> &ImportedLibraries,
0083                       ArrayRef<StringRef> VCLibs, ArrayRef<StringRef> UCRTLibs);
0084 };
0085 
0086 } // namespace orc
0087 } // namespace llvm
0088 
0089 #endif