[llvm] 01353d8 - [llvm-jitlink] Allow -entry option to find hidden symbols.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 4 21:26:28 PST 2021
Author: Lang Hames
Date: 2021-12-05T16:26:21+11:00
New Revision: 01353d81ea607c587d00d905a12dcddd8f34548e
URL: https://github.com/llvm/llvm-project/commit/01353d81ea607c587d00d905a12dcddd8f34548e
DIFF: https://github.com/llvm/llvm-project/commit/01353d81ea607c587d00d905a12dcddd8f34548e.diff
LOG: [llvm-jitlink] Allow -entry option to find hidden symbols.
This is useful when debugging failures in object files compiled with
visibility=hidden.
Added:
Modified:
llvm/tools/llvm-jitlink/llvm-jitlink.cpp
llvm/tools/llvm-jitlink/llvm-jitlink.h
Removed:
################################################################################
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index 202b459a6078f..b643a8f0f76d6 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -1301,7 +1301,7 @@ static Error loadObjects(Session &S) {
{
// Create a "main" JITLinkDylib.
IdxToJLD[0] = S.MainJD;
- S.JDSearchOrder.push_back(S.MainJD);
+ S.JDSearchOrder.push_back({S.MainJD, JITDylibLookupFlags::MatchAllSymbols});
LLVM_DEBUG(dbgs() << " 0: " << S.MainJD->getName() << "\n");
// Add any extra JITLinkDylibs from the command line.
@@ -1314,15 +1314,18 @@ static Error loadObjects(Session &S) {
unsigned JDIdx =
JITLinkDylibs.getPosition(JLDItr - JITLinkDylibs.begin());
IdxToJLD[JDIdx] = &*JD;
- S.JDSearchOrder.push_back(&*JD);
+ S.JDSearchOrder.push_back({&*JD, JITDylibLookupFlags::MatchAllSymbols});
LLVM_DEBUG(dbgs() << " " << JDIdx << ": " << JD->getName() << "\n");
}
- // Set every dylib to link against every other, in command line order.
- for (auto *JD : S.JDSearchOrder) {
+ // Set every dylib to link against every other, in command line order,
+ // using exported symbols only.
+ for (auto &KV : S.JDSearchOrder) {
+ auto *JD = KV.first;
auto LookupFlags = JITDylibLookupFlags::MatchExportedSymbolsOnly;
JITDylibSearchOrder LinkOrder;
- for (auto *JD2 : S.JDSearchOrder) {
+ for (auto &KV2 : S.JDSearchOrder) {
+ auto *JD2 = KV2.first;
if (JD2 == JD)
continue;
LinkOrder.push_back(std::make_pair(JD2, LookupFlags));
@@ -1395,8 +1398,8 @@ static Error loadObjects(Session &S) {
LLVM_DEBUG({
dbgs() << "Dylib search order is [ ";
- for (auto *JD : S.JDSearchOrder)
- dbgs() << JD->getName() << " ";
+ for (auto &KV : S.JDSearchOrder)
+ dbgs() << KV.first->getName() << " ";
dbgs() << "]\n";
});
@@ -1553,7 +1556,7 @@ static void dumpSessionStats(Session &S) {
}
static Expected<JITEvaluatedSymbol> getMainEntryPoint(Session &S) {
- return S.ES.lookup(S.JDSearchOrder, EntryPointName);
+ return S.ES.lookup(S.JDSearchOrder, S.ES.intern(EntryPointName));
}
static Expected<JITEvaluatedSymbol> getOrcRuntimeEntryPoint(Session &S) {
@@ -1561,7 +1564,7 @@ static Expected<JITEvaluatedSymbol> getOrcRuntimeEntryPoint(Session &S) {
const auto &TT = S.ES.getExecutorProcessControl().getTargetTriple();
if (TT.getObjectFormat() == Triple::MachO)
RuntimeEntryPoint = '_' + RuntimeEntryPoint;
- return S.ES.lookup(S.JDSearchOrder, RuntimeEntryPoint);
+ return S.ES.lookup(S.JDSearchOrder, S.ES.intern(RuntimeEntryPoint));
}
static Expected<int> runWithRuntime(Session &S, ExecutorAddr EntryPointAddr) {
@@ -1630,11 +1633,20 @@ int main(int argc, char *argv[]) {
// Find the entry-point function unconditionally, since we want to force
// it to be materialized to collect stats.
EntryPoint = ExitOnErr(getMainEntryPoint(*S));
+ LLVM_DEBUG({
+ dbgs() << "Using entry point \"" << EntryPointName
+ << "\": " << formatv("{0:x16}", EntryPoint.getAddress()) << "\n";
+ });
// If we're running with the ORC runtime then replace the entry-point
// with the __orc_rt_run_program symbol.
- if (!OrcRuntime.empty())
+ if (!OrcRuntime.empty()) {
EntryPoint = ExitOnErr(getOrcRuntimeEntryPoint(*S));
+ LLVM_DEBUG({
+ dbgs() << "(called via __orc_rt_run_program_wrapper at "
+ << formatv("{0:x16}", EntryPoint.getAddress()) << ")\n";
+ });
+ }
}
if (ShowAddrs)
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.h b/llvm/tools/llvm-jitlink/llvm-jitlink.h
index ecf370959385d..7d58cd4ac62f1 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.h
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.h
@@ -50,7 +50,7 @@ struct Session {
orc::ExecutionSession ES;
orc::JITDylib *MainJD = nullptr;
LLVMJITLinkObjectLinkingLayer ObjLayer;
- std::vector<orc::JITDylib *> JDSearchOrder;
+ orc::JITDylibSearchOrder JDSearchOrder;
~Session();
More information about the llvm-commits
mailing list