3947 Commits

Author SHA1 Message Date
Jorge Gorbe Moya
ee1ee1144a Fix unused variable warning in non-debug build after 7d3dfc862d283319d01997c0672c50b4a082aa4e (NFC) 2025-04-03 16:50:19 -07:00
Henry Jiang
7d3dfc862d
[JITLink][XCOFF] Setup initial build support for XCOFF (#127266)
This patch starts the initial implementation of JITLink for XCOFF (Object format for AIX).
2025-04-03 17:01:18 -04:00
Lang Hames
191e0622e8 [JITLink][MachO][arm64] Don't lower ptrauth edges in noalloc-lifetime sections.
Ptrauth relocations can only be fixed up in the executing process, but noalloc
sections do not have any memory in the executing process. Failure to skip
ptrauth edges results in signing instructions that operate on invalid addresses,
leading to segfaults or data corruption.

Ignoring noalloc sections for ptrauth lowering purposes allows the ptrauth
edges to persist until they reach the applyFixup method, at which point they
raise a useful error and cleanly terminate linking.
2025-04-01 22:18:00 +11:00
Kazu Hirata
2de7b6ca4e
[ExecutionEngine] Use DenseMap::insert_range (NFC) (#133847)
We can safely switch to insert_range here because LR starts out empty.
Also, *Result is a DenseMap, so we know that the keys are unique.
2025-03-31 22:11:34 -07:00
Lang Hames
dad86f5931 [ORC] MapperJITLinkMemoryManager should deinitialize on abandon, not deallocate.
The JITLinkMemoryManager::InFlightAlloc::abandon method should only abandon
memory for the current allocation, not any other allocations. In
MapperJITLinkMemoryManager this corresponds to the deinitialize operation, not
the deallocate operation (which releases whole slabs of memory that may be
shared by many allocations).

No testcase: This was spotted by inspection. The failing program was linking
concurrently when one linker instance raised an error. Through the call to
abandon an entire underlying slab was deallocated, resulting in segfaults in
other concurrent links that were sharing that slab.
2025-03-31 14:08:42 +11:00
Kazu Hirata
825ecfed9e
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#133615) 2025-03-29 22:39:57 -07:00
Lang Hames
14c36db16f [ORC] Generalize GetDylibInterface to support MachO Universal Binaries.
Also adds a testcase for dylib handling in llvm-jitlink`s -weak-lx and
-weak_library options.
2025-03-28 13:28:04 +11:00
David Spickett
1f291acc97
Revert "[ExecutionEngine] Avoid repeated hash lookups (NFC)" (#133101)
Reverts llvm/llvm-project#132587

Due to causing test failures on several of Linaro's buildbots. Several
MLIR test failures and at least one test timing out.

I doubt it's the patch itself, but instead an issue it has uncovered.
Revert while we dig into that.
2025-03-26 15:06:13 +00:00
Kazu Hirata
40d251db4a
[llvm] Use *Set::insert_range (NFC) (#133041)
We can use *Set::insert_range to collapse:

  for (auto Elem : Range)
    Set.insert(E);

down to:

  Set.insert_range(Range);

In some cases, we can further fold that into the set declaration.
2025-03-26 07:46:24 -07:00
Kazu Hirata
0b181de206
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#132587) 2025-03-23 07:37:51 -07:00
Kazu Hirata
ac269e6d94
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#132143) 2025-03-20 09:10:53 -07:00
Kazu Hirata
099a11f4ab
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#131959) 2025-03-19 07:13:42 -07:00
Zequan Wu
6dbe82f061
[NFC][DebugInfo] Wrap DILineInfo return type with std::optional to handle missing debug info. (#129792)
Currently, `DIContext::getLineInfoForAddress` and
`DIContext::getLineInfoForDataAddress` returns empty DILineInfo when the
debug info is missing for the given address. This is not differentiable
with the case when debug info is found for the given address but the
debug info is default value (filename:linenum is <invalid>:0).

This change wraps the return types of `DIContext::getLineInfoForAddress`
and `DIContext::getLineInfoForDataAddress` with `std::optional`.
2025-03-17 17:01:06 -04:00
Kazu Hirata
78408fddcc
[ExecutionEngine] Avoid repeated map lookups (NFC) (#131552) 2025-03-16 23:52:47 -07:00
Kazu Hirata
d1700cdbf2
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#131423) 2025-03-15 09:12:23 -07:00
Lang Hames
3b5842c9c4 [ORC] Make runAllocActions and runDeallocActions asynchorous.
Part of ongoing work to make core ORC operations asynchronous.

This only affects the runner utilities, not the AllocationActions themselves.
The AllocationActions will be made asynchronous in a future patch.
2025-03-14 10:32:00 +11:00
Lang Hames
15e6bb6224 [ORC] Rename wrapper arguments to match conventions. NFCI. 2025-03-13 07:36:17 +11:00
Nikita Popov
f137c3d592
[TargetRegistry] Accept Triple in createTargetMachine() (NFC) (#130940)
This avoids doing a Triple -> std::string -> Triple round trip in lots
of places, now that the Module stores a Triple.
2025-03-12 17:35:09 +01:00
Lang Hames
76d5a79bed
[ORC] Drop EHFrameRegistrar, register eh-frames with AllocActions (#130719)
This simplifies resource management, and should improve performance for most use
cases.
2025-03-12 10:02:30 +11:00
Kazu Hirata
8c2714e448
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#130707) 2025-03-11 07:34:04 -07:00
Kazu Hirata
b4caea8466
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#130544) 2025-03-10 10:17:08 -07:00
Kazu Hirata
2d1634fab7
[ExecutionEngine] Avoid repeated map lookups (NFC) (#130461) 2025-03-09 00:47:42 -08:00
Zibi Sarbinowski
afbbca5c9d
[z/OS] Add call to shmctl() to release shared memory on z/OS (#130163)
This PR will solve the issue with leaking shared memory we have after running llvm lit test on z/OS.
In particular llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp was causing the leak.
2025-03-07 12:41:17 -05:00
Kazu Hirata
8bf13afd4a
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#130239) 2025-03-07 00:59:50 -08: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
Lang Hames
b18e5b6a36 Re-apply "[ORC] Remove the Triple argument from LLJITBuilder::..." with fixes.
This re-applies f905bf3e1ef860c4d6fe67fb64901b6bbe698a91, which was reverted in
c861c1a046eb8c1e546a8767e0010904a3c8c385 due to compiler errors, with a fix for
MLIR.
2025-03-06 17:17:05 +11:00
Lang Hames
c861c1a046 Revert "[ORC] Remove the Triple argument from LLJITBuilder::ObjectLinking..."
This reverts commit f905bf3e1ef860c4d6fe67fb64901b6bbe698a91 while I fix
some compile errors reported on the buildbots (see e.g.
https://lab.llvm.org/buildbot/#/builders/53/builds/13369).
2025-03-06 16:22:39 +11:00
Lang Hames
f905bf3e1e [ORC] Remove the Triple argument from LLJITBuilder::ObjectLinkingLayerCreator.
ExecutionSession can provide the Triple, so this argument has been redundant
for a while, and no in-tree clients use it.
2025-03-06 16:13:10 +11:00
Kazu Hirata
fb9329ce15
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#129822) 2025-03-05 08:59:26 -08:00
Kazu Hirata
178fb96f72
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#129466) 2025-03-03 01:02:57 -08:00
Kazu Hirata
70f4e6abf6
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#129356) 2025-03-01 08:15:00 -08:00
Kazu Hirata
9af10e3d9d
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#129191) 2025-02-28 08:04:09 -08:00
Lang Hames
8493467490 [JITLink][AArch64] Ensure that nulls remain null during ptrauth signing.
Signing a null pointer value can, and usually will, result in some high bits
being set, causing null checks to fail. E.g. in

extern void __attribute__((weak_import)) f(void);
void (*p) = &f;

if f is undefined then p should be null (left unsigned).

This patch updates lowerPointer64AuthEdgesToSigningFunction to check for
Pointer64Authenticated edges to null targets. Where found, these edges are
turned into plain Pointer64 edges (which we know from context will write a null
value to the fixup location), and signing instructions for these locations are
omitted from the signing function.
2025-02-28 15:19:41 +11:00
Kazu Hirata
42e5592538
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#128997) 2025-02-27 01:45:36 -08:00
Lang Hames
20cea4d410 [ORC] Sink include into implementation file.
TapiUniversal.h is only needed as an implementation detail.
2025-02-27 14:07:36 +11:00
Lang Hames
2e6d9af7e2 [ORC] Support adding LC_LOAD_WEAK_DYLIB commands to MachO JITDylib headers.
MachOPlatform synthesizes Mach headers for JITDylibs (see ef314d39b92). This
commit adds support for adding LC_LOAD_WEAK_DYLIB commands to these synthesized
headers (LC_LOAD_DYLIB was already supported previously).
2025-02-27 14:07:36 +11:00
Kazu Hirata
67d92cf384
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#128827) 2025-02-26 00:56:26 -08:00
Lang Hames
5114b9b386 [ORC][llvm-jitlink] Extend weak-linking emulation to real dylibs.
Commit 253e11695ba added support for emulating weak-linking against dylibs
that are (under the emulation) absent at runtime. This commit extends emulated
weak linking support to allow a real dylib to supply the interface (i.e.
-weak-lx / -weak_library can be pointed at a dylib, in which case they should
be read as "weak-link against this dylib, behavining as if it weren't actually
present at runtime").
2025-02-25 19:53:31 +11:00
Lang Hames
aa902a0380 [ORC] Add dependence on TextAPI to reflect changes in 253e11695ba. 2025-02-25 14:18:02 +11:00
Lang Hames
253e11695b [ORC][llvm-jitlink] Add support for emulating ld64 -weak-lx / -weak_library.
Linking libraries in ld64 with -weak-lx / -weak_library causes all references
to symbols in those libraries to be made weak, allowing the librarie to be
missing at runtime.

This patch extends EPCDynamicLibrarySearchGenerator with support for emulating
this behavior: If an instance is constructed with an Allow predicate but no
dylib handle then all symbols matching the predicate are immediately resolved
to null.

The llvm-jitlink tool is updated with -weak-lx / -weak_library options for
testing. Unlike their ld64 counterparts these options take a TBD file as input,
and always resolve all exports in the TBD file to null.
2025-02-25 13:54:17 +11:00
Kazu Hirata
4cfeebd9b4
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#127577) 2025-02-18 08:39:44 -08:00
Lang Hames
059f044309 [ORC] Propagate weak & hidden flags when creating lazy reexports, redirectables.
Updates JITLinkRedirectableSymbolManager to take alias flags into account when
setting the scope and linkage of the created stubs (weak aliases get now get weak
linkage, hidden stubs get hidden visibility).

Updates lazyReexports to propagate alias flags (rather than trampoline flags)
when building the initial destinations map for the redirectable symbols manager.

Together these changes allow the LazyObjectLinkingLayer to link objects
containing weak and hidden symbols.
2025-02-18 22:18:34 +11:00
Kazu Hirata
05209f1e59
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#127303) 2025-02-15 01:37:02 -08:00
Lang Hames
9456e7fcdd [ORC] Silence unused variable warnings. 2025-02-13 15:24:43 +11:00
NAKAMURA Takumi
cdf45447ef Orc: Suppress a warning in #126691 2025-02-13 13:07:19 +09:00
Kazu Hirata
31c4d17fbc [ExecutionEngine] Fix formatting (NFC) 2025-02-11 16:06:29 -08:00
Kazu Hirata
b72079e75d [ExecutionEngine] Fix a warning
This patch fixes:

  llvm/lib/ExecutionEngine/Orc/TargetProcess/UnwindInfoManager.cpp:53:20:
  error: unused variable 'AddFnName' [-Werror,-Wunused-variable]
2025-02-11 15:54:24 -08:00
Florian Mayer
9f61a60c77 [NFC] [clang] fixed unused variable warning 2025-02-11 15:30:00 -08:00
Lang Hames
84fe1f63b0
[ORC] Switch to singleton pattern for UnwindInfoManager. (#126691)
The find-dynamic-unwind-info callback registration APIs in libunwind
limit the number of callbacks that can be registered. If we use multiple
UnwindInfoManager instances, each with their own own callback function
(as was the case prior to this patch) we can quickly exceed this limit
(see https://github.com/llvm/llvm-project/issues/126611).

This patch updates the UnwindInfoManager class to use a singleton
pattern, with the single instance shared between all LLVM JITs in the
process.

This change does _not_ apply to compact unwind info registered through
the ORC runtime (which currently installs its own callbacks).

As a bonus this change eliminates the need to load an IR "bouncer"
module to supply the unique callback for each instance, so support for
compact-unwind can be extended to the llvm-jitlink tools (which does not
support adding IR).
2025-02-12 10:00:10 +11:00
Lang Hames
e2eaf8ded7 [ORC] Force eh-frame use for older Darwins on x86-64 in MachOPlatform, LLJIT.
The system libunwind on older Darwins does not support JIT registration of
compact-unwind. Since the CompactUnwindManager utility discards redundant
eh-frame FDEs by default we need to remove the compact-unwind section first
when targeting older libunwinds in order to preserve eh-frames.

While LLJIT was already doing this as of eae6d6d18bd, MachOPlatform was not.
This was causing buildbot failures in the ORC runtime (e.g. in
https://green.lab.llvm.org/job/llvm.org/job/clang-stage1-RA/3479/).

This patch updates both LLJIT and MachOPlatform to check a bootstrap value,
"darwin-use-ehframes-only", to determine whether to forcibly preserve
eh-frame sections. If this value is present and set to true then compact-unwind
sections will be discarded, causing eh-frames to be preserved. If the value is
absent or set to false then compact-unwind will be used and redundant FDEs in
eh-frames discarded (FDEs that are needed by the compact-unwind section are
always preserved).

rdar://143895614
2025-02-07 17:04:05 +11:00