Path: blob/main/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/SectCreate.cpp
35266 views
//===--------- SectCreate.cpp - Emulate ld64's -sectcreate option ---------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/ExecutionEngine/Orc/SectCreate.h"910#define DEBUG_TYPE "orc"1112using namespace llvm::jitlink;1314namespace llvm::orc {1516void SectCreateMaterializationUnit::materialize(17std::unique_ptr<MaterializationResponsibility> R) {18auto G = std::make_unique<LinkGraph>(19"orc_sectcreate_" + SectName,20ObjLinkingLayer.getExecutionSession().getTargetTriple(),21getGenericEdgeKindName);2223auto &Sect = G->createSection(SectName, MP);24auto Content = G->allocateContent(25ArrayRef<char>(Data->getBuffer().data(), Data->getBuffer().size()));26auto &B = G->createContentBlock(Sect, Content, ExecutorAddr(), Alignment, 0);2728for (auto &[Name, Info] : ExtraSymbols) {29auto L = Info.Flags.isStrong() ? Linkage::Strong : Linkage::Weak;30auto S = Info.Flags.isExported() ? Scope::Default : Scope::Hidden;31G->addDefinedSymbol(B, Info.Offset, *Name, 0, L, S, Info.Flags.isCallable(),32true);33}3435ObjLinkingLayer.emit(std::move(R), std::move(G));36}3738void SectCreateMaterializationUnit::discard(const JITDylib &JD,39const SymbolStringPtr &Name) {40ExtraSymbols.erase(Name);41}4243MaterializationUnit::Interface SectCreateMaterializationUnit::getInterface(44const ExtraSymbolsMap &ExtraSymbols) {45SymbolFlagsMap SymbolFlags;46for (auto &[Name, Info] : ExtraSymbols)47SymbolFlags[Name] = Info.Flags;48return {std::move(SymbolFlags), nullptr};49}5051} // End namespace llvm::orc.525354