-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a few JITLink nits #46216
Merged
Merged
Fix a few JITLink nits #46216
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -540,6 +540,7 @@ struct JITObjectInfo { | |
}; | ||
|
||
class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin { | ||
std::mutex PluginMutex; | ||
std::map<MaterializationResponsibility *, std::unique_ptr<JITObjectInfo>> PendingObjs; | ||
// Resources from distinct MaterializationResponsibilitys can get merged | ||
// after emission, so we can have multiple debug objects per resource key. | ||
|
@@ -560,33 +561,40 @@ class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin { | |
auto NewObj = | ||
cantFail(object::ObjectFile::createObjectFile(NewBuffer->getMemBufferRef())); | ||
|
||
assert(PendingObjs.count(&MR) == 0); | ||
PendingObjs[&MR] = std::unique_ptr<JITObjectInfo>( | ||
new JITObjectInfo{std::move(NewBuffer), std::move(NewObj), {}}); | ||
{ | ||
std::lock_guard<std::mutex> lock(PluginMutex); | ||
assert(PendingObjs.count(&MR) == 0); | ||
PendingObjs[&MR] = std::unique_ptr<JITObjectInfo>( | ||
new JITObjectInfo{std::move(NewBuffer), std::move(NewObj), {}}); | ||
} | ||
} | ||
|
||
Error notifyEmitted(MaterializationResponsibility &MR) override | ||
{ | ||
auto It = PendingObjs.find(&MR); | ||
if (It == PendingObjs.end()) | ||
return Error::success(); | ||
|
||
auto NewInfo = PendingObjs[&MR].get(); | ||
auto getLoadAddress = [NewInfo](const StringRef &Name) -> uint64_t { | ||
auto result = NewInfo->SectionLoadAddresses.find(Name); | ||
if (result == NewInfo->SectionLoadAddresses.end()) { | ||
LLVM_DEBUG({ | ||
dbgs() << "JLDebuginfoPlugin: No load address found for section '" | ||
<< Name << "'\n"; | ||
}); | ||
return 0; | ||
} | ||
return result->second; | ||
}; | ||
{ | ||
std::lock_guard<std::mutex> lock(PluginMutex); | ||
auto It = PendingObjs.find(&MR); | ||
if (It == PendingObjs.end()) | ||
return Error::success(); | ||
|
||
auto NewInfo = PendingObjs[&MR].get(); | ||
auto getLoadAddress = [NewInfo](const StringRef &Name) -> uint64_t { | ||
auto result = NewInfo->SectionLoadAddresses.find(Name); | ||
if (result == NewInfo->SectionLoadAddresses.end()) { | ||
LLVM_DEBUG({ | ||
dbgs() << "JLDebuginfoPlugin: No load address found for section '" | ||
<< Name << "'\n"; | ||
}); | ||
return 0; | ||
} | ||
return result->second; | ||
}; | ||
|
||
jl_register_jit_object(*NewInfo->Object, getLoadAddress, nullptr); | ||
jl_register_jit_object(*NewInfo->Object, getLoadAddress, nullptr); | ||
} | ||
|
||
cantFail(MR.withResourceKeyDo([&](ResourceKey K) { | ||
std::lock_guard<std::mutex> lock(PluginMutex); | ||
RegisteredObjs[K].push_back(std::move(PendingObjs[&MR])); | ||
PendingObjs.erase(&MR); | ||
})); | ||
|
@@ -596,19 +604,22 @@ class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin { | |
|
||
Error notifyFailed(MaterializationResponsibility &MR) override | ||
{ | ||
std::lock_guard<std::mutex> lock(PluginMutex); | ||
PendingObjs.erase(&MR); | ||
return Error::success(); | ||
} | ||
|
||
Error notifyRemovingResources(ResourceKey K) override | ||
{ | ||
std::lock_guard<std::mutex> lock(PluginMutex); | ||
RegisteredObjs.erase(K); | ||
// TODO: If we ever unload code, need to notify debuginfo registry. | ||
return Error::success(); | ||
} | ||
|
||
void notifyTransferringResources(ResourceKey DstKey, ResourceKey SrcKey) override | ||
{ | ||
std::lock_guard<std::mutex> lock(PluginMutex); | ||
auto SrcIt = RegisteredObjs.find(SrcKey); | ||
if (SrcIt != RegisteredObjs.end()) { | ||
for (std::unique_ptr<JITObjectInfo> &Info : SrcIt->second) | ||
|
@@ -620,13 +631,16 @@ class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin { | |
void modifyPassConfig(MaterializationResponsibility &MR, jitlink::LinkGraph &, | ||
jitlink::PassConfiguration &PassConfig) override | ||
{ | ||
std::lock_guard<std::mutex> lock(PluginMutex); | ||
auto It = PendingObjs.find(&MR); | ||
if (It == PendingObjs.end()) | ||
return; | ||
|
||
JITObjectInfo &Info = *It->second; | ||
PassConfig.PostAllocationPasses.push_back([&Info](jitlink::LinkGraph &G) -> Error { | ||
PassConfig.PostAllocationPasses.push_back([&Info, this](jitlink::LinkGraph &G) -> Error { | ||
std::lock_guard<std::mutex> lock(PluginMutex); | ||
for (const jitlink::Section &Sec : G.sections()) { | ||
#ifdef _OS_DARWIN_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
// Canonical JITLink section names have the segment name included, e.g. | ||
// "__TEXT,__text" or "__DWARF,__debug_str". There are some special internal | ||
// sections without a comma separator, which we can just ignore. | ||
|
@@ -639,6 +653,9 @@ class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin { | |
continue; | ||
} | ||
auto SecName = Sec.getName().substr(SepPos + 1); | ||
#else | ||
auto SecName = Sec.getName(); | ||
#endif | ||
// https://github.com/llvm/llvm-project/commit/118e953b18ff07d00b8f822dfbf2991e41d6d791 | ||
#if JL_LLVM_VERSION >= 140000 | ||
Info.SectionLoadAddresses[SecName] = jitlink::SectionRange(Sec).getStart().getValue(); | ||
|
@@ -1051,7 +1068,7 @@ JuliaOJIT::JuliaOJIT() | |
OptSelLayer(Pipelines) | ||
{ | ||
#ifdef JL_USE_JITLINK | ||
# if defined(_OS_DARWIN_) && defined(LLVM_SHLIB) | ||
# if defined(LLVM_SHLIB) | ||
// When dynamically linking against LLVM, use our custom EH frame registration code | ||
// also used with RTDyld to inform both our and the libc copy of libunwind. | ||
auto ehRegistrar = std::make_unique<JLEHFrameRegistrar>(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion here, but my thinking behind making it an error was that the USE_*_JITEVENTS flags need to be explicitly specified by the user, so if they can't be honoured, they shouldn't be silently ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For whatever reason, at least on Linux-x86-64 the default
make
command sets one or more of these flags, so I turned it into a message so that I could test JITLink on that platform. Since at least for the time being we're not enabling JITLink on any platform except the ones that actually need it (aarch64), I thought it would be better as a message rather than an error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes on Linux we ship
perf
support by default.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right – but couldn't we then rather just change those defaults for aarch64-linux once that is switched over as well, as that would be self-documenting for users in combination with doc/src/manual/profile.md? Maybe a compiler message is visible enough, though, I haven't tried.