Commit Graph

852 Commits

Author SHA1 Message Date
Fangrui Song a996cc217c Remove unused #include "llvm/ADT/Optional.h" 2022-12-05 06:31:11 +00:00
Kazu Hirata aadaaface2 [llvm] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-02 21:11:44 -08:00
David Blaikie 1c2ee6bdce Add void cast for preprocessor-conditionall-unused loop variable
Fixing -Wunused -Werror build on Android.
2022-12-02 02:24:56 +00:00
Kazu Hirata 54ea422d9f [Orc] Use std::optional in ObjectFileInterface.cpp (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-26 15:24:34 -08:00
Kazu Hirata 0b5ba08013 [Orc] Use std::optional in MachOPlatform.cpp (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-26 15:22:05 -08:00
Kazu Hirata 6698a2b6af [Orc] Use std::optional in ELFNixPlatform.cpp (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-26 15:19:50 -08:00
Kazu Hirata e35c73f31c [Orc] Use std::optional in Core.cpp (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-26 15:17:42 -08:00
Lang Hames 5f479ee7fc [ORC] Capture JD by value in MachOPlatform::pushInitializersLoop.
The lambda may run after pushInitializersLoop returns.
2022-11-11 16:01:25 -08:00
Lang Hames ba26b5ef15 [ORC] Mark late-claimed weak symbols as live in ObjectLinkingLayer.
ObjectLinkingLayer attempts to claim responsibility for weak definitions that
are present in LinkGraphs, but not present in the corresponding
MaterializationResponsibility object. Where such a claim is successful, the
symbol should be marked as live to prevent it from being dead stripped.

(For the curious: Such "late-breaking" definitions are introduced somewhere in
the materialization pipeline after the initial responsibility set is calculated.
The usual source is the complier or assembler. Examples of common late-breaking
definitions include personality pointers, e.g. "DW.ref.__gxx_personality_v0",
and named constant pool entries, e.g. __realXX..XX.)

The failure to mark these symbols live caused few problems in practice because
late-breaking definitions are usually anchored by existing live definitions
within the graph (e.g. DW.ref.__gxx_personality_v0 is transitively referenced by
functions via eh-frame records), and so they usually survived dead-stripping
anyway. This accidental persistence isn't a principled solution though, and it
fails altogether if a late-breaking definition is not otherwise referenced by
the graph, with the result that the now-claimed symbol is stripped triggering a
"Failed to materialize symbols" error in ORC. Marking such symbols live is the
correct solution.

No testcase, as it's difficult to construct a situation where a late-breaking
definition is inserted without being referenced outside the context of new
backend bringup or plugin-specific shenanigans.

See discussion in https://reviews.llvm.org/D133452 and
https://reviews.llvm.org/D136877.
2022-10-29 19:07:51 +00:00
Lang Hames b26f45e5a4 [ORC] Skip non-SHF_ALLOC sections in DebugObjectManagerPlugin.
We don't need to provide a load-address for non-alloc sections. Skipping them
allows us to avoid some complications, like handling duplicate .group sections.
2022-10-25 18:40:38 -07:00
Lang Hames b3c9ced93c [ORC] Allow EPCDebugObjectRegistrar clients to specify registration fn dylib.
Similar to the EPCEHFrameRegistrar change in c977251ef6, this allows clients
who have sourced a dylib handle via a side-channel to search that dylib to
find the registration functions.

This patch defaults to the existing behavior in the case where the client does
not specify a handle to use.
2022-10-25 08:50:27 -07:00
Lang Hames 9000ee2224 [ORC] Update SelfExecutorProcessControl to allow user-supplied handles.
SelfExecutorProcessControl no longer requires that handles passed to
lookupSymbols be ones that were previously returned from loadDylib. This brings
SelfExecutorPRocessControl into alignment with SimpleRemoteEPC, which was
updated in 6613f4aff8.
2022-10-25 08:50:27 -07:00
Lang Hames c977251ef6 [ORC] Allow EPCEHFrameRegistrar clients to specify registration function dylib.
Previously, EPCEHFrameRegistrar always used the
ExecutorProcessControl::loadDylib(nullptr) method to obtain a handle for the
process, but this doesn't work if the registration functions aren't visible in
a standard search of the process (e.g. if the JIT is in a plugin that is loaded
with RTLD_LOCAL).

This patch retains the old behavior by default, but allows clients to supply
their own handle for the library containing the registration functions if they
need to (e.g. to work around limitations like RDLD_LOCAL above, which aren't
expressible within the existing loadDylib / DynamicLibrary APIs).
2022-10-24 13:57:04 -07:00
Lang Hames 6613f4aff8 [ORC] Use raw OS handle values, ExecutorAddr for EPC dylib handles.
Updates tpctypes::DylibHandle to be an ExecutorAddr (rather than a uint64_t),
and SimpleExecutorDylibManager to hold and return raw OS handle values (as
ExecutorAddrs) rather than index values into a map of DynamicLibrary instances.

This will allow clients to use EPCGenericDylibManager in contexts where the
existing DynamicLibrary interface is too limited to be used. (e.g. to look up
JIT symbols in a dylib that was loaded with RTLD_LOCAL).
2022-10-24 13:57:04 -07:00
Lang Hames e7673d982d [ORC] Force linking of eh-frame registration functions from LLJIT.cpp.
Since aedeb8d557, which switched to EPC-based eh-frame registrationin LLJIT,
the eh-frame registration functions need to be forcibly linked into the target
process.

Failure to link the eh-frame registration functions triggered a test failure in
https://green.lab.llvm.org/green/job/clang-stage1-RA/31497, which was fixed by
forcibly linking the registration functions into that test case in saf2b2214b4
(rdar://101083784), however it has also caused some tests (e.g. the C API unit
tests) that depend on successful construction of an LLJIT instance to be
skipped.

Moving the forcible registration into LLJIT.cpp fixes the general issue.
2022-10-23 13:55:55 -07:00
Lang Hames 45b6fe8c69 [ORC] Add more information to duplicate section error message.
Now includes the name of the graph and duplicate section.
2022-10-22 05:03:11 +00:00
Lang Hames d6c9b3cc34 [ORC] Relax assertions in SimpleRemoteEPCTransport.
Null source/destination pointers are ok for zero-sized messages.
2022-10-09 21:58:10 -07:00
Lang Hames aedeb8d557 [LLJIT] Default to EPCEHFrameRegistrar rather than InProcessEHFrameRegistrar.
Now that ExecutionSession objects alway have ExecutorProcessControl (EPC)
objects attached we can use EPCEHFrameRegistrar by default, rather than
InProcessEHFrameRegistrar. This allows LLJIT to work out-of-the-box with remote
EPCs on platforms that use JITLink, without requiring a custom
ObjectLinkingLayerCreator to override the eh-frame registrar.
2022-10-09 21:58:10 -07:00
Alexandre Ganea 1c25ce1738 [Orc] Fix the SharedMemoryMapper dtor
As briefly discussed on https://reviews.llvm.org/rG1134d3a03facccd75efc5385ba46918bef94fcb6, fix the unintended copy while iterating on Reservations and add a mutex guard, to be symmetric with other usages of Reservations.

Differential revision: https://reviews.llvm.org/D134212
2022-10-05 12:16:54 -04:00
Lang Hames 3019f488f4 [ORC] Don't unnecessarily copy collection element. 2022-10-03 21:50:01 -07:00
Lang Hames ff85a1879c [ORC] Fix typo in 543790add8. 2022-10-03 20:43:48 -07:00
Lang Hames 516397e144 [ORC] More attempts to fix Windows bots after d3d9f7caf9.
Move getWindowsProtectionFlags inside namespace to make MemProt type accessible.
2022-10-03 20:31:31 -07:00
Lang Hames 543790add8 [ORC] Attempt to fix Windows bots after d3d9f7caf9.
That patch failed to include an update to the Windows side of
ExecutorSharedMemoryMapperService.
2022-10-03 20:15:58 -07:00
Lang Hames d3d9f7caf9 [ORC][JITLink] Move MemoryFlags.h (MemProt, AllocGroup,...) from JITLink to ORC.
Moving these types to OrcShared eliminates the need for the separate
WireProtectionFlags type.
2022-10-03 19:35:34 -07:00
Lang Hames ffe2dda29f [ORC][JITLink] Retain Weak flags in JITDylib interfaces, propagate to LinkGraph.
Previously we stripped Weak flags from JITDylib symbol table entries once they
were resolved (there was no particularly good reason for this). Now we want to
retain them and query them when setting the Linkage on external symbols in
LinkGraphs during symbol resolution (this was the motivation for 75404e9ef8).
Making weak linkage of external definitions discoverable in the LinkGraph will
in turn allow future plugins to implement correct handling for them (by
recording locations that depend on exported weak definitions and pointing all
of these at one chosen definition at runtime).
2022-09-27 10:04:59 -07:00
Kazu Hirata 06b1e5fdc3 [llvm] Use std::underlying_type_t (NFC) 2022-09-25 23:14:15 -07:00
Keith Smiley f331ccca26
[ORC] Fix macho section name typo
I don't think __obj_selrefs is a thing, but __objc_selrefs definitely
is.

Differential Revision: https://reviews.llvm.org/D130221
2022-09-19 09:49:46 -07:00
Lang Hames 47e9e58808 [ORC][ORC-RT][MachO] Reset __data and __common sections on library close.
If we want to be able to close and then re-open a library then we need to reset
the data section states when the library is closed. This commit updates
MachOPlatform and the ORC runtime to track __data and __common sections, and
reset the state in MachOPlatformRuntimeState::dlcloseDeinitialize.

This is only a first step to full support -- there are other data sections that
we're not capturing, and we'll probably want a more efficient representation
for the sections (rather than passing their string name over IPC), but this is
a reasonable first step.

This commit also contains a fix to MapperJITLinkMemoryManager that prevents it
from calling OnDeallocated twice in the case of an error.
2022-09-16 13:40:19 -07:00
Kazu Hirata 9606608474 [llvm] Use x.empty() instead of llvm::empty(x) (NFC)
I'm planning to deprecate and eventually remove llvm::empty.

I thought about replacing llvm::empty(x) with std::empty(x), but it
turns out that all uses can be converted to x.empty().  That is, no
use requires the ability of std::empty to accept C arrays and
std::initializer_list.

Differential Revision: https://reviews.llvm.org/D133677
2022-09-12 13:34:35 -07:00
sunho e57ded44d4 [ORC] Remove moves. 2022-09-10 15:46:11 +09:00
sunho d1c4d96126 [ORC][ORC_RT][COFF] Remove public bootstrap method.
Removes public bootstrap method that is not really necessary and not consistent with other platform API.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D132780
2022-09-10 15:25:50 +09:00
sunho 73c4033987 [ORC][ORC_RT][COFF] Support dynamic VC runtime.
Supports dynamic VC runtime. It implements atexits handling which is required to load msvcrt.lib successfully. (the object file containing atexit symbol somehow resolves to static vc runtim symbols) It also default to dynamic vc runtime which tends to be more robust.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D132525
2022-09-10 15:25:49 +09:00
sunho bc24e6ab7c [JITLink][COFF] Use DLLImportDefinitionGenerator for creating PLT stubs.
Uses DLLImportDefinitionGenerator for creating PLT stubs. It removes previous approach for dllimport stub creation which can't deal with jump thunks.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D132524
2022-09-10 15:25:44 +09:00
Kazu Hirata 89f1433225 Use llvm::lower_bound (NFC) 2022-09-03 11:17:37 -07:00
Lang Hames 349e5bd24e [ORC] Update mapper deinitialize functions to deinitialize in reverse order.
This updates the ExecutorSharedMemoryMapperService::deinitialize and
InProcessMemoryMapper::deinitialize methods to deinitialize in reverse order,
bringing them into alignment with the behavior of
InProcessMemoryManager::deallocate and SimpleExecutorMemoryManager::deallocate.
Reverse deinitialization is required because later allocations can depend on
earlier ones.

This fixes failures in the ORC runtime test suite.
2022-08-30 13:17:44 -07:00
Kazu Hirata 0e9d37ff95 [llvm] Qualify auto in range-based for loops (NFC) 2022-08-28 23:29:00 -07:00
Anubhab Ghosh ab492f6282 [Orc] Take offset inside slab into account in SharedMemoryMapper
SharedMemoryMapper assumed each reservation will have its corresponding
allocations starting from the beginning. However with the introduction
of the slab allocator, there can be a possible offset from the start
from where the initialization is being performed.

This commit also simplifies the logic for finding the parent reservation
and makes the assert messages consistent.
2022-08-27 07:49:48 +05:30
Anubhab Ghosh e309f5ebc0 [Orc] Improve deintialize and shutdown logic
When deinitializing, the allocation needs to be removed from the
allocation list of its associated reservation so that remaining
allocations can be deinitialized when releasing the reservation.

Differential Revision: https://reviews.llvm.org/D132313
2022-08-21 16:36:37 +05:30
Anubhab Ghosh 0ecfee0b9e [Orc] Provide correct Reservation address for slab allocations
When slab allocator is used, the MappingBase is not necessarily
the same as the original reservation base as the allocation could
be a part of the whole reservation.

In this case the original reservation address needs to be passed to
ExecutorSharedMemoryMapperService to associate the new allocation
with the original reservation.

Differential Revision: https://reviews.llvm.org/D132313
2022-08-21 16:36:37 +05:30
Anubhab Ghosh 1134d3a03f [Orc] Only unmap shared memory in controller process destructor
By the time SharedMemoryMapper destructor is called, the RPC
connection is no longer available causing the release() call to
always fail. Instead at this point only shared memory regions
can be unmapped safely.

Deinitializers are called and mapped memory is released at the
executor side by ExecutorSharedMemoryMapperService::shutdown()
instead. Memory can also be released earlier by calling release()
earlier before RPC connection is closed.

Differential Revision: https://reviews.llvm.org/D132313
2022-08-21 16:36:37 +05:30
Anubhab Ghosh 5df428eac3 [Orc] Actually save the callback
The callback function was captured by reference but it lived on the
stack and was in danger of being overwritten and could cause a crash.

Differential Revision: https://reviews.llvm.org/D132313
2022-08-21 16:36:37 +05:30
Lang Hames 2bf87a4946 [ORC][MachO] Fix MachOPlatform after 9189a26664.
Commit 9189a26664 caused llvm-jitlink to create bare JITDylibs to wrap real
dylibs loaded via -preload. This exposed a bug in MachOPlatform where we
assumed that all JITDylibs had been registered with the platform through
MachOPlatform::setupJITDylib (bare JITDylibs are _not_ run through this
function), and errored out where this was not the case.
This bug in MachOPlatform was causing test failures in compilert-rt:

Failed Tests (2):
  ORC-x86_64-darwin :: TestCases/Darwin/x86-64/trivial-objc-methods.S
  ORC-x86_64-darwin :: TestCases/Darwin/x86-64/trivial-swift-types-section.S

This commit fixes the issue by skipping JITDylibs that haven't been registered
with the platform via MachOPlatform::setupJITDylib.
2022-08-17 18:18:48 -07:00
Kazu Hirata 71d12bc2de [ExecutionEngine] Fix warnings
This patch fixes:

  llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp:512:12: error:
  moving a temporary object prevents copy elision
  [-Werror,-Wpessimizing-move]

and:

  llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp:515:12: error:
  moving a temporary object prevents copy elision
  [-Werror,-Wpessimizing-move]
2022-08-15 10:26:03 -07:00
Sunho Kim 0c69f9f32c [ORC][COFF] Introduce DLLImportDefinitionGenerator.
This class will be used to properly solve the `__imp_` symbol and jump-thunk generation issues. It is assumed to be the last definition generator to be called, and as it's the last generator the only symbols remaining in the lookup set are the symbols that are supposed to be queried outside this jitdylib. Instead of just letting them through, we issue another lookup invocation and fetch the allocated addresses, and then create jitlink graph containing `__imp_` GOT symbols and jump-thunks targetting the fetched addresses.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D131833
2022-08-16 02:06:57 +09:00
Anubhab Ghosh 23d0e71fcb [Orc] Use IntervalMap to store free memory regions in MapperJITLinkMemoryManager
MapperJITLinkMemoryManager uses a free list to keep track of available
memory regions. Using an IntervalMap instead of vector allow automatic
coalescing of memory regions as they are freed.

Differential Revision: https://reviews.llvm.org/D131831
2022-08-14 14:35:08 +05:30
Kazu Hirata 109df7f9a4 [llvm] Qualify auto in range-based for loops (NFC)
Identified with readability-qualified-auto.
2022-08-13 12:55:42 -07:00
Anubhab Ghosh a31af32183 Reapply [Orc] Properly deallocate mapped memory in MapperJITLinkMemoryManager
When memory is deallocated from MapperJITLinkMemoryManager deinitialize
actions are run through mapper and in case of InProcessMapper, memory
protections of the region are reset to read/write as they were previously
changed and can be reused in future.

Differential Revision: https://reviews.llvm.org/D131768
2022-08-13 13:07:50 +05:30
Sunho Kim 50f305017d [ORC] Silence copy elision warning. 2022-08-13 14:17:43 +09:00
Sunho Kim 7332b18fa7 [ORC] Specify the typename. 2022-08-13 13:58:50 +09:00
Anubhab Ghosh 8180105143 Revert "[Orc] Properly deallocate mapped memory in MapperJITLinkMemoryManager"
This reverts commit 143555b2ed.
2022-08-13 10:22:31 +05:30