4091 Commits

Author SHA1 Message Date
Min-Yih Hsu
696ea11b94
[ELFDebugObjectPlugin] Do not wait for std::future in post-fixup phase in the absent of debug info (#178541)
If there is no debug information, we wouldn't call
`DebugObject::collectTargetAlloc` in the post-allocation phase.
Therefore, when it's in the post-fixup phase,
`DebugObject::awaitTargetMem` will fail with _"std::future_error: No
associated state"_ because the std::future was not even populated.
2026-01-29 18:24:25 +00:00
serge-sans-paille
47bfb42bed
[perf] Replace copy-assign by move-assign in llvm/lib/ExecutionEngine/* (#178173) 2026-01-27 13:21:11 +00:00
Yaxing Cai
1b37911f1a
[ORC] Fix missing support of deinitialize on ELF platform and execution order by priority (#175981)
This PR fixes
1. issue #175509 about missing support of deinitialize on ELF platform. 
2. missing support of execution order by proirity at both initialize and
deinitialize stage.

cc: @tqchen @joker-eph
2026-01-22 17:31:28 +11:00
Jameson Nash
2458387ac1
[NFC] replace getValueType with more specific getFunctionType (#177175)
When trivially valid already, use the more specific method, instead of
casting the result of the less specific method.
2026-01-21 10:30:09 -05:00
Sven van Haastregt
2f119133ba
Add missing newlines at EOF; NFC (#176192) 2026-01-16 10:41:39 +01:00
Lang Hames
d16413ad22
[JITLink][CompactUnwind] Explicitly enumerate mergeable encodings. NFCI. (#176317)
Updates CompactUnwindTraits_MachO_arm64 and
CompactUnwindTraits_MachO_x86_64 encodingCanBeMerged methods to use
switch statements that clearly list mergeable encodings, and have a
default "false" case.

Since the new scheme explicitly covers DWARF modes (always
non-mergeable), this patch removes the separate DWARF mode check from
mergeRecords in CompactUnwindSupport.h.
2026-01-16 18:13:25 +11:00
Lang Hames
3bdd794f98
[JITLink][CompactUnwind] Expand CompactUnwindTraits struct comment. (#176315)
Adds notes on the properties and methods that must be implemented by
traits classes derived from CompactUnwindTraits.
2026-01-16 17:15:45 +11:00
Lang Hames
66e4919b22
[JITLink][CompactUnwind] Express mergeability via +ve predicate. NFCI. (#176313)
Compact unwind record merging is an optimization. Using a can-be-merged
predicate is preferrable to a "cannot-be-merged" predicate as the former
encourages conservatively correct implementations: "what is safe to
merge" is easier to reason about than "what is safe to not not merge".
2026-01-16 17:12:24 +11:00
Lang Hames
a9e852c0fa
[ORC][MachO] Clean up incompatible-arch-in-object error message. (#176092)
Add missing spaces to error messages, use Triple::getArchName (gives
canonical arch name on Darwin, e.g. "arm64" rather than "aarch64").

No testcase for this one: the change is cosmetic, and the error message
format not relied upon anywhere.
2026-01-15 18:23:49 +11:00
hev
29419c48d5
[JITLink][LoongArch] Refactor jump stub to support LA32R (#175355) 2026-01-15 10:54:22 +08:00
hev
9c7904bac2
[JITLink][LoongArch] Add reloc types for LA32R/LA32S (#175353) 2026-01-14 18:03:56 +08:00
anoopkg6
ab34189878
[JITLink] Add GOT indirection optimization for SystemZ (#171919)
Optimize the GOT and Stub relocations if the edge target address is in
range from call site - Indirect jump by plt stub can be replaced with
direct jump to target in post-allocation optimization.
2026-01-12 17:47:13 +01:00
aokblast
ba6a59c875
[JITLink] Set correct triple instead of hard-code the value to linux (#175404) 2026-01-12 16:13:13 +11:00
Lang Hames
f114d95926
[ORC] Simplify zero initializer. NFCI. (#175482)
Based on suggestion from @macdice on
https://github.com/llvm/llvm-project/pull/175204. Thanks @macdice!
2026-01-12 16:11:24 +11:00
Anthonin Bonnefoy
91dafc7f40
[ORC][JITLink] Fix unitialised JIT dump header (#175204)
When trying to perf inject JIT dump generatd through the perf plugin,
perf fails with the following error:
```
jitdump file contains invalid or unsupported flags 0xf5880666c26c
0x2b750 [0xa8]: failed to process type: 10 [Operation not permitted]
```
It turns out that Header's Flags field was never initialized, so the
value could be random.
This patch fixes the issue by initialising all Header's fields.

Co-authored-by: Lang Hames <lhames@gmail.com>
2026-01-12 14:13:31 +11:00
Icenowy Zheng
458a983df4
[RuntimeDyld][MIPS] Use AT for stub function instead of T9 (#174354)
The stub function is generated for R_MIPS_26 relocation, which could be
used for local jumping inside a function, and do not expect any
temporary register to be clobbered.

Use AT instead of T9 for the stub function, otherwise functions using T9
will be messed up.

Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
2026-01-12 10:50:43 +08:00
Lang Hames
dcf8ae8028
Reapply "[ORC] Add utilities for limited symbolication of JIT backtra… (#175469)
…ces"

This reapplies 906b48616c03948a4df62a5a144f7108f3c455e8, which was
reverted in c11df52f9b847170b766fb71defd2a9222d95a8d due to bot
failures.

The testcase has been dropped from this recommit as it failed on several
bots (possbly due to differing backtrace formats or failure modes). I'll
re-introduce the testcase in a follow-up commit so that it cane be
iterated on (and re-reverted if necessary) without affecting the options
introduced by this commit. (Since these options are best-effort
debugging tools it's ok if they live in-tree without a test for now).
2026-01-12 12:23:07 +11:00
Vedran Miletić
f091be6d53
[ORC] Fixed incorrect additional header dirs (#175193)
The CMake ADDITIONAL_HEADER_DIRS directive for two Orc libraries,
specifically Shared and TargetProcess, used incorrect values that
pointed to its parent library include directory instead of its own. This
is now fixed.
2026-01-12 10:24:45 +11:00
WANG Rui
4ecee62133 [JITLink][LoongArch][NFC] Move applyFixup implementation from header to source file 2026-01-10 22:58:25 +08:00
Aiden Grossman
c11df52f9b Revert "[ORC] Add utilities for limited symbolication of JIT backtraces (#175099)"
This reverts commit 906b48616c03948a4df62a5a144f7108f3c455e8.

The forward fix for this got reverted in
25976e83606f1a7615e3725e6038bb53ee96c3d5, so reverting the original
commit given it is still broken and the forward fix that mitigated most
of the issues is no longer in tree.
2026-01-09 22:13:57 +00:00
Nikita Popov
ecc8a955af
[CommandLine] Use DenseMap instead of StringMap (NFC) (#174988)
StringMap duplicates the option name to a new allocation for every
option, which is not necessary. Instead we can use the same StringRef
that the Option already uses inside a DenseMap. This reduces the amount
of allocations when loading libLLVM.
2026-01-09 15:22:28 +01:00
Lang Hames
906b48616c
[ORC] Add utilities for limited symbolication of JIT backtraces (#175099)
This patch adds tools for capturing symbol information from JIT'd code
and using it to symbolicate backtraces. This is useful for debugging
crashes in JIT-compiled code where traditional symbolication tools may
not have access to the JIT symbol table. These tools are not a general
solution to the JIT symbolication problem (that will require further
integration with system components like libunwind, the dynamic linker,
and/or crash tracing tools), but will aid in JIT debugging and
development until a general solution is available.

APIs Added:

1. SymbolTableDumpPlugin - A LinkGraphLinkingLayer::Plugin that captures
symbol information as code is JIT'd and writes it to a file.

- Create(StringRef Path) ->
Expected<std::shared_ptr<SymbolTableDumpPlugin>> Creates a plugin that
appends symbol information to the specified file.

- Symbol table format: "<link graph name>" <address> <symbol name>
<address> <symbol name> ...

The plugin uses a PostAllocationPass to write symbols after addresses
have
   been assigned but before the code is finalized.

2. DumpedSymbolTable - A class for symbolicating backtraces using a
previously dumped symbol table.

- Create(StringRef Path) -> Expected<DumpedSymbolTable> Loads and parses
a symbol table from a file.

- symbolicate(StringRef Backtrace) -> std::string Given text of a
backtrace, for rows ending with a hex address, adds the symbol name,
offset, and defining graph name.

New `llvm-jitlink` Command Line Options:

1. -write-symtab=<path> Enables the SymbolTableDumpPlugin to write
symbol information to the specified file as objects are JIT'd. The
symbol table can then be used to symbolicate backtraces from crashes or
signal handlers.

2. -symbolicate-with=<path> Runs llvm-jitlink in symbolication mode.
Reads the symbol table from <path> and symbolicates backtraces read from
stdin or input files.

Usage Examples:

$ llvm-jitlink -write-symtab=symbols.txt mycode.o

$ llvm-jitlink -symbolicate-with=symbols.txt - < backtrace.txt
2026-01-09 15:42:00 +11:00
Lang Hames
a1c2882d72
[ORC] Add JITDylibDefunct Error. (#174923)
This Error can be returned from operations on JITDylibs that cannot
proceed as the target JITDylib has been closed.

This patch uses the new error to replace an unsafe assertion in
JITDylib::define: If a JITDylib::define operation is run by an in-flight
task after the target JITDylib is closed it should error out rather than
asserting.

See also https://github.com/llvm/llvm-project/issues/174922
2026-01-09 09:29:22 +11:00
Lang Hames
b4c68cb224
[ORC][C API] Replace 'bool' with 'LLVMBool'. (#174525)
The LLVM C APIs use LLVMBool rather than bool. This should fix the
failure in https://lab.llvm.org/buildbot/#/builders/29/builds/19955 and
similar builds.
2026-01-06 15:34:47 +11:00
Thomas Munro
2945e44750
[C-API] Allow SectionMemoryManager's ReserveAlloc flag to be enabled (#174307)
Allow C programs to pass a ReserveAlloc flag to the constructor of
llvm::SessionMemoryManager, using a new variant of
LLVMOrcCreateRTDyldObjectLinkingLayerWithSectionMemoryManager that has
...ReserveAlloc() appended to its name.
2026-01-06 14:01:26 +11:00
SahilPatidar
a6d2f24176
[Orc][LibResolver] Refactor resolver internals and simplify symbol resolution. (#169161)
- Replace getLibraries() with cursor-based iteration.
- Simplify search logic and handle new libraries during scanning.
- Make symbol resolution faster with single enumeration and early exit.
2026-01-04 14:37:39 +05:30
Victor Chernyakin
c438773432
[LLVM][ADT] Migrate users of make_scope_exit to CTAD (#174030)
This is a followup to #173131, which introduced the CTAD functionality.
2026-01-02 20:42:56 -08:00
Lang Hames
5be1d4b0dc
[ORC] Fix ReOptimizeLayer buggy jit-dispatch signature in fa7f7a4cab4. (#173457)
fa7f7a4cab4 changed the jit-dispatch function signature used in the
orc_rt_lite_reoptimize_helper function, but jit-dispatch still takes a
raw data pointer and size argument.

Should fix the bug in
https://lab.llvm.org/buildbot/#/builders/169/builds/18319 and similar
builds.
2025-12-24 19:15:07 +11:00
Lang Hames
fa7f7a4cab
[ORC] Pass JITDispatchHandler argument buffers as WrapperFunctionBuffer. (#173334)
Updates ExecutionSession::runJITDispatchHandler to take the argument
buffer for the function as a WrapperFunctionBuffer, rather than an
ArrayRef<char>.

This is a first step towards more efficient jit-dispatch handler calls:

1. Handlers can now be run as tasks, since they own their argument
buffer (so there's no risk of it being deallocated before they're run)
2. In in-process JIT setups, this will allow argument buffers to be
passed in directly from the ORC runtime, rather than having to copy the
buffer.
2025-12-24 09:18:38 +11:00
Lang Hames
01effcd82d
[ORC] Add, and call through, reoptimize function in ReOptimizeLayer. (#173204)
ReOptimizeLayer was building LLVM IR to define a precomputed,
SPS-serialized argument buffer, then inserting calls directly to
__orc_rt_jit_dispatch, passing the address of the precomputed buffer and
an __orc_rt_reoptimize_tag defined by the ORC runtime. This design is
non-canonical, requiring the ORC runtime to be loaded (or an extra
definition for __orc_rt_reoptimize_tag to be inserted) while not using
the runtime to perform the serialization.

This commit updates ReOptimizeLayer to instead insert calls to an
__orc_rt_reoptimize function implemented in the ORC runtime. This
function will perform serialization and call __orc_rt_jit_dispatch,
similar to other functions in the ORC runtime.

To maintain support for in-process JITs that don't use the ORC runtime,
this commit adds a ReOptimizeLayer::addOrcRTLiteSupport method which
injects IR to define __orc_rt_reoptimize (calling through to an
orc_rt_lite_reoptimize_helper function defined in LLVM) and
__orc_rt_reoptimize_tag. The ReOptimizeLayerTest is updated to use
addOrcRTLiteSupport.
2025-12-23 17:28:28 +11:00
Stefan Gränitz
fea987b5ee
[ORC] Fix unchecked Expected<T> in ELFDebugObjectPlugin::FinalizePromise (#172904)
If `Alloc.finalize()` fails in the post-allocation pass, we store the
error in `FinalizePromise`. If we don't reach the post-fixup pass
afterwards the error will leak. This patch adds another case in the
DebugObject destructor that will check the `Expected<T>` and report the
error.
2025-12-20 17:11:36 +01:00
Lang Hames
48c8c45475
[ORC] Fix typo in method name. NFCI. (#172787)
"reigsterRuntimeFunctions" should be "registerRuntimeFunctions".
2025-12-18 16:14:01 +11:00
Michael Smith
35b2b24e62
Implement reserveAllocationSpace for SectionMemoryManager (#71968)
Implements `reserveAllocationSpace` and provides an option to enable
`needsToReserveAllocationSpace` for large-memory environments with
AArch64.

The [AArch64
ABI](https://github.com/ARM-software/abi-aa/blob/main/sysvabi64/sysvabi64.rst#7code-models)
has restrictions on the distance between TEXT and GOT sections as the
instructions to reference them are limited to 2 or 4GB. Allocating
sections in multiple blocks can result in distances greater than that on
systems with lots of memory. In those environments several projects
using SectionMemoryManager with MCJIT have run across assertion failures
for the R_AARCH64_ADR_PREL_PG_HI21 instruction as it attempts to address
across distances greater than 2GB (an int32).

Fixes #71963 by allocating all sections in a single contiguous memory
allocation, limiting the distance required for instruction offsets
similar to how pre-compiled binaries would be loaded into memory.

Co-authored-by: Lang Hames <lhames@gmail.com>
2025-12-18 13:19:45 +11:00
Lang Hames
ad5a02a603
[ORC] Rewrite loop to use structured bindings. NFCI. (#172631) 2025-12-18 08:03:56 +11:00
Lang Hames
558760009c
[ORC] Rename WrapperFunctionResult to WrapperFunctionBuffer. NFCI. (#172633)
Also renames CWrapperFunctionResult to CWrapperFunctionBuffer.

These types are used as argument buffers, as well as result buffers. The
new name better reflects their purpose, and is consistent with naming in
the new ORC runtime (llvm-project/orc-rt).
2025-12-18 07:57:06 +11:00
Nikita Popov
b963def2cb
[ELFDebugObjectPlugin] Gracefully handle missing section (#172622)
On ppc64le some sections like .toc get merged into other sections by
JITLink. As such, some sections in the object file may not be present in
the link graph. Skip those sections.
2025-12-17 15:04:59 +01:00
Lang Hames
dec5d66374
[ORC] Make WrapperFunctionResult constructor explicit. (#172602)
The WrapperFunctionBuffer(CWrapperFunctionBuffer) constructor takes
ownership of the underlying buffer (if one exists). Making the
constructor explicit makes this clearer at the call site.
2025-12-17 18:38:28 +11:00
Stefan Gränitz
d2a097d6a3
Reland: [ORC] Tailor ELF debugger support plugin to load-address patching only (#169482)
In 4 years the ELF debugger support plugin wasn't adapted to other
object formats or debugging approaches. After the renaming NFC in
https://github.com/llvm/llvm-project/pull/168343, this patch tailors the
plugin to ELF and section load-address patching. It allows removal of
abstractions and consolidate processing steps with the newly enabled
AllocActions from https://github.com/llvm/llvm-project/pull/168343.

The key change is to process debug sections in one place in a
post-allocation pass. Since we can handle the endianness of the ELF file
the single `visitSectionLoadAddresses()` visitor function now, we don't
need to track debug objects and sections in template classes anymore. We
keep using the `DebugObject` class and drop `DebugObjectSection`,
`ELFDebugObjectSection<ELFT>` and `ELFDebugObject`.

Furthermore, we now use the allocation's working memory for load-address
fixups directly. We can drop the `WritableMemoryBuffer` from the debug
object and most of the `finalizeWorkingMemory()` step, which saves one
copy of the entire debug object buffer. Inlining `finalizeAsync()` into
the pre-fixup pass simplifies quite some logic.

The original patch broke compiler-rt checks: db5eeddbd3
Reverted with: 0182a76970
2025-12-16 12:04:00 +01:00
anoopkg6
d0767e96f9
[JITLink] Add TLS support for SystemZ (#171559)
This patch adds TLS support for SystemZ on top of orc-runtime support. A
separate orc-runtime support #171062 has been created from earlier TLS
support #[170706](https://github.com/llvm/llvm-project/pull/170706).

See conversations in
[#170706](https://github.com/llvm/llvm-project/pull/170706)

---------

Co-authored-by: anoopkg6 <anoopkg6@github.com>
2025-12-11 12:11:50 +01:00
anoopkg6
e60a3325a3
[JITLink] Add orc-runtime support for SystemZ (#171062)
Add orc-runtime support and tests for SystemZ.

Co-authored-by: anoopkg6 <anoopkg6@github.com>
2025-12-09 12:07:40 +01:00
Thomas Munro
2222cfe7e1
[C-API] LLVMOrcCreateObjectLinkingLayerWithInProcessMemoryManager (#169862)
Allow C programs to use JITLink with trivial new C-API wrapper. Modeled
on `LLVMOrcCreateRTDyldObjectLinkingLayerWithSectionMemoryManager`
except that it has to deal with failure of
`jitlink::InProcessMemoryManager::Create()`. Function name suggested by
@lhames in https://github.com/llvm/llvm-project/issues/106203.

I suppose failure of underlying platform-specific things like
`sysconf(_SC_PAGESIZE)` shouldn't really happen. An alternative error
reporting style might be to follow
`LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess` and return
`LLVMErrorRef` with an output parameter for the `LLVMOrcObjectLayerRef`,
but then it wouldn't be a drop-in replacement for
`LLVMOrcCreateRTDyldObjectLinkingLayerWithSectionMemoryManager`.
Thoughts?

This is wanted by PostgreSQL (branch using this API:
https://github.com/macdice/postgres/tree/llvm-22-proposed-c-api). (We're
also using `LLVMCreatePerfJITEventListener`,
`LLVMCreatePerfJITEventListener`,
`LLVMOrcRTDyldObjectLinkingLayerRegisterJITEventListener`, so it looks
like we'll need to research `PerfSupportPlugin`,
`DebuggerSupportPlugin`, `ObjectLinkingLayer::addPlugin()`...)
2025-12-04 14:22:07 +11:00
Kazu Hirata
2b81e9e8fe
[Orc] Use a range-based for loop (NFC) (#169240)
Identified with modernize-loop-convert.
2025-11-23 22:32:58 -08:00
Stefan Gränitz
0182a76970
Revert "[ORC] Tailor ELF debugger support plugin to load-address patching only" (#169073)
Reverts llvm/llvm-project#168518
2025-11-21 19:14:09 +01:00
Stefan Gränitz
db5eeddbd3
[ORC] Tailor ELF debugger support plugin to load-address patching only (#168518)
In 4 years the ELF debugger support plugin wasn't adapted to other
object formats or debugging approaches. After the renaming NFC in
https://github.com/llvm/llvm-project/pull/168343, this patch tailors the
plugin to ELF and section load-address patching. It allows removal of
abstractions and consolidate processing steps with the newly enabled
AllocActions from https://github.com/llvm/llvm-project/pull/168343.

The key change is to process debug sections in one place in a
post-allocation pass. Since we can handle the endianness of the ELF file
the single `visitSectionLoadAddresses()` visitor function now, we don't
need to track debug objects and sections in template classes anymore. We
keep using the `DebugObject` class and drop `DebugObjectSection`,
`ELFDebugObjectSection<ELFT>` and `ELFDebugObject`.

Furthermore, we now use the allocation's working memory for load-address
fixups directly. We can drop the `WritableMemoryBuffer` from the debug
object and most of the `finalizeWorkingMemory()` step, which saves one
copy of the entire debug object buffer. Inlining `finalizeAsync()` into
the pre-fixup pass simplifies quite some logic.

We still track `RegisteredObjs` here, because we want to free memory
once the corresponding code is freed. There will be a follow-up patch
that turns it into a dealloc action.
2025-11-21 15:05:51 +01:00
Stefan Gränitz
907e8514b1
[ORC] Remove now unused EPCDebugObjectRegistrar (NFC) (#167868)
EPCDebugObjectRegistrar is unused now that the ELF debugger support plugin uses AllocActions
https://github.com/llvm/llvm-project/pull/167866
2025-11-19 10:39:08 +01:00
Stefan Gränitz
4c9020ded7 [ORC] Fix shlibs build: add Object to libLLVMOrcDebugging (#168343) 2025-11-18 13:59:06 +01:00
Stefan Gränitz
3ce893f834
[ORC] Move DebugObjectManagerPlugin into Debugging/ELFDebugObjectPlugin (NFC) (#168343)
In 4 years the plugin wasn't adapted to other object formats. This patch
makes it specific for ELF, which will allow to remove some abstractions
down the line. It also moves the plugin from LLVMOrcJIT into
LLVMOrcDebugging, which didn't exist back then.
2025-11-18 11:44:00 +01:00
Lang Hames
f15b756b56
[ORC] Remove unnecessary LLVM_ABI on function def. NFCI. (#168478) 2025-11-18 17:51:37 +11:00
Lang Hames
4b0d422753
[ORC] Support scanning "fallback" slices for interfaces. (#168472)
When scanning an interface source (dylib or TBD file), consider
"fallback" architectures (CPUType / CPUSubType pairs) in addition to the
process's CPUType / CPUSubType.

Background:

When dyld loads a dylib into a process it may load dylib or slice whose
CPU type / subtype isn't an exact match for the process's CPU type /
subtype. E.g. arm64 processes can load arm64e dylibs / slices.

When building an interface we need to follow the same logic, otherwise
we risk generating a spurious "does not contain a compatible slice"
error. E.g. If we're running an arm64 JIT'd program and loading an
interface from a TBD file, and if no arm64 slice is present in that
file, then we should fall back to looking for an arm64e slice.

rdar://164510783
2025-11-18 13:54:02 +11:00
Lang Hames
17f0afe40a
[ORC] Merge GetDylibInterface.h APIs into MachO.h. (#168462)
These APIs are MachO specific, and the interfaces are about to be
extended to support more MachO-specific behavior. For now it makes sense
to group them with other MachO specific APIs in MachO.h.
2025-11-18 11:51:08 +11:00