xref: /freebsd/contrib/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/SectCreate.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1 //===---- SectCreate.h -- Emulates ld64's -sectcreate option ----*- 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 // Emulates ld64's -sectcreate option.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_EXECUTIONENGINE_ORC_SECTCREATE_H
14 #define LLVM_EXECUTIONENGINE_ORC_SECTCREATE_H
15 
16 #include "llvm/ExecutionEngine/Orc/Core.h"
17 #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
18 
19 #include <utility>
20 #include <vector>
21 
22 namespace llvm::orc {
23 
24 class SectCreateMaterializationUnit : public MaterializationUnit {
25 public:
26   struct ExtraSymbolInfo {
27     JITSymbolFlags Flags;
28     size_t Offset = 0;
29   };
30 
31   using ExtraSymbolsMap = DenseMap<SymbolStringPtr, ExtraSymbolInfo>;
32 
33   SectCreateMaterializationUnit(
34       ObjectLinkingLayer &ObjLinkingLayer, std::string SectName, MemProt MP,
35       uint64_t Alignment, std::unique_ptr<MemoryBuffer> Data,
36       ExtraSymbolsMap ExtraSymbols = ExtraSymbolsMap())
MaterializationUnit(getInterface (ExtraSymbols))37       : MaterializationUnit(getInterface(ExtraSymbols)),
38         ObjLinkingLayer(ObjLinkingLayer), SectName(std::move(SectName)), MP(MP),
39         Alignment(Alignment), Data(std::move(Data)),
40         ExtraSymbols(std::move(ExtraSymbols)) {}
41 
getName()42   StringRef getName() const override { return "SectCreate"; }
43 
44   void materialize(std::unique_ptr<MaterializationResponsibility> R) override;
45 
46 private:
47   void discard(const JITDylib &JD, const SymbolStringPtr &Name) override;
48 
49   static Interface getInterface(const ExtraSymbolsMap &ExtraSymbols);
50 
51   ObjectLinkingLayer &ObjLinkingLayer;
52   std::string SectName;
53   MemProt MP;
54   uint64_t Alignment;
55   std::unique_ptr<MemoryBuffer> Data;
56   ExtraSymbolsMap ExtraSymbols;
57 };
58 
59 } // namespace llvm::orc
60 
61 #endif // LLVM_EXECUTIONENGINE_ORC_SECTCREATE_H
62