1c625b996SLang Hames //===--------- SectCreate.cpp - Emulate ld64's -sectcreate option ---------===// 2c625b996SLang Hames // 3c625b996SLang Hames // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4c625b996SLang Hames // See https://llvm.org/LICENSE.txt for license information. 5c625b996SLang Hames // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6c625b996SLang Hames // 7c625b996SLang Hames //===----------------------------------------------------------------------===// 8c625b996SLang Hames 9c625b996SLang Hames #include "llvm/ExecutionEngine/Orc/SectCreate.h" 10c625b996SLang Hames 11c625b996SLang Hames #define DEBUG_TYPE "orc" 12c625b996SLang Hames 13c625b996SLang Hames using namespace llvm::jitlink; 14c625b996SLang Hames 15c625b996SLang Hames namespace llvm::orc { 16c625b996SLang Hames 17c625b996SLang Hames void SectCreateMaterializationUnit::materialize( 18c625b996SLang Hames std::unique_ptr<MaterializationResponsibility> R) { 19c625b996SLang Hames auto G = std::make_unique<LinkGraph>( 20c625b996SLang Hames "orc_sectcreate_" + SectName, 212ccf7ed2SJared Wyles ObjLinkingLayer.getExecutionSession().getSymbolStringPool(), 22c625b996SLang Hames ObjLinkingLayer.getExecutionSession().getTargetTriple(), 23*4eaff6c5SLang Hames SubtargetFeatures(), getGenericEdgeKindName); 24c625b996SLang Hames 25c625b996SLang Hames auto &Sect = G->createSection(SectName, MP); 26c625b996SLang Hames auto Content = G->allocateContent( 27c625b996SLang Hames ArrayRef<char>(Data->getBuffer().data(), Data->getBuffer().size())); 28c625b996SLang Hames auto &B = G->createContentBlock(Sect, Content, ExecutorAddr(), Alignment, 0); 29c625b996SLang Hames 30c625b996SLang Hames for (auto &[Name, Info] : ExtraSymbols) { 31c625b996SLang Hames auto L = Info.Flags.isStrong() ? Linkage::Strong : Linkage::Weak; 32c625b996SLang Hames auto S = Info.Flags.isExported() ? Scope::Default : Scope::Hidden; 33c625b996SLang Hames G->addDefinedSymbol(B, Info.Offset, *Name, 0, L, S, Info.Flags.isCallable(), 34c625b996SLang Hames true); 35c625b996SLang Hames } 36c625b996SLang Hames 37c625b996SLang Hames ObjLinkingLayer.emit(std::move(R), std::move(G)); 38c625b996SLang Hames } 39c625b996SLang Hames 40c625b996SLang Hames void SectCreateMaterializationUnit::discard(const JITDylib &JD, 41c625b996SLang Hames const SymbolStringPtr &Name) { 42c625b996SLang Hames ExtraSymbols.erase(Name); 43c625b996SLang Hames } 44c625b996SLang Hames 45c625b996SLang Hames MaterializationUnit::Interface SectCreateMaterializationUnit::getInterface( 46c625b996SLang Hames const ExtraSymbolsMap &ExtraSymbols) { 47c625b996SLang Hames SymbolFlagsMap SymbolFlags; 48c625b996SLang Hames for (auto &[Name, Info] : ExtraSymbols) 49c625b996SLang Hames SymbolFlags[Name] = Info.Flags; 50c625b996SLang Hames return {std::move(SymbolFlags), nullptr}; 51c625b996SLang Hames } 52c625b996SLang Hames 53c625b996SLang Hames } // End namespace llvm::orc. 54