This is an archive of the discontinued LLVM Phabricator instance.

[MCJIT] Call JIT notifiers only after code sections are ready.
Needs ReviewPublic

Authored by anarazel on May 24 2018, 12:06 PM.
This revision needs review, but all reviewers have resigned.

Details

Reviewers
reames
Summary

Extracted from https://reviews.llvm.org/D44892

Previously JIT notifiers were called before relocations were
performed (leading to ominious looking function calls of "0" being
shown in debugger / profiles), and before memory marked
executable (confusing some profilers).

Move notifications to finalizeLoadedModules().

Diff Detail

Event Timeline

anarazel created this revision.May 24 2018, 12:06 PM
lhames added a subscriber: lhames.May 24 2018, 2:49 PM

This patch doesn't affect any of my use-cases, but it's possible that some clients are relying on the fact that memory will still be writable at this point.

As an alternative: ORC's RTDyldObjectLinkingLayer has a NotifyFinalized callback that is called in the equivalent location (i.e. after finalizeMemory has been called). If we want to maintain behavior for existing MCJIT clients it seems reasonable to add a matching "NotifyFinalized" callback to MCJIT.

This patch doesn't affect any of my use-cases, but it's possible that some clients are relying on the fact that memory will still be writable at this point.

Would that ever be a safe thing to do? Even if, I've a hard time seeing when that'd be a reasonable solution. Not that hacks necessarily have to be reasonable. The other in-tree users of event listeners at least don't care...

As an alternative: ORC's RTDyldObjectLinkingLayer has a NotifyFinalized callback that is called in the equivalent location (i.e. after finalizeMemory has been called). If we want to maintain behavior for existing MCJIT clients it seems reasonable to add a matching "NotifyFinalized" callback to MCJIT.

That'd make sense. OTOH, afaict it'd require changing all the existing notifier users, because they all would want the new thing.

Now that https://reviews.llvm.org/D44890 has landed, I care a bit less. I was mostly bothered because without either D44890 or this, I was unable to test D44892.

This patch doesn't affect any of my use-cases, but it's possible that some clients are relying on the fact that memory will still be writable at this point.

Would that ever be a safe thing to do? Even if, I've a hard time seeing when that'd be a reasonable solution. Not that hacks necessarily have to be reasonable. The other in-tree users of event listeners at least don't care...

I have backwards compatibility with unreasonable hacks in mind here. :)

As an alternative: ORC's RTDyldObjectLinkingLayer has a NotifyFinalized callback that is called in the equivalent location (i.e. after finalizeMemory has been called). If we want to maintain behavior for existing MCJIT clients it seems reasonable to add a matching "NotifyFinalized" callback to MCJIT.

That'd make sense. OTOH, afaict it'd require changing all the existing notifier users, because they all would want the new thing.

Now that https://reviews.llvm.org/D44890 has landed, I care a bit less. I was mostly bothered because without either D44890 or this, I was unable to test D44892.

Ok. If this is no longer urgent I'll close this revision and revisit the alternative (adding NotifyFinalized) in the future. Does that sound ok to you?

reames resigned from this revision.Mar 25 2020, 11:16 AM