841 Commits

Author SHA1 Message Date
Lang Hames
853849a984 [ORC] Remove some unnecessary namespace qualifications. NFCI. 2025-03-13 14:15:01 +11:00
Lang Hames
666540cb65 [ORC] Swap handleAsync handler and send-result arguments.
Placing the handler argument last improves readability when passing a lambda
value (the common case for this API).
2025-03-11 13:17:25 +11:00
Nikita Popov
979c275097
[IR] Store Triple in Module (NFC) (#129868)
The module currently stores the target triple as a string. This means
that any code that wants to actually use the triple first has to
instantiate a Triple, which is somewhat expensive. The change in #121652
caused a moderate compile-time regression due to this. While it would be
easy enough to work around, I think that architecturally, it makes more
sense to store the parsed Triple in the module, so that it can always be
directly queried.

For this change, I've opted not to add any magic conversions between
std::string and Triple for backwards-compatibilty purses, and instead
write out needed Triple()s or str()s explicitly. This is because I think
a decent number of them should be changed to work on Triple as well, to
avoid unnecessary conversions back and forth.

The only interesting part in this patch is that the default triple is
Triple("") instead of Triple() to preserve existing behavior. The former
defaults to using the ELF object format instead of unknown object
format. We should fix that as well.
2025-03-06 10:27:47 +01:00
Tristan Ross
415607e10b
[ORC][unittests] Remove hard coded 16k page size (#127115)
Fixes a couple hard coded 16k values which is being used as the page
size. Replaces the hard coded value with the system's page size. This
fixes #116753 on an Ampere Altra Q64-22

CC @lhames
2025-02-14 09:56:55 +11:00
Lang Hames
4a2a8ed70d [JITLink] Add a jitlink::Symbol::getSection() convenience method.
`Sym.getSection()` is equivalent to `Sym.getBlock().getSection()`.
2025-02-06 14:37:45 +11:00
Mats Jun Larsen
7bb949ec61
[IR][unittests] Replace of PointerType::getUnqual(Type) with opaque version (NFC) (#123901)
Follow up to https://github.com/llvm/llvm-project/issues/123569
2025-01-22 18:02:51 +09:00
Lang Hames
81c0f3023f [ORC] Add ExecutorSymbolDef toPtr / fromPtr convenience functions.
This will simplify conversion of a number of APIs from ExecutorAddr to
ExecutorSymbolDef.
2025-01-22 09:53:42 +11:00
Lang Hames
8fb29ba287 [JITLink] Teach x86_64 GOT & PLT table managers to discover existing entries.
x86_64::GOTTableManager and x86_64::PLTTableManager will now look for existing
GOT and PLT sections and re-use existing entries if they're present.

This will be used for an upcoming MachO patch to enable compact unwind support.

This patch is the x86-64 counterpart 42595bdaefb, which added the same
functionality to the GOT and PLT managers for aarch64.
2025-01-16 19:38:55 +11:00
Lang Hames
29e63328a7 [JITLink] Add Block::edges_at(Edge::OffsetT): iterate over edges at offset.
Block::edges_at is a convenience method for iterating over edges at a given
offset within a jitlink::Block.

This method will be used in an upcoming patch for compact unwind info support.
2025-01-16 13:18:15 +11:00
Lang Hames
9c5001e454 [JITLink] Add convenience methods to LinkGraph to find symbols by name.
Adds new convenience methods findDefinedSymbolByName, findExternalSymbolByName
and findAbsoluteSymbolByName to the LinkGraph class. These should be used to
find symbols of the given types by name.

COFFLinkGraphBuilder and MachOPlatform are updated to take advantage of the
new methods.
2025-01-15 14:11:18 +11:00
Lang Hames
42595bdaef [JITLink] Teach aarch64 GOT & PLT table managers to discover existing entries.
aarch64::GOTTableManager and aarch64::PLTTableManager will now look for
existing GOT and PLT sections and re-use existing entries if they're present.

This will be used for an upcoming MachO patch to enable compact unwind support.
2025-01-14 19:54:55 +11:00
Lang Hames
c9bc0fffa7 [JITLink] Fix incorrect file name in unit test file comment. 2025-01-14 18:40:10 +11:00
Lang Hames
4eaff6c58a [JITLink] Use target triple for LinkGraph pointer size and endianness.
Removes LinkGraph's PointerSize and Endianness members and uses the triple to
find these values instead.

Also removes some redundant Triple copies.
2025-01-14 18:11:19 +11:00
Lang Hames
300deebf41 [ORC] Make LazyReexportsManager implement ResourceManager.
This ensures that the reexports mappings are cleared when the resource tracker
associated with each mapping is removed.
2024-12-17 18:45:16 +11:00
Jared Wyles
2ccf7ed277
[JITLink] Switch to SymbolStringPtr for Symbol names (#115796)
Use SymbolStringPtr for Symbol names in LinkGraph. This reduces string interning
on the boundary between JITLink and ORC, and allows pointer comparisons (rather
than string comparisons) between Symbol names. This should improve the
performance and readability of code that bridges between JITLink and ORC (e.g.
ObjectLinkingLayer and ObjectLinkingLayer::Plugins).

To enable use of SymbolStringPtr a std::shared_ptr<SymbolStringPool> is added to
LinkGraph and threaded through to its construction sites in LLVM and Bolt. All
LinkGraphs that are to have symbol names compared by pointer equality must point
to the same SymbolStringPool instance, which in ORC sessions should be the pool
attached to the ExecutionSession.
---------

Co-authored-by: Lang Hames <lhames@gmail.com>
2024-12-06 10:22:09 +11:00
Lang Hames
6ef4990daa Re-apply "[ORC] Track all dependencies on symbols that aren't..." with fixes.
This reapplies 427fb5cc5ac, which was reverted in 08c1a6b3e18 due to bot
failures.

The fix was to remove an incorrect assertion: In IL_emit, during the initial
worklist loop, an EDU can have all of its dependencies removed without becoming
ready (because it may still have implicit dependencies that will be added back
during the subsequent propagateExtraEmitDeps operation). The EDU will be marked
Ready at the end of IL_emit if its Dependencies set is empty at that point.
Prior to that we can only assert that it's either Emitted or Ready (which is
already covered by other assertions).
2024-12-03 15:06:45 +11:00
Lang Hames
08c1a6b3e1 Revert "[ORC] Track all dependencies on symbols that aren't Ready yet."
This reverts commit 427fb5cc5ac34414c4682c90d3db0c63c5a1b227 while I investigate
the bot failure in https://lab.llvm.org/buildbot/#/builders/95/builds/6835.
2024-12-02 18:37:48 +11:00
Lang Hames
427fb5cc5a [ORC] Track all dependencies on symbols that aren't Ready yet.
AsynchronousSymbolQuery tracks the symbols that it depends on in order to (1)
detach the query in the event of a failure, and (2) report those dependencies
to clients of the ExecutionSession::lookup method (via the RegisterDependencies
argument). Previously we tracked only dependencies on symbols that didn't meet
the required state (the only symbols that the query needs to be attached to),
but this is insufficient to report all necessary dependencies to lookup clients.
E.g. A lookup requiring SymbolState::Resolved where some matched symbol is
already Resolved but not yet Emitted or Ready would result in the dependency on
that symbol not being reported, which could result in illegal access in
concurrent JIT setups. (This bug was discovered by @mikaoP on discord with a
simple concurrent JIT setup).

This patch tracks and reports all dependencies on symbols that aren't Ready yet,
correcting the under-reporting issue. AsynchronousSymbolQuery::detach is updated
to stop asserting that all depended-upon symbols have a query attached.
2024-12-02 13:17:19 +11:00
Lang Hames
521c996276 [JITLink] Move Symbol to new block before updating size.
Symbol::setSize asserts that the new size does not overflow the containing
block, so we need to point the Symbol at the correct Block before updating its
size (otherwise we may get a spurious overflow assertion).
2024-11-18 10:38:50 +11:00
Lang Hames
dc11c06015 [ORC] Move absoluteSymbols from Core.h to new AbsoluteSymbols.h header. NFC.
Continuing Core.h clean-up.

If you see any errors about a missing absoluteSymbols function you need to
include the new AbsoluteSymbols.h header.
2024-11-11 11:39:53 +11:00
Jonas Paulsson
9f73c69e5a
[ORC] Add signext on @sum() arguments in test. (#113308)
Make sure the inlined @sum() function has the right extension attributes
on its arguments.

A new struct TargetI32ArgExtensions is added that sets the Ret/Arg extension
strings given a string TargetTriple. This might be used elsewhere as well for
this purpose if needed.

Fixes: #112503
2024-11-05 04:13:40 +01:00
Lang Hames
529c091381 [ORC] Simplify JITLinkRedirectableSymbolManager, fix definition locations.
Redirectable stubs should be placed in the same JITDylib as their names, with
their lifetimes managed according to the ResourceTracker used when adding them.

The original implementation created a single pool of stubs in the JITDylib
that is passed to the JITLinkRedirectableSymbolManager constructor, but this
may cause the addresses of the redirectable symbols themselves (added to the
JITDylibs passed to createRedirectableSymbols) to appear outside the address
range of their defining JITDylib.

This patch fixes the issue by dropping the pool and emitting a new graph for
each set of requested redirectable symbols. We lose the ability to recycle
stubs, but gain the ability to free them entirely. Since we don't expect stub
reuse to be a common case this is likely the best trade-off.

If in the future we do need to return to a stub pool we should create a
separate one for each JITDylib to ensure that addresses behave as expected.
2024-11-02 15:22:02 +11:00
Lang Hames
1d657cfeac [ORC] Initialize native target in JITLinkRedirectionManagerTest test fixture.
The native target must be initialized here otherwise the test will be skipped
unless some prior test happens to initialize it. Failure to initialize the
native target was causing the test to be skipped when --gtest_filter was used.
2024-11-02 15:09:48 +11:00
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