This is an archive of the discontinued LLVM Phabricator instance.

[Orc] Fix race condition in DebugObjectManagerPlugin
ClosedPublic

Authored by sgraenitz on Mar 11 2021, 5:41 AM.

Details

Summary

During finalization the debug object is registered with the target. Materialization must wait for this process to finish. Otherwise we might start running code before the debugger finished processing the corresponding debug info.

Diff Detail

Event Timeline

sgraenitz created this revision.Mar 11 2021, 5:41 AM
sgraenitz requested review of this revision.Mar 11 2021, 5:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 11 2021, 5:41 AM

This means that materialization is blocked until finalization of the debug object allocation is done, i.e.:

  • memory was copied over to the target
  • an entry was added to the JIT descriptor (locks a global mutex)
  • the executing process ran into the rendezvous breakpoint (1st process switch)
  • the debugger processed the debug object, read the symbol table and returned control back to the executor (2nd process switch)

This might introduce a considerable delay in materialization. I wonder if this points out an interesting design question for the plugin API: Debug registration could run safely in parallel up to the point that execution reaches the emitted code. The only way I see to achieve it with the current API is blocking the notifyEmitted() callback. Could we instead return the promise and wait for it at a later point in time?

lhames accepted this revision.Mar 11 2021, 9:09 AM

LGTM.

This might introduce a considerable delay in materialization. I wonder if this points out an interesting design question for the plugin API...

I think you're right, but rather than approach this through the plugin API I think the solution will come from rethinking "finalization" on the memory manager API: If we represented all the various pieces of metadata (eh-frames, objc registration, debug registration, etc.) as sections in the allocation, and allowed additional operations to be attached to the finalization call, then we could do everything in one RPC round trip.

This revision is now accepted and ready to land.Mar 11 2021, 9:09 AM

I think you're right, but rather than approach this through the plugin API I think the solution will come from rethinking "finalization" on the memory manager API

Alright, that sounds reasonable. Having this delay for debugging use cases should be acceptable for the moment. It can be avoided by feeding in modules without debug info. The plugin detects that and stops any further processing early on.

This revision was automatically updated to reflect the committed changes.