3937 Commits

Author SHA1 Message Date
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
Lang Hames
7811c20bcd [ORC] Add a FIXME. NFC. 2025-02-07 14:28:01 +11:00
Lang Hames
9d88ffe7f7 [JITLink] Handle compact-unwind records that depend on DWARF FDEs.
Compact-unwind encodings are more limited than DWARF frame descriptions. For
functions whose frame layout cannot be described by a compact unwind encoding,
the encoding for the function will specify "use DWARF", and the corresponding
unwind-info record will use the low bits of the encoding to point to the FDE
for the function.

We test this with a frame-pointer=none function, since these frame layouts
always triger a fall-back to DWARF on arm64.
2025-02-06 16:10:30 +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
Lang Hames
88f55d16c4 [ORC] Fix buggy calculation of second-level-page offset in unwind-info.
SecondLevelPageOffset should be incremented by SecondLevelPageSize bytes, not
one byte.

Failure to calculate the offset correctly leads to corrupted unwind-info (and
consequently broken exceptions / unwinding) when more than one second level
page is needed. Since JITLink's unwind support only produces
UNWIND_SECOND_LEVEL_REGULAR-style pages this would trigger for any file
containing more than 511 functions with unwind info. The included test-case
contains 1022 functions (sufficient for both the current format and any
future implementation that supports UNWIND_SECOND_LEVEL_COMPRESSED pages).

Thanks to @edoardo on discord for spotting this bug!
2025-02-06 11:02:06 +11:00
Lang Hames
eae6d6d18b Re-reapply "[ORC] Enable JIT support for the compact-unwind..." with fixes.
Re-enables compact-unwind support in JITLink, which was reverted in b04847b427d
due to buildbot failures.

The underlying cause for the failures on the buildbots was the lack of
compact-unwind registration support on older Darwin OSes. Since the
CompactUnwindManager pass now removes eh-frames by default we were left with
unwind-info that could not be registered. On x86-64, where eh-frame info is
produced by default the solution is to fall back to using eh-frames. On arm64
we simply can't support exceptions on older OSes.

This patch updates the EHFrameRegistrationPlugin to remove the compact-unwind
section (__LD,__compact_unwind) when installed, forcing use of eh-frames when
the EHFrameRegistrationPlugin is used. In LLJIT, the EHFrameRegistrationPlugin
continues to be used for all non-Darwin platform, and will be added on Darwin
platforms when the a CompactUnwindRegistrationPlugin instance can't be created
(e.g. due to missing support for compact-unwind info registration).

The lit.cfg.py script is updated to check whether the host OSes default unwind
info supports JIT registration, allowing tests to be disabled for older Darwin
OSes on arm64.
2025-02-05 19:40:30 +11:00
Lang Hames
9de581b206 [ORC] Moch MachOPlatform unwind-info fixes.
Some eh-frame records are CIEs, which don't point to functions. We need to skip
these records. This patch reuses EHFrameCFIBlockInspector to identify function
targets, rather than a custom loop. Any performance impact will be minimal, and
essentially irrelevant once compact-unwind support re-lands (since at that
point we'll discard most eh-frame records).

For unwind-info sections: don't assume one block per record: the unwind-info
section packs all records into a single block.
2025-02-05 13:31:22 +11:00
Lang Hames
c67148d846 [ORC] Add note to call endSession to assertion messages.
The most likely cause of these assertions is a failure to call endSession. The
new message should clients spot the issue more easily.
2025-02-05 11:33:28 +11:00
Lang Hames
52b5e3638a [ORC] Fix eh-frame record target finding in MachOPlatform.
Unwind-info records only have one keep-alive edge to their target function, but
eh-frame records may have multiple edges (to the CIE, function, personality, and
lsda). We need to identify the target-function edge differently for each section
type.
2025-02-05 11:00:08 +11:00
Lang Hames
b84ac58dce [ORC] Rename MachOCompactUnwindSectionName to MachOUnwindInfoSectionName.
a1ff2d18466 should have disambiguated MachOCompactUnwindInfoSectionName to
MachOUnwindInfoSectionName, given how it's used in MachOPlatform and its
value.

A MachOCompactUnwindSectionName variable with an appropriate value will be
added in an upcoming patch to re-enable compact-unwind support in JITLink.
2025-02-05 11:00:08 +11:00
Zentrik
f8287f6c37
Fix build if ITTAPI_SOURCE_DIR is specified (#106924)
de92615d68f allows specifying the source directory of ittapi. This
change allows configuring the source directory of ittapi here as well.
2025-02-04 11:23:54 +11:00