1//===--------- SectCreate.cpp - Emulate ld64's -sectcreate option ---------===//
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#include "llvm/ExecutionEngine/Orc/SectCreate.h"
10
11#define DEBUG_TYPE "orc"
12
13using namespace llvm::jitlink;
14
15namespace llvm::orc {
16
17void SectCreateMaterializationUnit::materialize(
18 std::unique_ptr<MaterializationResponsibility> R) {
19 auto G = std::make_unique<LinkGraph>(
20 args: "orc_sectcreate_" + SectName,
21 args: ObjLinkingLayer.getExecutionSession().getTargetTriple(),
22 args&: getGenericEdgeKindName);
23
24 auto &Sect = G->createSection(Name: SectName, Prot: MP);
25 auto Content = G->allocateContent(
26 Source: ArrayRef<char>(Data->getBuffer().data(), Data->getBuffer().size()));
27 auto &B = G->createContentBlock(Parent&: Sect, Content, Address: ExecutorAddr(), Alignment, AlignmentOffset: 0);
28
29 for (auto &[Name, Info] : ExtraSymbols) {
30 auto L = Info.Flags.isStrong() ? Linkage::Strong : Linkage::Weak;
31 auto S = Info.Flags.isExported() ? Scope::Default : Scope::Hidden;
32 G->addDefinedSymbol(Content&: B, Offset: Info.Offset, Name: *Name, Size: 0, L, S, IsCallable: Info.Flags.isCallable(),
33 IsLive: true);
34 }
35
36 ObjLinkingLayer.emit(R: std::move(R), G: std::move(G));
37}
38
39void SectCreateMaterializationUnit::discard(const JITDylib &JD,
40 const SymbolStringPtr &Name) {
41 ExtraSymbols.erase(Val: Name);
42}
43
44MaterializationUnit::Interface SectCreateMaterializationUnit::getInterface(
45 const ExtraSymbolsMap &ExtraSymbols) {
46 SymbolFlagsMap SymbolFlags;
47 for (auto &[Name, Info] : ExtraSymbols)
48 SymbolFlags[Name] = Info.Flags;
49 return {std::move(SymbolFlags), nullptr};
50}
51
52} // End namespace llvm::orc.
53