Commit Graph

3688 Commits

Author SHA1 Message Date
Ben Langmuir
aacb8985f7 [orc] Reduce memory usage from empty materialization info DenseMaps (#88167)
Saves several MB of memory in larger applications after linking finishes
by clearing DenseMap storage that is empty. This does not attempt to
shrink partially full materialization infos. The assumption is that
adding more after linking finishes is rare.

rdar://126145336
2024-04-09 13:01:00 -07:00
Lang Hames
925b7d6f62 [ORC] Replace some KV loop variables with structured bindings.
Same idea as 006aaf3225 -- reduce boilerplate and improve readability. This
time updates will be piecemeal to make it easier to identify errors.

Coding my way home: 2.18555S, 93.78063W
2024-04-08 18:50:52 -06:00
Lang Hames
fdd023612c Revert "[ORC] Replace some KV loop variables with structured bindings."
This reverts commit 006aaf3225 while I
investigate some bot failures (See e.g.
https://lab.llvm.org/buildbot/#/builders/109/builds/86659).
2024-04-08 00:02:01 -06:00
Lang Hames
006aaf3225 [ORC] Replace some KV loop variables with structured bindings.
This allows us to remove a lot of boilerplate .first and .second references
and improve readability.

Coding my way home: 1.58814S, 91.93889W
2024-04-07 23:30:46 -06:00
Lang Hames
649523f6f7 [ORC] Add an ExecutionSession state verifier.
Add an ExecutionSession state verifier, enabled under EXPENSIVE_CHECKS, that can
be used to identify inconsistent session state to assist in tracking down bugs.

This initial version was motivated by investigation of the EDU-update bug that
was fixed in a671ceec33.

rdar://125376708
2024-04-07 15:36:45 -06:00
Lang Hames
a671ceec33 [ORC] Fix an EDU-update bug in ExecutionSession::IL_failSymbols.
We were catching a local variable, SymMI, by value instead of by reference
during EDU cleanup and this was leaving the dependence graph in an
inconsistent state that could lead to crashes on subsequent emits. Fixing this
bug required us to also avoid aliasing between SymMI and MI (which would have
caused cleanup to clear the MI.DependantEDUs set that we're iterating over).

No testcase: the crash only triggered in very specific circumstances
(including concurrent linking) in an out-of-tree ORC client. I'm working on a
session state verifier that could be turned on when compiling with
expensive-checks turned on and that should help us catch issues like this in
the future.

rdar://125164262

Coding my way home: 0.89527S, 89.61313W
2024-04-05 11:14:06 -05:00
Fangrui Song
2763353891 [Object,ELFType] Rename TargetEndianness to Endianness (#86604)
`TargetEndianness` is long and unwieldy. "Target" in the name is confusing. Rename it to "Endianness".

I cannot find noticeable out-of-tree users of `TargetEndianness`, but
keep `TargetEndianness` to make this patch safer. `TargetEndianness`
will be removed by a subsequent change.
2024-03-28 09:10:34 -07:00
Lang Hames
c4d5881550 [JITLink][MachO] Handle MachO section start/end symbols.
Transform section$start$<section-name> and section$end$<section-name> external
symbols into defined symbols when a section named <section-name> is present.

rdar://125357048

Coding my way home: 8.98112N, 79.52094W
2024-03-25 11:40:52 -05:00
Lang Hames
94bbc18bb6 [ORC] Add some debug logging to EPCDynamicLibrarySearchGenerator.
Coding my way home: 8.98112N, 79.52094W
2024-03-25 11:40:52 -05:00
Lang Hames
c15218bccb [JITLink] Dump weak-ref status for external symbols in LinkGraphs.
Coding my way home: 8.98112N, 79.52094W
2024-03-25 11:40:51 -05:00
Lang Hames
8ef451072a [JITLink][ELF][AArch64] Make include order consistent with other JITLink files.
Coding my way home: 8.98112N, 79.52094W
2024-03-25 11:40:51 -05:00
Lang Hames
488a18738f [JITLink][ELF] Improve ELF section start/end symbol handling.
This commit adds section start and stop symbol handling to ELF/aarch64, and
fixes the section symbol prefixes (using `__start_` and `__stop_`, rather than
`__start` and `__end`). It also adds a testcase for handling of these symbols.
2024-03-24 14:54:15 -05:00
Keith Smiley
2f6b1b4b30 [ORC] Add default visibility to required JIT functions (#86322)
If you build LLVM with `-DCMAKE_CXX_VISIBILITY_PRESET=hidden` to help
reduce binary size, these symbols end up becoming local, and getting
stripped. This forces default visibility to override the global setting
in that case.

Relevant:
https://github.com/llvm/llvm-project/issues/62815#issuecomment-1560078260
2024-03-22 21:10:21 -04:00
Lang Hames
e40bc8e509 [ORC][MachO] Make BuildVersionOpts::fromTriple result optional, add test.
Only platform specific darwin OS values (e.g. macosx, ios, watchos, ...) can be
mapped to an LC_BUILD_VERSION platform. For all other values return an empty
optional to indicate that the load command can't be constructed.

Also fixes the simulator conditions to return the correct platform, and adds a
testcase.
2024-03-14 15:11:39 -07:00
Lang Hames
2c80a9accb [ORC][MachO] Pluralize member name.
This member switched from an optional to a vector in 0f252e7bd8.
2024-03-14 10:38:49 -07:00
Lang Hames
0f252e7bd8 [ORC][MachO] Allow multiple LC_BUILD_VERSION commands.
No testcase: I'm still thinking about the best way to test this.
2024-03-14 09:45:28 -07:00
Chen Cheng
35f5caea51 [NFC] Corrected data type (#84880)
On windows, "&Method.first" is of type "unsigned long long *", and a
type conversion error occurs.
2024-03-13 10:16:42 -07:00
Nathan Sidwell
66f0984385 Reorder fields for better packing (#77998)
The RelocationEntry's fields are poorly ordered when considering
padding. This reordering reduces the size from 56 bytes to 40 bytes (on
LP64).
2024-03-11 07:35:02 -04:00
Michael Spencer
ba13fa2a5d [llvm][Support] Add and use errnoAsErrorCode (#84423)
LLVM is inconsistent about how it converts `errno` to `std::error_code`.
This can cause problems because values outside of `std::errc` compare
differently if one is system and one is generic on POSIX systems.

This is even more of a problem on Windows where use of the system
category is just wrong, as that is for Windows errors, which have a
completely different mapping than POSIX/generic errors. This patch fixes
one instance of this mistake in `JSONTransport.cpp`.

This patch adds `errnoAsErrorCode()` which makes it so people do not
need to think about this issue in the future. It also cleans up a lot of
usage of `errno` in LLVM and Clang.
2024-03-08 23:30:33 -08:00
Lang Hames
48673825f4 [ORC] Deallocate FinalizedAllocs on error paths in notifyEmitted.
If notifyEmitted encounters a failure (either because some plugin returned one,
or because the ResourceTracker was defunct) then we need to deallocate the
FinalizedAlloc manually.

No testcase yet: This requires a concurrent setup -- we'll need to build some
infrastructure to coordinate links and deliberately injected failures in order
to reliably test this.
2024-03-07 14:41:30 -08:00
Lang Hames
4d31fbbb5a [ORC] Propagate defineMaterializing failure when resource tracker is defunct.
Remove an overly aggressive cantFail: This call to defineMaterializing should
never fail with a duplicate symbols error (since all new symbols shoul be
weak), but may fail if the tracker has become defunct in the mean time. In that
case we need to propagate the error.
2024-03-07 11:30:18 -08:00
Hongyu Chen
00f412168c [ORC][JITLink] Add Intel VTune support to JITLink (#83957)
[ORC] Re-land https://github.com/llvm/llvm-project/pull/81826

This patch adds two plugins: VTuneSupportPlugin.cpp and
JITLoaderVTune.cpp. The testing is done in a manner similar to
llvm-jitlistener. Currently, we only support the old version of Intel
VTune API.
2024-03-07 11:15:16 -08:00
Mehdi Amini
716042a63f Rename llvm::ThreadPool -> llvm::DefaultThreadPool (NFC) (#83702)
The base class llvm::ThreadPoolInterface will be renamed
llvm::ThreadPool in a subsequent commit.

This is a breaking change: clients who use to create a ThreadPool must
now create a DefaultThreadPool instead.
2024-03-05 18:00:46 -08:00
Lang Hames
e77a473601 [ORC][MachO] Simplify use of LC_BUILD_VERSION in JITDylib headers.
API clients can now set a MachO::HeaderOptions::BuildVersionOpts field to have
MachOPlatform add an LC_BUILD_VERSION load command to the Mach header for each
JITDylib.

No testcase yet. In the future we'll try to add a MachO parser to the ORC
runtime and extra test options to llvm-jitlink for this.

This commit also incidentally fixes a bug in the MachOBuilder class that lead to
a delegation cycle.
2024-03-05 14:46:22 -08:00
Jordan Rupprecht
1a67dee089 Revert "[ORC][JITLink] Add Intel VTune support to JITLink (#81826)"
This reverts commit 17efdad229. It introduces a layering violation: https://github.com/llvm/llvm-project/pull/81826#issuecomment-1977455140
2024-03-04 17:50:44 -08:00
Hongyu Chen
17efdad229 [ORC][JITLink] Add Intel VTune support to JITLink (#81826)
This patch adds two plugins: VTuneSupportPlugin.cpp and
JITLoaderVTune.cpp. The testing is done in a manner similar to
llvm-jitlistener. Currently, we only support the old version of Intel
VTune API.

This pull request is stacked on top of
https://github.com/llvm/llvm-project/pull/81825
2024-03-04 08:52:45 -08:00
Hongyu Chen
de92615d68 [ExecutionEngine] Move IntelJITEventsWrapper to its own library. NFC (#81825)
Split IntelJITEventsWrapper away from IntelJITEvents and rename it into
IntelJITProfiling.
NFC
2024-03-04 08:44:36 -08:00
Lang Hames
c625b99652 [ORC] Add SectCreateMaterializationUnit, llvm-jitlink -sectcreate option.
The SectCreateMaterializationUnit creates a LinkGraph with a single named
section containing a single named block whose content is given by a
MemoryBuffer. It is intended to support emulation of ld64's -sectcreate option.
2024-02-20 10:23:54 -08:00
Min-Yih Hsu
3d67cf681a [JITLink] Always unmap standard segments in InProcessMemoryManager::deallocate (#81943)
Right now InProcessMemoryManager only releases a standard segment (via
sys::Memory::releaseMappedMemory) in `deallocate` when there is a
DeallocAction associated, leaving residual memory pages in the process
until termination.
Despite being a de facto memory leak, it won't cause a major issue if
users only create a single LLJIT instance per process, which is the most
common use cases. It will, however, drain virtual memory pages if we
create thousands of ephemeral LLJIT instances in the same process.

This patch fixes this issue by releasing every standard segments
regardless of the attached DeallocAction.
2024-02-16 16:19:56 -08:00
Ben Langmuir
54226e234f [ORC] Make EPCDynamicLibrarySearchGenerator async
Switch the primary implementation of EPC lookupSymbols to be async,
keeping a synchronous wrapper for compatibility. Use the new async
implementation inside EPCDynamicLibrarySearchGenerator to work
working towards a fully async search generator.

Provide an asynchronous lookup API for EPCGenericDylibManager and adopt
that from the SimpleRemoteEPC. This enables an end-to-end async
EPCDynamicLibrarySearchGenerator. Note: currently we keep the current
per-dlhandle lookup model, but a future improvement could do a single
async call for a given lookup operation.
2024-02-12 10:54:49 -08:00
Jonas Hahnfeld
78f39dc70c [JITLink][RISCV] Use hashmap to find PCREL_HI20 edge (#78849)
As noted in issues #68594 and #73935, `JITLink/RISCV/ELF_ehframe.s`
fails with libstdc++'s expensive checks because `getRISCVPCRelHi20`
calls `std::equal_range` on the edges which may not be ordered by their
offset. Instead let `ELFJITLinker_riscv` build a hashmap of all edges
with type `R_RISCV_PCREL_HI20` that can be looked up in constant time.

Closes #73935
2024-02-12 19:45:52 +01:00
Lang Hames
1389260805 [JITLink][MachO][arm64] Fix error-check order.
The error check should be performed after the iterator increment, not before
it. Thanks to @dcb314 for catching this!

Fixes github.com/apple/swift/issues/81119
2024-02-08 16:55:05 -08:00
Craig Topper
8c37e3e64b [RISCV] Only set Zca flag for EF_RISCV_RVC in ELFObjectFileBase::getRISCVFeatures(). (#80928)
This code appears to be a hack to set the features to include compressed
instructions if the ELF EFLAGS flags bit is present, but the ELF
attribute for the ISA string is no present or not accurate.

We can't remove the hack because llvm-mc doesn't create ELF attributes
by default so a lot of tests fail to disassembler properly. Using clang
as the assembler does set the attributes.

This patch changes the hack to only set Zca since that is the minimum
implied by the flag. Setting anything else potentially conflicts with
the ISA string containing Zcmp or Zcmt.

JITLink also needs to be updated to recognize Zca in addition to C.
2024-02-07 08:23:57 -08:00
Fraser Cormack
d4c5acac99 [ExecutionEngine] Fix a couple of typos (NFC) 2024-02-06 15:23:24 +00:00
Kazu Hirata
a37e8b85ee [ExecutionEngine] Simplify a string comparison (NFC) 2024-02-03 21:43:08 -08:00
lhames
ebe8733a11 [ORC] Merge MaterializationResponsibility notifyEmitted and addDependencies
Removes the MaterializationResponsibility::addDependencies and
addDependenciesForAll methods, and transfers dependency registration to
the notifyEmitted operation. The new dependency registration allows
dependencies to be specified for arbitrary subsets of the
MaterializationResponsibility's symbols (rather than just single symbols
or all symbols) via an array of SymbolDependenceGroups (pairs of symbol
sets and corresponding dependencies for that set).

This patch aims to both improve emission performance and simplify
dependence tracking. By eliminating some states (e.g. symbols having
registered dependencies but not yet being resolved or emitted) we make
some errors impossible by construction, and reduce the number of error
cases that we need to check. NonOwningSymbolStringPtrs are used for
dependence tracking under the session lock, which should reduce
ref-counting operations, and intra-emit dependencies are resolved
outside the session lock, which should provide better performance when
JITing concurrently (since some dependence tracking can happen in
parallel).

The Orc C API is updated to account for this change, with the
LLVMOrcMaterializationResponsibilityNotifyEmitted API being modified and
the LLVMOrcMaterializationResponsibilityAddDependencies and
LLVMOrcMaterializationResponsibilityAddDependenciesForAll operations
being removed.
2024-01-31 13:06:09 -08:00
Jordan Rupprecht
96ec447a6a [NFC] Fix various unintentional //namespace formatting 2024-01-24 21:17:45 -08:00
Stefan Gränitz
e4f0829d80 [Orc] Let LLJIT default to JITLink for ELF-based ARM targets (#77313)
The JITLink AArch32 backend reached feature-parity with RuntimeDyld
on ELF-based systems. This patch changes the default JIT-linker in Orc's
LLJIT for these platforms.

This allows us to run clang-repl with JITLink on ARM and use all the
features we had with RuntimeDyld before. All existing tests for
clang-repl are passing.
2024-01-23 18:50:41 +01:00
Stefan Gränitz
55929cd679 [JITLink][AArch32] Implement Armv5 ldr-pc stubs and use them for all pre-v7 targets (#79082)
This stub type loads an absolute address directly into the PC register.
It's the simplest and most compatible way to implement a branch
indirection across the entire address space (and probably the slowest as
well). It's the ideal fallback for all targets for which we did not
(yet) implement a more performant solution.
2024-01-23 18:02:17 +01:00
Stefan Gränitz
9577806b1e [JITLink][AArch32] Implement R_ARM_PREL31 and process .ARM.exidx sections (#79044)
`R_ARM_PREL31` is a 31-bits relative data relocation where the
most-significant bit is preserved. It's used primarily in `.ARM.exidx`
sections, which we skipped processing until now, because we didn't
support the relocation type. This was implemented in RuntimeDyld with
https://reviews.llvm.org/D25069 and I implemented it in a similar way in
JITLink in order to reach feature parity.
2024-01-23 03:37:32 +01:00
Stefan Gränitz
e5ca202ef8 [JITLink][AArch32] Multi-stub support for armv7/thumbv7 (#78371)
We want to emit stubs that match the instruction set state of the
relocation site. This is important for branches that have no built-in
switch for the instruction set state. It's the case for Jump24
relocations. Relocations on instructions that support switching on
the fly will be rewritten in a relaxation step in the future. This
affects Call relocations on `BL`/`BLX` instructions.

In this patch, the StubManager gains a second stub symbol slot for each
target and selects which one to use based on the relocation type. For
testing, we select the appropriate slot with a stub-kind filter, i.e.
`arm` or `thumb`. With that we can implement Armv7 stubs and test
that we can have both kinds of stubs for a single external symbol.
2024-01-23 02:59:30 +01:00
Stefan Gränitz
565470ed27 [JITLink][AArch32] Implement ELF relocation R_ARM_NONE 2024-01-22 16:47:17 +01:00
Stefan Gränitz
bfb09326be [JITLink][AArch32] Implement ELF relocation R_ARM_TARGET1
Prepare a configuration switch and default to R_ARM_ABS32
2024-01-22 16:47:17 +01:00
Stefan Gränitz
c4fc563b8d [JITLink][AArch32] Add GOT builder and implement R_ARM_GOT_PREL relocations for ELF (#78753)
LLJIT needs this relocation for running deinitializers. Implementation and
test are adapted from test arm-fpic-got.s in LLD.
2024-01-22 12:00:24 +01:00
Stefan Gränitz
6a433d77b1 [llvm-jitlink] Allow optional stub-kind filter in stub_addr() expressions (#78369)
We use `jitlink-check` lines in LIT tests as the primary tool for
testing JITLink backends. Parsing and evaluation of the expressions is
implemented in `RuntimeDyldChecker`. The `stub_addr(obj, name)`
expression allows to obtain the linker-generated stub for the external
symbol `name` in object file `obj`.

This patch adds support for a filter parameter to select one out of many
stubs. This is necessary for the AArch32 JITLink backend, which must be
able to emit two different kinds of stubs depending on the instruction
set state (Arm/Thumb) of the relocation site. Since the new parameter is
optional, we don't have to update existing tests.

Filters are regular expressions without brackets that match exactly one
existing stub. Given object file `armv7.o` with two stubs for external
function `ext` of kinds `armv7_abs_le` and `thumbv7_abs_le`, we get the
following filter results e.g.:
```
stub_addr(armv7.o, ext, thumb)        thumbv7_abs_le
stub_addr(armv7.o, ext, thumbv7)      thumbv7_abs_le
stub_addr(armv7.o, ext, armv7_abs_le) armv7_abs_le
stub_addr(armv7.o, ext, v7_.*_le)     Error: "ext" has 2 candidate stubs in file "armv7.o". Please refine stub-kind filter "v7_.*_le" for disambiguation (encountered kinds are "thumbv7_abs_le", "armv7_abs_le").
stub_addr(armv7.o, ext, v8)           Error: "ext" has 2 stubs in file "armv7.o", but none of them matches the stub-kind filter "v8" (all encountered kinds are "thumbv7_abs_le", "armv7_abs_le").
```
2024-01-20 09:57:03 +01:00
Kazu Hirata
b7a66d0fae [llvm] Use SmallString::operator std::string (NFC) 2024-01-19 18:54:11 -08:00
Ben Langmuir
b08aca7a4f [ORC][MachO] Support common load commands in the platform's mach-o header builder
Add a HeaderOptions struct that can be used to configure commonly-used
load commands LC_ID_DYLIB, LC_LOAD_DYLIB, and LC_RPATH when setupDylib
creates a mach-o header.
2024-01-18 09:14:15 -08:00
Stefan Gränitz
9c607e77ea [JITLink][AArch32] Refactor StubsManager (NFC) 2024-01-17 00:36:30 +01:00
Stefan Gränitz
a979797dc2 [JITLink][AArch32] Rename stubs flavor Thumbv7 to v7 (NFC) 2024-01-17 00:36:30 +01:00
David Green
7850c94b86 [NFC] sentinal -> sentinel 2024-01-16 17:22:06 +00:00