Skip to content

Commit df2485b

Browse files
committed
Revert "[llvm-jitlink] Add Process and Platform JITDylibs, generalize alias..."
This reverts commit 3d0dd1a while I investigate bot failures (e.g. https://lab.llvm.org/buildbot/#/builders/272/builds/2573)
1 parent d281941 commit df2485b

File tree

8 files changed

+75
-172
lines changed

8 files changed

+75
-172
lines changed

compiler-rt/test/orc/TestCases/Darwin/x86-64/jit-re-dlopen-data-reset.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// RUN: %clang -c -o %t.main.o %p/Inputs/dlopen-dlclose-x2.S
44
// RUN: %clang -c -o %t.inits.o %s
55
// RUN: %llvm_jitlink \
6-
// RUN: -alias Platform:_dlopen=___orc_rt_macho_jit_dlopen \
7-
// RUN: -alias Platform:_dlclose=___orc_rt_macho_jit_dlclose \
6+
// RUN: -alias _dlopen=___orc_rt_macho_jit_dlopen \
7+
// RUN: -alias _dlclose=___orc_rt_macho_jit_dlclose \
88
// RUN: %t.main.o -jd inits %t.inits.o -lmain | FileCheck %s
99

1010
// CHECK: entering main

compiler-rt/test/orc/TestCases/Darwin/x86-64/jit-re-dlopen-trivial.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
// RUN: %clang -c -o %t.main.o %p/Inputs/dlopen-dlclose-x2.S
88
// RUN: %clang -c -o %t.inits.o %s
99
// RUN: %llvm_jitlink \
10-
// RUN: -alias Platform:_dlopen=___orc_rt_macho_jit_dlopen \
11-
// RUN: -alias Platform:_dlclose=___orc_rt_macho_jit_dlclose \
10+
// RUN: -alias _dlopen=___orc_rt_macho_jit_dlopen \
11+
// RUN: -alias _dlclose=___orc_rt_macho_jit_dlclose \
1212
// RUN: %t.main.o -jd inits %t.inits.o -lmain | FileCheck %s
1313

1414
// CHECK: entering main

compiler-rt/test/orc/TestCases/Darwin/x86-64/trivial-jit-dlopen-nested.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// RUN: %clang -c -o %t.inits.o %p/Inputs/standalone-ctor-and-cxa-atexit-dtor.S
66
// RUN: %clang -c -o %t.test.o %s
77
// RUN: %llvm_jitlink \
8-
// RUN: -alias Platform:_dlopen=___orc_rt_macho_jit_dlopen \
9-
// RUN: -alias Platform:_dlclose=___orc_rt_macho_jit_dlclose \
8+
// RUN: -alias _dlopen=___orc_rt_macho_jit_dlopen \
9+
// RUN: -alias _dlclose=___orc_rt_macho_jit_dlclose \
1010
// RUN: %t.test.o -jd inits %t.inits.o -lmain | FileCheck %s
1111

1212
// CHECK: entering main

compiler-rt/test/orc/TestCases/Darwin/x86-64/trivial-jit-dlopen.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// RUN: %clang -c -o %t.inits.o %p/Inputs/standalone-ctor-and-cxa-atexit-dtor.S
66
// RUN: %clang -c -o %t.test.o %s
77
// RUN: %llvm_jitlink \
8-
// RUN: -alias Platform:_dlopen=___orc_rt_macho_jit_dlopen \
9-
// RUN: -alias Platform:_dlclose=___orc_rt_macho_jit_dlclose \
8+
// RUN: -alias _dlopen=___orc_rt_macho_jit_dlopen \
9+
// RUN: -alias _dlclose=___orc_rt_macho_jit_dlclose \
1010
// RUN: %t.test.o -jd inits %t.inits.o -lmain | FileCheck %s
1111

1212
// CHECK: entering main

compiler-rt/test/orc/TestCases/Windows/x86-64/trivial-jit-dlopen.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// RUN: %clang_cl -MD -c -o %t.inits.o %p/Inputs/standalone-dylib.c
66
// RUN: %clang_cl -MD -c -o %t.test.o %s
77
// RUN: %llvm_jitlink \
8-
// RUN: -alias Platform:dlopen=__orc_rt_coff_jit_dlopen \
9-
// RUN: -alias Platform:dlclose=__orc_rt_coff_jit_dlclose \
8+
// RUN: -alias dlopen=__orc_rt_coff_jit_dlopen \
9+
// RUN: -alias dlclose=__orc_rt_coff_jit_dlclose \
1010
// RUN: %t.test.o -jd inits %t.inits.o -lmain | FileCheck %s
1111

1212
// CHECK: entering main

llvm/test/ExecutionEngine/JITLink/AArch32/ELF_thumbv7_printf.s

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
// Check that main is a thumb symbol (with LSB set) and printf is arm (with LSB clear)
55
//
6-
// CHECK-LABEL: JITDylib "main"
7-
// CHECK-NEXT: Link order: [ ("main", MatchAllSymbols), ("Process", MatchExportedSymbolsOnly) ]
8-
// CHECK-NEXT: Symbol table:
6+
// CHECK-LABEL: Symbol table:
97
// CHECK-NEXT: "main": 0x{{[0-9a-f]+[13579bdf]}} [Callable] Ready
108
// CHECK-NEXT: "printf": 0x76bbe880 [Data] Ready
119

llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Lines changed: 64 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -692,12 +692,11 @@ getTestObjectFileInterface(Session &S, MemoryBufferRef O) {
692692
}
693693

694694
static Error loadProcessSymbols(Session &S) {
695-
S.ProcessSymsJD = &S.ES.createBareJITDylib("Process");
696695
auto FilterMainEntryPoint =
697696
[EPName = S.ES.intern(EntryPointName)](SymbolStringPtr Name) {
698697
return Name != EPName;
699698
};
700-
S.ProcessSymsJD->addGenerator(
699+
S.MainJD->addGenerator(
701700
ExitOnErr(orc::EPCDynamicLibrarySearchGenerator::GetForTargetProcess(
702701
S.ES, std::move(FilterMainEntryPoint))));
703702

@@ -708,9 +707,8 @@ static Error loadDylibs(Session &S) {
708707
LLVM_DEBUG(dbgs() << "Loading dylibs...\n");
709708
for (const auto &Dylib : Dylibs) {
710709
LLVM_DEBUG(dbgs() << " " << Dylib << "\n");
711-
auto DL = S.getOrLoadDynamicLibrary(Dylib);
712-
if (!DL)
713-
return DL.takeError();
710+
if (auto Err = S.loadAndLinkDynamicLibrary(*S.MainJD, Dylib))
711+
return Err;
714712
}
715713

716714
return Error::success();
@@ -965,79 +963,69 @@ Session::Session(std::unique_ptr<ExecutorProcessControl> EPC, Error &Err)
965963

966964
ES.setErrorReporter(reportLLVMJITLinkError);
967965

966+
if (auto MainJDOrErr = ES.createJITDylib("main"))
967+
MainJD = &*MainJDOrErr;
968+
else {
969+
Err = MainJDOrErr.takeError();
970+
return;
971+
}
972+
968973
if (!NoProcessSymbols)
969974
ExitOnErr(loadProcessSymbols(*this));
975+
else {
976+
// This symbol is used in testcases.
977+
auto &TestResultJD = ES.createBareJITDylib("<TestResultJD>");
978+
ExitOnErr(TestResultJD.define(absoluteSymbols(
979+
{{ES.intern("llvm_jitlink_setTestResultOverride"),
980+
{ExecutorAddr::fromPtr(llvm_jitlink_setTestResultOverride),
981+
JITSymbolFlags::Exported}}})));
982+
MainJD->addToLinkOrder(TestResultJD);
983+
}
970984

971985
ExitOnErr(loadDylibs(*this));
972986

973987
auto &TT = ES.getTargetTriple();
974988

975-
if (DebuggerSupport && TT.isOSBinFormatMachO()) {
976-
if (!ProcessSymsJD) {
977-
Err = make_error<StringError>("MachO debugging requires process symbols",
978-
inconvertibleErrorCode());
979-
return;
980-
}
981-
ObjLayer.addPlugin(ExitOnErr(GDBJITDebugInfoRegistrationPlugin::Create(
982-
this->ES, *ProcessSymsJD, TT)));
983-
}
989+
if (DebuggerSupport && TT.isOSBinFormatMachO())
990+
ObjLayer.addPlugin(ExitOnErr(
991+
GDBJITDebugInfoRegistrationPlugin::Create(this->ES, *MainJD, TT)));
984992

985993
if (PerfSupport && TT.isOSBinFormatELF()) {
986-
if (!ProcessSymsJD) {
987-
Err = make_error<StringError>("MachO debugging requires process symbols",
988-
inconvertibleErrorCode());
989-
return;
990-
}
991994
ObjLayer.addPlugin(ExitOnErr(DebugInfoPreservationPlugin::Create()));
992995
ObjLayer.addPlugin(ExitOnErr(PerfSupportPlugin::Create(
993-
this->ES.getExecutorProcessControl(), *ProcessSymsJD, true, true)));
996+
this->ES.getExecutorProcessControl(), *MainJD, true, true)));
994997
}
995998

996999
// Set up the platform.
997-
if (!OrcRuntime.empty()) {
998-
assert(ProcessSymsJD && "ProcessSymsJD should have been set");
999-
PlatformJD = &ES.createBareJITDylib("Platform");
1000-
PlatformJD->addToLinkOrder(*ProcessSymsJD);
1001-
1002-
if (TT.isOSBinFormatMachO()) {
1003-
if (auto P = MachOPlatform::Create(ES, ObjLayer, *PlatformJD,
1004-
OrcRuntime.c_str()))
1005-
ES.setPlatform(std::move(*P));
1006-
else {
1007-
Err = P.takeError();
1008-
return;
1009-
}
1010-
} else if (TT.isOSBinFormatELF()) {
1011-
if (auto P = ELFNixPlatform::Create(ES, ObjLayer, *PlatformJD,
1012-
OrcRuntime.c_str()))
1013-
ES.setPlatform(std::move(*P));
1014-
else {
1015-
Err = P.takeError();
1016-
return;
1017-
}
1018-
} else if (TT.isOSBinFormatCOFF()) {
1019-
auto LoadDynLibrary = [&, this](JITDylib &JD,
1020-
StringRef DLLName) -> Error {
1021-
if (!DLLName.ends_with_insensitive(".dll"))
1022-
return make_error<StringError>("DLLName not ending with .dll",
1023-
inconvertibleErrorCode());
1024-
return loadAndLinkDynamicLibrary(JD, DLLName);
1025-
};
1000+
if (TT.isOSBinFormatMachO() && !OrcRuntime.empty()) {
1001+
if (auto P =
1002+
MachOPlatform::Create(ES, ObjLayer, *MainJD, OrcRuntime.c_str()))
1003+
ES.setPlatform(std::move(*P));
1004+
else {
1005+
Err = P.takeError();
1006+
return;
1007+
}
1008+
} else if (TT.isOSBinFormatELF() && !OrcRuntime.empty()) {
1009+
if (auto P =
1010+
ELFNixPlatform::Create(ES, ObjLayer, *MainJD, OrcRuntime.c_str()))
1011+
ES.setPlatform(std::move(*P));
1012+
else {
1013+
Err = P.takeError();
1014+
return;
1015+
}
1016+
} else if (TT.isOSBinFormatCOFF() && !OrcRuntime.empty()) {
1017+
auto LoadDynLibrary = [&, this](JITDylib &JD, StringRef DLLName) -> Error {
1018+
if (!DLLName.ends_with_insensitive(".dll"))
1019+
return make_error<StringError>("DLLName not ending with .dll",
1020+
inconvertibleErrorCode());
1021+
return loadAndLinkDynamicLibrary(JD, DLLName);
1022+
};
10261023

1027-
if (auto P = COFFPlatform::Create(ES, ObjLayer, *PlatformJD,
1028-
OrcRuntime.c_str(),
1029-
std::move(LoadDynLibrary)))
1030-
ES.setPlatform(std::move(*P));
1031-
else {
1032-
Err = P.takeError();
1033-
return;
1034-
}
1035-
} else {
1036-
Err = make_error<StringError>(
1037-
"-" + OrcRuntime.ArgStr + " specified, but format " +
1038-
Triple::getObjectFormatTypeName(TT.getObjectFormat()) +
1039-
" not supported",
1040-
inconvertibleErrorCode());
1024+
if (auto P = COFFPlatform::Create(ES, ObjLayer, *MainJD, OrcRuntime.c_str(),
1025+
std::move(LoadDynLibrary)))
1026+
ES.setPlatform(std::move(*P));
1027+
else {
1028+
Err = P.takeError();
10411029
return;
10421030
}
10431031
} else if (TT.isOSBinFormatELF()) {
@@ -1049,24 +1037,6 @@ Session::Session(std::unique_ptr<ExecutorProcessControl> EPC, Error &Err)
10491037
ES, ExitOnErr(createJITLoaderGDBRegistrar(this->ES)), true, true));
10501038
}
10511039

1052-
if (auto MainJDOrErr = ES.createJITDylib("main"))
1053-
MainJD = &*MainJDOrErr;
1054-
else {
1055-
Err = MainJDOrErr.takeError();
1056-
return;
1057-
}
1058-
1059-
if (NoProcessSymbols) {
1060-
// This symbol is used in testcases, but we're not reflecting process
1061-
// symbols so we'll need to make it available some other way.
1062-
auto &TestResultJD = ES.createBareJITDylib("<TestResultJD>");
1063-
ExitOnErr(TestResultJD.define(absoluteSymbols(
1064-
{{ES.intern("llvm_jitlink_setTestResultOverride"),
1065-
{ExecutorAddr::fromPtr(llvm_jitlink_setTestResultOverride),
1066-
JITSymbolFlags::Exported}}})));
1067-
MainJD->addToLinkOrder(TestResultJD);
1068-
}
1069-
10701040
ObjLayer.addPlugin(std::make_unique<JITLinkSessionPlugin>(*this));
10711041

10721042
// Process any harness files.
@@ -1296,10 +1266,6 @@ static Error sanitizeArguments(const Triple &TT, const char *ArgV0) {
12961266
if (DebuggerSupport.getNumOccurrences() == 0 && NoExec)
12971267
DebuggerSupport = false;
12981268

1299-
if (!OrcRuntime.empty() && NoProcessSymbols)
1300-
return make_error<StringError>("-orc-runtime requires process symbols",
1301-
inconvertibleErrorCode());
1302-
13031269
// If -slab-allocate is passed, check that we're not trying to use it in
13041270
// -oop-executor or -oop-executor-connect mode.
13051271
//
@@ -1399,13 +1365,6 @@ static Error createJITDylibs(Session &S,
13991365
}
14001366
}
14011367

1402-
if (S.PlatformJD)
1403-
S.JDSearchOrder.push_back(
1404-
{S.PlatformJD, JITDylibLookupFlags::MatchExportedSymbolsOnly});
1405-
if (S.ProcessSymsJD)
1406-
S.JDSearchOrder.push_back(
1407-
{S.ProcessSymsJD, JITDylibLookupFlags::MatchExportedSymbolsOnly});
1408-
14091368
LLVM_DEBUG({
14101369
dbgs() << "Dylib search order is [ ";
14111370
for (auto &KV : S.JDSearchOrder)
@@ -1457,67 +1416,23 @@ static Error addAliases(Session &S,
14571416
const std::map<unsigned, JITDylib *> &IdxToJD) {
14581417
// Define absolute symbols.
14591418
LLVM_DEBUG(dbgs() << "Defining aliases...\n");
1460-
1461-
DenseMap<std::pair<JITDylib *, JITDylib *>, SymbolAliasMap> Reexports;
14621419
for (auto AliasItr = Aliases.begin(), AliasEnd = Aliases.end();
14631420
AliasItr != AliasEnd; ++AliasItr) {
1421+
unsigned AliasArgIdx = Aliases.getPosition(AliasItr - Aliases.begin());
1422+
auto &JD = *std::prev(IdxToJD.lower_bound(AliasArgIdx))->second;
14641423

1465-
auto BadExpr = [&]() {
1466-
return make_error<StringError>(
1467-
"Invalid alias definition \"" + *AliasItr +
1468-
"\". Syntax: [<dst-jd>:]<alias>=[<src-jd>:]<aliasee>",
1469-
inconvertibleErrorCode());
1470-
};
1471-
1472-
auto GetJD = [&](StringRef JDName) -> Expected<JITDylib *> {
1473-
if (JDName.empty()) {
1474-
unsigned AliasArgIdx = Aliases.getPosition(AliasItr - Aliases.begin());
1475-
return std::prev(IdxToJD.lower_bound(AliasArgIdx))->second;
1476-
}
1477-
1478-
auto *JD = S.ES.getJITDylibByName(JDName);
1479-
if (!JD)
1480-
return make_error<StringError>(StringRef("In alias definition \"") +
1481-
*AliasItr + "\" no dylib named " +
1482-
JDName,
1483-
inconvertibleErrorCode());
1484-
1485-
return JD;
1486-
};
1487-
1488-
{
1489-
// First split on '=' to get alias and aliasee.
1490-
StringRef AliasStmt = *AliasItr;
1491-
auto [AliasExpr, AliaseeExpr] = AliasStmt.split('=');
1492-
if (AliaseeExpr.empty())
1493-
return BadExpr();
1494-
1495-
auto [AliasJDName, Alias] = AliasExpr.split(':');
1496-
if (Alias.empty())
1497-
std::swap(AliasJDName, Alias);
1498-
1499-
auto AliasJD = GetJD(AliasJDName);
1500-
if (!AliasJD)
1501-
return AliasJD.takeError();
1502-
1503-
auto [AliaseeJDName, Aliasee] = AliaseeExpr.split(':');
1504-
if (Aliasee.empty())
1505-
std::swap(AliaseeJDName, Aliasee);
1506-
1507-
if (AliaseeJDName.empty() && !AliasJDName.empty())
1508-
AliaseeJDName = AliasJDName;
1509-
auto AliaseeJD = GetJD(AliaseeJDName);
1510-
if (!AliaseeJD)
1511-
return AliaseeJD.takeError();
1512-
1513-
Reexports[{*AliasJD, *AliaseeJD}][S.ES.intern(Alias)] = {
1514-
S.ES.intern(Aliasee), JITSymbolFlags::Exported};
1515-
}
1516-
}
1424+
StringRef AliasStmt = *AliasItr;
1425+
size_t EqIdx = AliasStmt.find_first_of('=');
1426+
if (EqIdx == StringRef::npos)
1427+
return make_error<StringError>("Invalid alias definition \"" + AliasStmt +
1428+
"\". Syntax: <name>=<addr>",
1429+
inconvertibleErrorCode());
1430+
StringRef Alias = AliasStmt.substr(0, EqIdx).trim();
1431+
StringRef Aliasee = AliasStmt.substr(EqIdx + 1).trim();
15171432

1518-
for (auto &[JDs, AliasMap] : Reexports) {
1519-
auto [DstJD, SrcJD] = JDs;
1520-
if (auto Err = DstJD->define(reexports(*SrcJD, std::move(AliasMap))))
1433+
SymbolAliasMap SAM;
1434+
SAM[S.ES.intern(Alias)] = {S.ES.intern(Aliasee), JITSymbolFlags::Exported};
1435+
if (auto Err = JD.define(symbolAliases(std::move(SAM))))
15211436
return Err;
15221437
}
15231438

@@ -1851,14 +1766,6 @@ static Error addLibraries(Session &S,
18511766
inconvertibleErrorCode());
18521767
}
18531768

1854-
// Add platform and process symbols if available.
1855-
for (auto &[Idx, JD] : IdxToJD) {
1856-
if (S.PlatformJD)
1857-
JD->addToLinkOrder(*S.PlatformJD);
1858-
if (S.ProcessSymsJD)
1859-
JD->addToLinkOrder(*S.ProcessSymsJD);
1860-
}
1861-
18621769
return Error::success();
18631770
}
18641771

llvm/tools/llvm-jitlink/llvm-jitlink.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ struct Session {
3131

3232
orc::ExecutionSession ES;
3333
orc::JITDylib *MainJD = nullptr;
34-
orc::JITDylib *ProcessSymsJD = nullptr;
35-
orc::JITDylib *PlatformJD = nullptr;
3634
orc::ObjectLinkingLayer ObjLayer;
3735
orc::JITDylibSearchOrder JDSearchOrder;
3836
SubtargetFeatures Features;

0 commit comments

Comments
 (0)