This is an archive of the discontinued LLVM Phabricator instance.

[JITLink][ORC] Rename MemDeallocPolicy to MemLifetimePolicy, add NoAlloc option.
ClosedPublic

Authored by lhames on Mar 15 2023, 5:48 PM.

Details

Summary

The original MemDeallocPolicy options were 'Standard' (the allocated memory
should live until the FinalizedAlloc is deallocated, or the InFlightAlloc is
abandoned) and 'Finalize' (the allocated memory should live until all finalize
actions have been run).

The new NoAlloc option indicates that the section should not have memory
allocated for it at all, and should be ignored by the JITLinkMemoryManager
(the memory manager should skip such sections entirely, allocating neither
working memory nor executor address space to them). The NoAlloc option is
intended to support metadata sections (e.g. debug info) that we want to keep in
the graph and have fixed up if necessary, but don't want allocated or
transmitted to the executor (or we want that transmission to be managed
manually by plugins).

Since NoAlloc blocks do not have working memory allocated for them by the
JITLinkMemoryManager, clients wishing to mutate their memory should call the
Block::getMutableMemory(G) method on them. This will copy the Block's content
to memory allocated on G's allocator (on first call, subsequent calls just
return the existing allocation(). If the block's content is not copied to
mutable memory prior to the fixup phase the generic link algorithm will do this
automatically. Block content in NoAlloc sections will remain available until
the LinkGraph is destroyed.

The addresses of blocks in NoAlloc sections are initialized by the LinkGraph
creator (a LinkGraphBuilder, if the graph is generated from an object file),
and is should not be modified by the JITLinkMemoryManager. Plugins are
responsible for updating addresses if they add/remove content from these
sections.

Blocks in Standard and Finalize sections should never contain edges pointing to
NonAlloc sections, as the addresses for these blocks aren't meaningful. The
LinkGraphBuilders should check this property in the input object files, and
plugins are required to preserve it.

Diff Detail

Event Timeline

lhames created this revision.Mar 15 2023, 5:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2023, 5:48 PM
lhames requested review of this revision.Mar 15 2023, 5:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2023, 5:48 PM

LinkGraphBuilder changes TBD.

I'm also rethinking this requirement:

Blocks in Standard and Finalize sections should never contain edges pointing to
NonAlloc sections, as the addresses for these blocks aren't meaningful. The
LinkGraphBuilders should check this property in the input object files, and
plugins are required to preserve it.

NoAlloc sections are effectively in a different address space, but it's probably fine to have references back and forward -- something on the executor side could still use the addresses in requests to the controller.

lhames updated this revision to Diff 505982.Mar 16 2023, 9:18 PM

Use NoAlloc lifetime in LinkGraphBuilders for COFF, ELF and MachO.

Update patch wording to clarify that edges between Standard/Finalize and
NoAlloc sections are legal in both directions, but only when the edge kinds
involved make sense.

New commit language on edges between Standard/Finalize and NoAlloc sections:

Addresses of blocks in NoAlloc sections are initialized by the LinkGraph
creator (a LinkGraphBuilder, if the graph is generated from an object file),
and should not be modified by the JITLinkMemoryManager. Plugins are responsible
for updating addresses if they add/remove content from these sections. The
meaning of addresses in NoAlloc-sections is backend/plugin-defined, but for
fixup purposes they will be treated the same as addresses in Standard/Finalize
sections. References from Standard/Finalize sections to NoAlloc sections are
expected to be common (these represent metadata tracking executor addresses).
References from NoAlloc sections to Standard/Finalize sections are expected to
be rare/non-existent (they would represent JIT'd code / data tracking metadata
in the controller, which would be surprising). LinkGraphBuilders and specific
backends may impose additional constraints on edges between Standard/Finalize
and NoAlloc sections where required for correctness.

This revision was not accepted when it landed; it landed in state Needs Review.Mar 17 2023, 12:38 PM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.