Commit Graph

3347 Commits

Author SHA1 Message Date
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
Kazu Hirata e80118eed6 [JITLink] Use std::optional in MachOLinkGraphBuilder.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:15:18 -08:00
luxufan f8979512ea [JITLink][RISCV] Add R_RISCV_LO12_S relocation support
Fixes: https://github.com/llvm/llvm-project/issues/58979

Reviewed By: Hahnfeld

Differential Revision: https://reviews.llvm.org/D138030
2022-11-16 19:50:18 +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
Moritz Sichert a667aa4de0 [RuntimeDyld] Added support for relocation of indirect functions
In ELF, symbols of type STT_GNU_IFUNC need to be resolved by calling the
function at the symbol's address. This is implemented by adding special
stubs for all symbols of that type.

Differential Revision: https://reviews.llvm.org/D105465
2022-11-02 10:46:11 +01:00
Stefan Gränitz f97d3ba269 [JITLink] Revert template typename change after 2a3b257a93 (NFC)
As pointed out in the review https://reviews.llvm.org/D135523#C3696894NL515
2022-11-01 10:20:29 +01:00
Lang Hames 5af9e648ae [JITLink][AArch46] Update aarch64 pointer jump stub sequence, add utilities.
Updates the aarch64 pointer jump stub sequence to:

ADRP x16, <ptr>@page21
LDR  x16, [x16, <ptr>@pageoff12]
BR   x16

from:

LDR  x16, <ptr>@ldrimm19
BR   x16

The old sequence can only reference pointers within +/-1Mb, which may not be
enough for large object files. The new sequence can reach pointers within
+/-4Gb. (A future pre-fixup-pass could apply range-based optimizations to
turn this into an ldr-br-nop sequence.)

Also adds createPointerJumpStubBlock and createAnonymousPointerJumpStub
utilities along the same lines as their x86-64 counterparts.

The PLTTableManager is updated to use the new utility functions.
2022-10-31 08:41:20 -07:00
Lang Hames cb33ef7ca7 [JITLink][AArch64] Update edge names to be more descriptive, add comments.
This brings the aarch64 edges into alignment with the naming scheme for the
x86-64 edges.

Edge behavior is mostly unchanged, but some irrelevant assertions and errors
have been removed.
2022-10-30 19:03:22 -07:00
Kshitij Jain 2a3b257a93 [JITLink][i386] Adds absolute and pc relative relocation support for ELF/i386.
This commit adds support for 32 bit absolute and pc relative relocations in
ELF/i386 objects, along with simple regression tests.

Reviewed By: sgraenitz, lhames

Differential Revision: https://reviews.llvm.org/D135523
2022-10-30 17:35:41 -07:00
Lang Hames 1f16107219 [JITLink][aarch64] Remove the unused PairedAddend aarch64 edge kind.
This is a vestige of the original MachO-specific edge set and was never used
as a generic aarch64 edge kind.
2022-10-30 16:07:27 -07:00
Lang Hames b4db2da420 [JITLink][AArch64] Remove unused Pointer64Anon edge kind.
Pointer64Anon was lifted out of the MachO backend and into aarch64.h when that
header was created, but Pointer64Anon is really a MachO-specific "normalized"
relocation value, rather than a generic Edge::Kind. Any uses can be safely
replaced with Pointer64.

(Side note: the role of MachOPointer64Anon is to aid MachO relocation parsing:
For MachOPointer64, the target symbol is specified by the r_symbolnum field in
the relocation. For MachOPointer64Anon the address of the anonymous target is
read from the fixup location.)
2022-10-30 11:21:08 -07: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
Jonas Hahnfeld c4dd260f92 [JITLink][RISCV] Add names for GOT/PLT relocations
It is confusing to see "Unrecognized edge kind" in debugging output
for supported relocations; this was probably an oversight in commit
89f546f6ba which added the support.

Differential Revision: https://reviews.llvm.org/D136985
2022-10-29 12:04:16 +02: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 b5d5813762 [JITLink][AArch64] Add a generic 'createAnonymousPointer' utility.
Adds a generic utility for creating anonymous aarch64 pointer blocks
(automatically adding an edge to initialize the pointer if given an
initial target).

Updates the aarch64 GOTTableManager to use the utility when building
GOT entries.
2022-10-25 11:46:06 -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
Pavel Chupin 27ef42bec8 Fix warnings in build done by clang-based compiler
Differential Revision: https://reviews.llvm.org/D135230
2022-10-07 14:12: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 565f4eb8e6 [JITLink] Update external symbol scopes to reflect scopes of resolved defs.
This is a counterpart to ffe2dda29f, and does for scope what that commit did
for linkage.

Making the scope of external definitions visible to JITLink plugins will
allow us to distinguish hidden weak defs (which do not need to be tracked by
default) from default-scoped weak defs (which need to be updated to point at
a single chosen definition at runtime).
2022-09-29 20:32:46 -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
Lang Hames 4ba1f04465 [JITLink] Remove overly-restrictive visibility check introduced in 75404e9ef8.
ELF undefined symbols can have non-default visibility.
2022-09-26 11:19:40 -07:00
Kazu Hirata 06b1e5fdc3 [llvm] Use std::underlying_type_t (NFC) 2022-09-25 23:14:15 -07:00
Lang Hames 75404e9ef8 [JITLink] Introduce new weakly-referenced concept separate from linkage.
Introduces two new methods on Symbol: isWeaklyReferenced and
setWeaklyReferenced. These are now used to track/set whether an external symbol
is weakly referenced, rather than having the Symbol's linkage set to weak.

This change is a first step towards proper handling of weak defs used across
JITDylib boundaries: It frees up the Linkage field on external symbols so that
it can be used to represent the linkage of the definition that the symbol resolves
to. It is expected that Platform plugins will use this information to track
locations that need to be updated if the selected weak definition changes (e.g.
because JITDylibs were dlclosed and then dlopened again in a different order).
2022-09-25 20:34:45 -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 06c4634483 [JITLink] Sink ELFX86RelocationKind into implementation file (ELF_x86_64.cpp).
The ELF/x86-64 backend uses the generic x86_64 edges now, so the
ELFX86RelocationKind is just an implementation detail.
2022-09-01 13:36:49 -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