818 Commits

Author SHA1 Message Date
Lang Hames
df78e6b872 [JITLink] Don't return errors from pointer and jump stub creators.
Creation of pointers and jump stubs always succeeds for all existing JITLink
backends, and I haven't been able to think of a scenario where it would fail.
(Pointer / stub *fixup* may fail due to range errors, but that will happen
later and the APIs already account for it).
2024-11-02 11:36:53 +11:00
Tom Stellard
beb7fb9d0f
[ORC] skip reoptimization tests on i386 (#114351)
This test currently segfaults on i386-unknown-linux-gnu builds.
2024-10-31 17:41:02 -07:00
Jonas Hahnfeld
c4e135ec04
[ORC] Fix transfer to unknown ResourceTrackers (#114063)
When transferring resources, the destination tracker key may not be in
the internal map, invalidating iterators and value references. The added
test creates such situation and would fail before with "Finalized
allocation was not deallocated."

For good measure, fix the same pattern in RTDyldObjectLinkingLayer
which is harder to test because it "only" results in memory managers
being deleted in the wrong order.
2024-10-30 13:56:27 +01:00
Lang Hames
6128ff6630 [JITLink][MachO] Add convenience functions for default text/data sections.
The getMachODefaultTextSection and getMachODefaultRWDataSection functions
return the "__TEXT,__text" and "__DATA,__data" sections respectively, creating
empty sections if the default sections are not already present in the graph.
These functions can be used by utilities that want to add code or data to these
standard sections (e.g. these functions can be used to supply the section
argument to the createAnonymousPointerJumpStub and
createPointerJumpStubBlock functions in the various targets).
2024-10-28 18:05:40 -07:00
Lang Hames
db21bd4fa9 [ORC] Move EPC load-dylib and lookup operations into their own class.
This keeps common operations together, and should make it easier to write
re-usable dylib managers in the future (e.g. a DylibManager that uses
the EPC's remote-execution APIs to implement load and lookup).
2024-10-23 02:59:14 +11:00
Tom Stellard
9b7be3ebe5
[ORC] skip reoptimization tests on s390x. (#112796)
The test was failing on s390x with this error:

JIT session error: Unsupported target machine architecture in ELF object
<main>-jitted-objectbuffer
2024-10-21 14:42:56 -07:00
Sunho Kim
39aae57574 [ORC] skip reoptimization tests on PPC.
Fix https://lab.llvm.org/buildbot/#/builders/64/builds/1202.
2024-10-14 21:35:40 +09:00
Sunho Kim
e5f7e73d90 [ORC] Skip reoptimization test on COFF-ARM64.
Try to skip tests to prevent build bot failure:
https://lab.llvm.org/buildbot/#/builders/161/builds/2692
2024-10-14 02:57:02 +09:00
Sunho Kim
7fea5c034c [ORC] Try to skip unsupported targets in another reoptimization test.
Skipping another reoptimization test when target is not found.
2024-10-12 01:59:26 +09:00
Sunho Kim
222d8fadb4 [ORC] Try to skip unsupported targets in reoptimization test.
Many build bots are getting failures because of this:
https://lab.llvm.org/buildbot/#/builders/140/builds/8600
https://lab.llvm.org/buildbot/#/builders/137/builds/6824
https://lab.llvm.org/buildbot/#/builders/140/builds/8600
2024-10-12 01:49:06 +09:00
Sunho Kim
188ede28e0 [ORC] Implement basic reoptimization. 2024-10-12 01:21:05 +09:00
Sunho Kim
2c01b27858 [ORC] Introduce RedirectionManager interface and implementation using JITLink. 2024-10-12 01:21:05 +09:00
Lang Hames
255870d7b5 [JITLink] Update splitBlock to support splitting into multiple blocks.
LinkGraph::splitBlock used to take a single split-point to split a Block into
two. In the common case where a block needs to be split repeatedly (e.g. in
eh-frame and compact-unwind sections), iterative calls to splitBlock could
lead to poor performance as symbols and edges are repeatedly shuffled to new
blocks.

This commit updates LinkGraph::splitBlock to take a sequence of split offsets,
allowing a block to be split into an arbitrary number of new blocks. Internally,
Symbols and Edges only need to be moved once (directly to whichever new block
they will be associated with), leading to better performance.

On some large MachO object files in an out of tree project this change improved
the performance of splitBlock by several orders of magnitude.

rdar://135820493
2024-09-22 09:52:08 +10:00
Daniil Fukalov
89e6a28867
[NFC] Add explicit #include llvm-config.h where its macros are used. (#106621)
Without these explicit includes, removing other headers, who implicitly
include llvm-config.h, may have non-trivial side effects.
2024-08-30 09:35:06 +02:00
Steven Wu
01b488faab
Reapply "[CMake] Fold export_executable_symbols_* into function args. (#101741)" (#102138)
Fix the builds with LLVM_TOOL_LLVM_DRIVER_BUILD enabled.

LLVM_ENABLE_EXPORTED_SYMBOLS_IN_EXECUTABLES is not completely
compatible with export_executable_symbols as the later will be ignored
if the previous is set to NO.

Fix the issue by passing if symbols need to be exported to
llvm_add_exectuable so the link flag can be determined directly
without calling export_executable_symbols_* later.
2024-08-07 09:12:15 -07:00
Steven Wu
f9b69a378c Revert "[CMake] Fold export_executable_symbols_* into function args. (#101741)"
This reverts commit 5c56b46a32a8856a022a54291bc9294068f7ddbd. This break
lld build when using GENERATE_DRIVER.
2024-08-06 06:08:16 -07:00
Steven Wu
5c56b46a32
[CMake] Fold export_executable_symbols_* into function args. (#101741)
`LLVM_ENABLE_EXPORTED_SYMBOLS_IN_EXECUTABLES` is not completely
compatible with `export_executable_symbols` as the later will be ignored
if the previous is set to NO.

 Fix the issue by passing if symbols need to be exported to
`llvm_add_exectuable` so the link flag can be determined directly
without calling `export_executable_symbols_*` later.
2024-08-05 19:08:27 -07:00
Lang Hames
b15aa7f88c [ORC] Add unit test for MemoryFlags APIs, don't dereference end() iterator.
In AllocGroupSmallMap::find(AllocGroup) we were calling lower_bound(...) and
then unconditionally dereferencing the resulting iterator, however
lower_bound(...) may return end() if the value being searched for is higher
than any value present in the map. This patch adds a check for end() before
the dereference to guard against dereference of end().

This commit also adds some basic unit tests for MemProt and AllocGroupSmallMap.

rdar://129662981
2024-07-22 17:16:32 +10:00
Lang Hames
4a7b800301 [ORC] Switch ExecutionSession::ErrorReporter to use unique_function.
This allows the ReportError functor to hold move-only types.
2024-06-07 16:55:22 +10:00
Michael Kruse
4ecbfacf9e
[llvm] Revise IDE folder structure (#89741)
Update the folder titles for targets in the monorepository that have not
seen taken care of for some time. These are the folders that targets are
organized in Visual Studio and XCode
(`set_property(TARGET <target> PROPERTY FOLDER "<title>")`)
when using the respective CMake's IDE generator.

 * Ensure that every target is in a folder
 * Use a folder hierarchy with each LLVM subproject as a top-level folder
 * Use consistent folder names between subprojects
 * When using target-creating functions from AddLLVM.cmake, automatically
deduce the folder. This reduces the number of
`set_property`/`set_target_property`, but are still necessary when
`add_custom_target`, `add_executable`, `add_library`, etc. are used. A
LLVM_SUBPROJECT_TITLE definition is used for that in each subproject's
root CMakeLists.txt.
2024-05-25 13:28:30 +02:00
Min Hsu
a3457369cd [Orc] Fix -Wsign-compare warnings in unittest
Multiple compares against `LookupsCompleted`, which is effectively an
unsigned long, with constant signed integer were throwing -Wsign-compare
warnings.

This is effectively NFC.
2024-05-09 14:40:19 -07:00
Lang Hames
c73516af10 [ORC] Add tests for error handling paths in suspended generators.
Test that (1) errors returned from a manually suspended generator are
propagated as expected, and (2) automatic suspension does not interfere with
our ability to resume (and return errors from) a generator.
2024-05-09 23:24:45 +10:00
Lang Hames
c32a4f83b5 [ORC] Allow removal of ObjectLinkingLayer Plugins.
This adds a removePlugin operation to ObjectLinkingLayer. The removal of a
plugin will be visible in all links started after the removal (ongoing links
started before the removal will still use the removed plugin).

Coding my way home: 17.56037S, 149.61118W
2024-05-01 22:40:59 -09:30
Nikita Popov
47682e4b4a Revert "[ORC] Implement basic reoptimization. (#67050)"
This reverts commit 0d288e5b0ccf217e41944ad4fd8772d8ae45daa1.

Breaks the build.
2024-04-26 14:47:48 +09:00
Sunho Kim
0d288e5b0c
[ORC] Implement basic reoptimization. (#67050) 2024-04-25 22:43:06 -07:00
Lang Hames
7da63426ac Re-apply "[ORC] Unify task dispatch across ExecutionSession..." with more fixes.
This re-applies 6094b3b7db7, which was reverted in e7efd37c229 (and before that
in 1effa19de24) due to bot failures.

The test failures were fixed by having SelfExecutorProcessControl use an
InPlaceTaskDispatcher by default, rather than a DynamicThreadPoolTaskDispatcher.
This shouldn't be necessary (and indicates a concurrency issue elsewhere), but
InPlaceTaskDispatcher is a less surprising default, and better matches the
existing behavior (compilation on current thread by default), so the change
seems reasonable. I've filed https://github.com/llvm/llvm-project/issues/89870
to investigate the concurrency issue as a follow-up.

Coding my way home: 6.25133S 127.94177W
2024-04-23 23:11:37 -08:00
Lang Hames
e7efd37c22 Revert "Re-apply [ORC] Unify task dispatch across ExecutionSession and..."
This reverts commit 1effa19de24 while I investigate the test failure at
https://lab.llvm.org/buildbot/#/builders/285/builds/888.
2024-04-22 16:53:34 -08:00
Lang Hames
1effa19de2 Re-apply "[ORC] Unify task dispatch across ExecutionSession and..." with fix.
This re-applies 6094b3b7db7, which was reverted in a28557aadd8 due to broken
bots. As far as I can tell all failures were due to a missing #include <deque>,
which has been adedd in this commit.
2024-04-22 16:28:17 -08:00
Mehdi Amini
a28557aadd Revert "[ORC] Unify task dispatch across ExecutionSession and ExecutorProcessControl."
This reverts commit 6094b3b7db7eab8318b9d30dec2691d231c7bdff.

Multiple bots are broken.
2024-04-22 16:31:45 -07:00
Lang Hames
6094b3b7db [ORC] Unify task dispatch across ExecutionSession and ExecutorProcessControl.
Updates ExecutionSession to use the ExecutorProcessControl object's
TaskDispatcher rather than having a separate dispatch function. This gives the
TaskDispatcher a global view of all tasks to be executed, and provides a
single point to wait on for tasks to complete when shutting down the JIT.
2024-04-22 15:17:34 -08: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
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
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
Stefan Gränitz
8e09f13d67 [OrcJITTests] Fix warning: suggest explicit braces to avoid ambiguous 'else' (NFC)
Likely related to platform-specific expansion of gtest macros:
```
llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp:1276:12: warning: suggest explicit
braces to avoid ambiguous 'else' [-Wdangling-else]
```
2024-01-23 11:49:41 +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
Ben Langmuir
08c5f1fede
[ORC] Add absoluteSymbolsLinkGraph to expose absolute symbols to platform (#77008)
Adds a function to create a LinkGraph of absolute symbols, and a
callback in dynamic library search generators to enable using it to
expose its symbols to the platform/orc runtime. This allows e.g. using
__orc_rt_run_program to run a precompiled function that was found via
dlsym. Ideally we would use this in llvm-jitlink's own search generator,
but it will require more work to align with the Process/Platform
JITDylib split, so not handled here.

As part of this change we need to handle LinkGraphs that only have
absolute symbols.
2024-01-05 15:32:29 -08:00
Stefan Gränitz
40236257ea
[Orc] Deduplicate GDB JIT Interface declarations (NFC) (#76373)
https://github.com/llvm/llvm-project/pull/76236 introduced the forth
copy and it was time to deduplicate. This patch brings it back to 2,
one in OrcTargetProcess and one in legacy ExecutionEngine.
2024-01-03 11:21:22 +01:00
Kazu Hirata
5c9d82de6b [llvm] Use StringRef::{starts,ends}_with (NFC)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-13 22:46:02 -08:00
Stefan Gränitz
e00ade1144 [llvm-c] Mitigate debug support test for systems that still default to RuntimeDyld
Fix test failure reported from buildbot clang-s390x-linux-lnt after #73257
OrcCAPITest.cpp:562: Debugger support requires JITLink
2023-12-12 10:26:54 +01:00
Stefan Gränitz
54397f9ac1
[llvm-c] Expose debug support for LLJIT in Orc C-API bindings (#73257)
Allow C-API users to debug their JITed code via the GDB JIT Interface.

This is currently supported on ELF and MachO based platforms. On
other systems `LLVMOrcLLJITEnableDebugSupport()` returns an error.

This patch adds a new C-API header `LLJITUtils.h`, which can host
further advanced JIT features in the future. Using the header requires
linking against LLVMOrcDebugging.
2023-12-11 20:47:20 +01:00
Stefan Gränitz
f32509b2ca
[JITLink][AArch32] Test out-of-range and interworking errors for Thumb (#73397) 2023-11-29 21:24:39 +01:00
Stefan Gränitz
2bdf6231da [JITLink][AArch32] Split out error test for invalid edge in applyFixup()
Also rename the fixture class since these tests are not ELF-specific.
2023-11-28 17:37:17 +01:00
Lang Hames
56c72c7f33 [ORC] Add a public unsafe-operations helper for SymbolStringPtr.
SymbolStringPoolEntryUnsafe provides unsafe access to SymbolStringPtr objects,
allowing clients to manually retain and release pool entries, or consume or
create SymbolStringPtr instances without affecting an entry's ref-count. This
can be useful when writing C APIs that need to handle SymbolStringPtrs.

As part of this patch the LLVM-C API implementation is updated to use the new
utility, rather than the old, private OrcV2CAPIHelper utility.
2023-11-27 09:48:56 -08:00
Stefan Gränitz
fa23d2b9d9 [JITLink][AArch32] Add test fixture with helper functions in error tests 2023-11-25 17:13:16 +01:00
Stefan Gränitz
0fea00d48b [JITLink][AArch32] Split invalid edge kind test out into readAddendDataErrors
This test actually exercises the readAddendData() function.
2023-11-25 14:08:17 +01:00
Stefan Gränitz
9020026b88 [JITLink][AArch32] Fix GetEdgeKindName function in error tests
The `getGenericEdgeKindName()` function returned "<Unrecognized edge kind>" for all our relocations.
We must use `aarch32::getEdgeKindName()` instead.
2023-11-25 13:24:25 +01:00
Stefan Gränitz
e970652776 [JITLink][AArch32] Reflow code structure after llvm::endianness refactor (NFC) 2023-11-25 12:37:29 +01:00
Stefan Gränitz
b86420c614
[JITLink][AArch32] Add dynamic lookup for relocation fixup infos (#71649)
Specifying relocation fixup constants with name and type facilitates
readability and compile-time checks. The `FixupInfo<EdgeKind>` facade
organizes the information into entries per relocation type and provides
uniform access across Arm and Thumb relocations. Since it uses template
specializations, it doesn't limit potential entries. We cannot access
the entries dynamically though, because `EdgeKind` must be given as a
compile-time constant.

With this patch we populate a static lookup table on-demand and use it
for dynamic access in opcode-checks.
2023-11-24 21:45:50 +01:00
Stefan Gränitz
808caa9d46
[JITLink][AArch32] Run all error unittests throug main entrypoints (#72091)
Reading implicit addend from a relocation site doesn't require a complete
`LinkGraph` edge. The operation is independent from `TargetSymbol`,
but constructing an `Edge` instance required one. This patch fixes the
inconsistency and simplifies some setup code from the error unittests.

Furthermore this patch prepares for the `Arm`/`Thumb`/`Data` helper
functions to be turned into implementation details. Exposing them in the
API causes unfortunate inconsistencies that we don't want to error-check
all the time, e.g. passing `Thumb_Call` to `readAddendArm()`.
2023-11-15 11:18:23 +01:00