4060 Commits

Author SHA1 Message Date
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
Stefan Gränitz
4268e677da
[ORC] Update ELF debugger support plugin to use AllocActions (#167866)
The `DebugObjectManagerPlugin` implements debugger support for ELF
platforms with the GDB JIT Interface. It emits a separate debug object
allocation in addition to the LinkGraph's own allocation. This used to
happen in the plugin's `notifyEmitted()` callback, i.e. after the
LinkGraph's allocation was finalized. In the meantime, it had to block
finalization of the corresponding materialization unit to make sure that
the debugger can register the object before the code runs.

This patch switches the plugin to use an allocation action instead. We
can remove the `notifyEmitted()` hook and implement all steps as JITLink
passes.
2025-11-17 09:33:03 +01:00
anoopkg6
82180558fe
JITLink: Add initial SystemZ Support. (#144528)
Set up initial infrastructure for SystemZ architecture support in
JITLink. It includes features like GOT and PLT handling. Relaxation of
GOT/PLT and support for TLS were intentionally left out for the moment.

Support for TLS might require info regarding moduleID. This could
further mean changes to target independent part of JITLink and library
support.

---------

Co-authored-by: anoopkg6 <anoopkg6@github.com>
2025-11-11 18:05:42 +01:00
serge-sans-paille
45a2320372
Remove unused <utility> inclusion
Per https://llvm.org/docs/CodingStandards.html#include-as-little-as-possible this improves compilation time, while not being too intrusive on the codebase.
2025-11-11 13:33:33 +01:00
serge-sans-paille
04b05998b1
Remove unused <array> and <list> inclusion (#167116) 2025-11-09 15:15:10 +00:00
Kazu Hirata
1b3eaacb9d
[llvm] Remove unused local variables (NFC) (#167185)
Identified with bugprone-unused-local-non-trivial-variable.
2025-11-08 22:56:03 -08:00
Kazu Hirata
c06f864558
[ExecutionEngine] Use StringRef::starts_with (NFC) (#167152)
Identified with modernize-use-starts-ends-with.
2025-11-08 10:16:16 -08:00
SahilPatidar
cc8f7cd252
[ORC][LibraryResolver] Fix ensureFilterBuilt assertion failure and concurrency issue. (#166510)
- Fixed architecture compatibility check.
Previously, we used `sys::getDefaultTriple()`, which caused issues on
build bots
using cross-compilation. We now ensure that the target architecture
where the
shared library (.so) is run or loaded matches the architecture it was
built for.

- Fixed ensureFilterBuilt assertion failure.

- Replaced use of FilteredView with a safer alternative for concurrent
environments.
The old FilteredView approach iterated over shared state without
sufficient
synchronization, which could lead to invalid accesses when libraries
were being
added or removed concurrently.
2025-11-06 12:30:22 +05:30
Kazu Hirata
4eed68357e
[llvm] Use "= default" (NFC) (#166088)
Identified with modernize-use-equals-default.
2025-11-02 17:16:47 -08:00
SahilPatidar
605a7d6534
REAPPLY [ORC] Add automatic shared library resolver for unresolved symbols. (attempt 2) (#165360)
This PR reapplies the changes previously introduced in
https://github.com/llvm/llvm-project/pull/148410.
It introduces a redesigned and rebuilt Cling-based auto-loading
workaround that enables scanning libraries and resolving unresolved
symbols within those libraries.

Fix build failures in LibraryResolverTest and silence symlink warning

This commit resolves issues observed in the build bots:

1. Silences the -Wunused-result warning by handling the return value
of ::symlink in LibraryResolverTest.cpp. Previously, ignoring
the return value triggered compiler warnings.

2. Fixes a linker error in OrcJITTests caused by an undefined
symbol: llvm::yaml::convertYAML. The test setup in
LibraryResolverTest.cpp now correctly links against the required
LLVM YAML library symbols.

3. Fixes persistent build bot failure caused by a path difference issue.

This resolves the build failures for PR
https://github.com/llvm/llvm-project/pull/148410 on the affected bots.
2025-11-01 11:19:28 +05:30
Kazu Hirata
817aff6960
[llvm] Use nullptr instead of 0 or NULL (NFC) (#165396)
Identified with modernize-use-nullptr.
2025-10-28 16:15:01 -07:00
Jordan Rupprecht
f58aa0ec8b
[ORC] Fix race when checking isComplete (#165063)
After #164340 there is a tsan race on `OutstandingSymbolsCount` when
decrementing it in `notifySymbolMetRequiredState` vs reading it in
`isComplete()`. Fix this by having `IL_emit` filter out non-completed
queries when it has the lock to do so, and that way we avoid needing to
call `isComplete()` later.
2025-10-25 07:49:02 -04:00
SahilPatidar
2afbd3df2a
Revert "REAPPLY [ORC] Add automatic shared library resolver for unresolved symbols. #148410" (#165069)
Reverting llvm/llvm-project#164551 due to persistent build bot failure
caused by a path difference issue.
2025-10-25 10:23:46 +05:30
SahilPatidar
4f53413ff0
REAPPLY [ORC] Add automatic shared library resolver for unresolved symbols. #148410 (#164551)
This PR reapplies the changes previously introduced in #148410.
It introduces a redesigned and rebuilt Cling-based auto-loading
workaround that enables scanning libraries and resolving unresolved
symbols within those libraries.
2025-10-24 15:13:29 +05:30
Kazu Hirata
c5f1c694ac
[ExecutionEngine] Add "override" where appropriate (NFC) (#164757)
Note that "override" makes "virtual" redundant.

Identified with modernize-use-override.
2025-10-23 07:09:03 -07:00
Lang Hames
9173846640
Reapply "[ORC] Replace ORC's baked-in dependence ... (#163027)" with … (#164340)
…fixes.

This reapplies c8c86efbbb5, which was reverted in 13ca8723d1b due to bot
failures. Those failures were compilation errors exposed when LLVM is
built with LLVM_ENABLE_EXPENSIVE_CHECKS=On. They have been fixed in this
commit.
2025-10-20 17:40:01 -07:00
Lang Hames
13ca8723d1 Revert "[ORC] Replace ORC's baked-in dependence tracking ... (#163027)"
Reverts commit c8c86efbbb55e51597c1bd8feb2e947bc0de3422 while I investigate bot
failures, e.g. https://lab.llvm.org/buildbot/#/builders/187/builds/12743.
2025-10-20 16:20:37 -07:00
Lang Hames
c8c86efbbb
[ORC] Replace ORC's baked-in dependence tracking with WaitingOnGraph. (#163027)
WaitingOnGraph tracks waiting-on relationships between nodes (intended
to represent symbols in an ORC program) in order to identify nodes that
are *Ready* (i.e. are not waiting on any other nodes) or have *Failed*
(are waiting on some node that cannot be produced).

WaitingOnGraph replaces ORC's baked-in data structures that were
tracking the same information (EmissionDepUnit, EmissionDepUnitInfo,
...). Isolating this information in a separate data structure simplifies
the code, allows us to unit test it, and simplifies performance testing.

The WaitingOnGraph uses several techniques to improve performance
relative to the old data structures, including symbol coalescing
("SuperNodes") and symbol keys that don't perform unnecessary reference
counting (NonOwningSymbolStringPtr).

This commit includes unit tests for common dependence-tracking issues
that have led to ORC bugs in the past.
2025-10-20 15:59:56 -07:00
SahilPatidar
8db1aabf8b
Revert "[ORC] Add automatic shared library resolver for unresolved symbols." (#163943)
Reverts llvm/llvm-project#148410

Reverting this change due to a few buildbot/test failures. Will
investigate and reapply once the issues are resolved.
2025-10-17 13:47:10 +02:00
SahilPatidar
1e7a23f822
[ORC] Add automatic shared library resolver for unresolved symbols. (#148410)
This PR introduces a redesigned and rebuilt Cling-based auto-loading
workaround, which enables scanning libraries and searching for
unresolved symbols within the scanned libraries.
2025-10-17 16:23:31 +05:30
Lang Hames
9c456e5eb7
[ORC] Add SimpleRemoteMemoryMapper (new MemoryMapper implementation). (#163707)
SimpleRemoteMemoryMapper is a MemoryMapper implementation that manages
remote memory via EPC-calls to reserve, initialize, deinitialize, and
release operations. It is compatible with the
SimpleExecutorMemoryManager backend, and its introduction allows
MapperJITLinkMemoryManager to use this backend.

It is also intended to be compatible with the
orc_rt::SimpleNativeMemoryMap backend.
2025-10-16 18:57:48 +11:00
Lang Hames
4374ca3cab
[ORC] Align ExecutorSimpleMemoryManager w/ orc_rt::SimpleNativeMemoryMap (#163693)
Teach ExecutorSimpleMemoryManager to handle slab reserve/release
operations, plus separate initialize/deinitialize for regions within the
slab. The release operation automatically deinitializes any regions
within each slab that have not already been released.

EPCGenericJITLinkMemoryManager is updated to use the reserve (allocate),
initialize (finalize), and relesae (deallocate) operations.

This brings ExecutorSimpleMemoryManager into alignment with the
orc_rt::SimpleNativeMemoryMap class, allowing SimpleNativeMemoryMap to
be used as a backend for EPCGenericJITLinkMemoryManager.

A future commit will introduce a new MemoryMapper class that will make
SimpleNativeMemoryMap usable as a backend for
MapperJITLinkMemoryManager.

This work will make it easier to re-use in-tree APIs and tools with the
new ORC runtime.
2025-10-16 16:08:23 +11:00
Lang Hames
8b60c05a7e
Revert "[ORC] Make runAllocActions and runDeallocActions asynchorous." (#163480)
This reverts commit 3b5842c9c41a441280100045ef62bb8a0fe7200f.

The intent of the original commit was to begin enabling asynchronous
alloation actions (calls attached to JIT'd memory initialization and
deinitialization). The asynchronous allocation actions scheme was
fleshed-out in a development branch, but ran into an issue: Functions
implementing actions are allowed to live in JIT'd code (e.g. in the ORC
runtime), but we can't genally rely on tail-call elimination kicking in.
This resulting in dealloc actions returning via stack frames that had
been deallocated, triggering segfaults.

It's possible that there are other approaches that would allow
asynchronous allocation actions to work, but they're not on the critical
path for JIT improvements so for now we'll just revert.
2025-10-15 12:21:28 +11:00
Lang Hames
2db5b326e1
[ORC] Add LinkGraph& argument to MemoryMapper::prepare. (#163121)
This gives MemoryMapper implementations a chance to allocate working
memory using the LinkGraph's allocator.
2025-10-13 17:20:39 +11:00
SahilPatidar
bb36630ecd
[ORC][Runtime] Add dlupdate for coff (#115448)
With the help of @lhames, This pull request introduces the dlupdate
function in the ORC runtime. dlupdate enables incremental execution of
new initializers introduced in the REPL environment. Unlike traditional
dlopen, which manages initializers, code mapping, and library reference
counts, dlupdate focuses exclusively on running new initializers.
2025-10-08 17:15:44 +05:30
SahilPatidar
e05d80ec7b
[ORC] Add Executor Resolver Utility (#143654)
This patch adds the new **executor-side resolver API** as suggested by
@lhames. It introduces a `DylibSymbolResolver` that helps resolve
symbols for each loaded dylib.

Previously, we returned a `DylibHandle` to the controller. Now, we wrap
the native handle inside `DylibSymbolResolver` and return a
`ResolverHandle` instead. This makes the code cleaner and separates the
symbol resolution logic from raw handle management.
2025-10-07 11:52:53 +05:30
Lang Hames
a7016c43da
[JITLink] Add LinkGraph name / triple to debugging output. (#161772)
Adds the name and triple of the graph to LinkGraph::dump output before
the rest of the graph content. Calls from JITLinkGeneric.cpp to dump the
graph are updated to avoid redundantly naming the graph.
2025-10-03 15:24:29 +10:00
Lang Hames
f29f1112f5 [JITLink][MachO] Use Triple::isArm64e consistently. 2025-10-01 11:07:37 +10:00
wanglei
6b23f4fc4d
[LoongArch] Add R_LARCH_MARK_LA relocation for la.abs
Match gas behavior: generate `R_LARCH_MARK_LA` relocation for `la.abs`.

Reviewers: heiher, SixWeining

Reviewed By: SixWeining, heiher

Pull Request: https://github.com/llvm/llvm-project/pull/161062
2025-09-30 09:58:12 +08:00
Kazu Hirata
84a796d7dd
[ExecutionEngine] Use std::tie for a lexicographical comparison (NFC) (#160007) 2025-09-21 19:17:05 -07:00
Zhijin Zeng
7a58e77143
[JITLink][RISC-V] Support R_RISCV_SET_ULEB128/R_RISCV_SUB_ULEB128 (#153778)
Support bolt instrument the elf binary which has exception handling table.

Fixes #153775
2025-09-09 17:51:30 +08:00
Matt Arsenault
819aa3521e
MC: Use Triple form of lookupTarget in more places (#157591) 2025-09-09 16:33:39 +09:00