Skip to content

Commit 2e6d9af

Browse files
committed
[ORC] Support adding LC_LOAD_WEAK_DYLIB commands to MachO JITDylib headers.
MachOPlatform synthesizes Mach headers for JITDylibs (see ef314d3). This commit adds support for adding LC_LOAD_WEAK_DYLIB commands to these synthesized headers (LC_LOAD_DYLIB was already supported previously).
1 parent 12c7908 commit 2e6d9af

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

llvm/include/llvm/ExecutionEngine/Orc/MachOBuilder.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ struct MachOBuilderLoadCommand<MachO::LC_LOAD_DYLIB>
116116
using MachOBuilderDylibLoadCommand::MachOBuilderDylibLoadCommand;
117117
};
118118

119+
template <>
120+
struct MachOBuilderLoadCommand<MachO::LC_LOAD_WEAK_DYLIB>
121+
: public MachOBuilderDylibLoadCommand<MachO::LC_LOAD_WEAK_DYLIB> {
122+
using MachOBuilderDylibLoadCommand::MachOBuilderDylibLoadCommand;
123+
};
124+
119125
template <>
120126
struct MachOBuilderLoadCommand<MachO::LC_RPATH>
121127
: public MachOBuilderLoadCommandImplBase<MachO::LC_RPATH> {

llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ class MachOPlatform : public Platform {
5858
uint32_t CompatibilityVersion;
5959
};
6060

61+
struct LoadDylibCmd {
62+
enum class LoadKind { Default, Weak };
63+
64+
Dylib D;
65+
LoadKind K;
66+
};
67+
6168
struct BuildVersionOpts {
6269

6370
// Derive platform from triple if possible.
@@ -74,7 +81,7 @@ class MachOPlatform : public Platform {
7481
std::optional<Dylib> IDDylib;
7582

7683
/// List of LC_LOAD_DYLIBs.
77-
std::vector<Dylib> LoadDylibs;
84+
std::vector<LoadDylibCmd> LoadDylibs;
7885
/// List of LC_RPATHs.
7986
std::vector<std::string> RPaths;
8087
/// List of LC_BUILD_VERSIONs.

llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,9 +1763,22 @@ jitlink::Block &createHeaderBlock(MachOPlatform &MOP,
17631763
for (auto &BV : Opts.BuildVersions)
17641764
B.template addLoadCommand<MachO::LC_BUILD_VERSION>(
17651765
BV.Platform, BV.MinOS, BV.SDK, static_cast<uint32_t>(0));
1766-
for (auto &D : Opts.LoadDylibs)
1767-
B.template addLoadCommand<MachO::LC_LOAD_DYLIB>(
1768-
D.Name, D.Timestamp, D.CurrentVersion, D.CompatibilityVersion);
1766+
1767+
using LoadKind = MachOPlatform::HeaderOptions::LoadDylibCmd::LoadKind;
1768+
for (auto &LD : Opts.LoadDylibs) {
1769+
switch (LD.K) {
1770+
case LoadKind::Default:
1771+
B.template addLoadCommand<MachO::LC_LOAD_DYLIB>(
1772+
LD.D.Name, LD.D.Timestamp, LD.D.CurrentVersion,
1773+
LD.D.CompatibilityVersion);
1774+
break;
1775+
case LoadKind::Weak:
1776+
B.template addLoadCommand<MachO::LC_LOAD_WEAK_DYLIB>(
1777+
LD.D.Name, LD.D.Timestamp, LD.D.CurrentVersion,
1778+
LD.D.CompatibilityVersion);
1779+
break;
1780+
}
1781+
}
17691782
for (auto &P : Opts.RPaths)
17701783
B.template addLoadCommand<MachO::LC_RPATH>(P);
17711784

0 commit comments

Comments
 (0)