LLVM 20.0.0git
SectCreate.cpp
Go to the documentation of this file.
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
10
11#define DEBUG_TYPE "orc"
12
13using namespace llvm::jitlink;
14
15namespace llvm::orc {
16
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(),
24
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);
29
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(),
34 true);
35 }
36
37 ObjLinkingLayer.emit(std::move(R), std::move(G));
38}
39
40void SectCreateMaterializationUnit::discard(const JITDylib &JD,
41 const SymbolStringPtr &Name) {
42 ExtraSymbols.erase(Name);
43}
44
45MaterializationUnit::Interface SectCreateMaterializationUnit::getInterface(
46 const ExtraSymbolsMap &ExtraSymbols) {
48 for (auto &[Name, Info] : ExtraSymbols)
49 SymbolFlags[Name] = Info.Flags;
50 return {std::move(SymbolFlags), nullptr};
51}
52
53} // End namespace llvm::orc.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
T Content
std::string Name
#define G(x, y, z)
Definition: MD5.cpp:56
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
bool erase(const KeyT &Val)
Definition: DenseMap.h:321
const Triple & getTargetTriple() const
Return the triple for the executor.
Definition: Core.h:1382
std::shared_ptr< SymbolStringPool > getSymbolStringPool()
Get the SymbolStringPool for this instance.
Definition: Core.h:1388
Represents an address in the executor process.
Represents a JIT'd dynamic library.
Definition: Core.h:897
ExecutionSession & getExecutionSession()
void emit(std::unique_ptr< MaterializationResponsibility > R, std::unique_ptr< MemoryBuffer > O) override
Emit an object file.
void materialize(std::unique_ptr< MaterializationResponsibility > R) override
Implementations of this method should materialize all symbols in the materialzation unit,...
Definition: SectCreate.cpp:17
Pointer to a pooled string representing a symbol name.
DenseMap< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.