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 #include "llvm/Support/Compiler.h" 19 20 #include <utility> 21 #include <vector> 22 23 namespace llvm::orc { 24 25 class LLVM_ABI SectCreateMaterializationUnit : public MaterializationUnit { 26 public: 27 struct ExtraSymbolInfo { 28 JITSymbolFlags Flags; 29 size_t Offset = 0; 30 }; 31 32 using ExtraSymbolsMap = DenseMap<SymbolStringPtr, ExtraSymbolInfo>; 33 34 SectCreateMaterializationUnit( 35 ObjectLinkingLayer &ObjLinkingLayer, std::string SectName, MemProt MP, 36 uint64_t Alignment, std::unique_ptr<MemoryBuffer> Data, 37 ExtraSymbolsMap ExtraSymbols = ExtraSymbolsMap()) MaterializationUnit(getInterface (ExtraSymbols))38 : MaterializationUnit(getInterface(ExtraSymbols)), 39 ObjLinkingLayer(ObjLinkingLayer), SectName(std::move(SectName)), MP(MP), 40 Alignment(Alignment), Data(std::move(Data)), 41 ExtraSymbols(std::move(ExtraSymbols)) {} 42 getName()43 StringRef getName() const override { return "SectCreate"; } 44 45 void materialize(std::unique_ptr<MaterializationResponsibility> R) override; 46 47 private: 48 void discard(const JITDylib &JD, const SymbolStringPtr &Name) override; 49 50 static Interface getInterface(const ExtraSymbolsMap &ExtraSymbols); 51 52 ObjectLinkingLayer &ObjLinkingLayer; 53 std::string SectName; 54 MemProt MP; 55 uint64_t Alignment; 56 std::unique_ptr<MemoryBuffer> Data; 57 ExtraSymbolsMap ExtraSymbols; 58 }; 59 60 } // namespace llvm::orc 61 62 #endif // LLVM_EXECUTIONENGINE_ORC_SECTCREATE_H 63