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