744 Commits

Author SHA1 Message Date
Kazu Hirata
84f4465135
[ExecutionEngine] Remove unnecessary casts (NFC) (#153931)
getLoadAddressWithOffset() and getLoadAddress() already return
uint64_t.
2025-08-16 06:47:25 -07:00
Kazu Hirata
35dd88918f
[llvm] Use llvm::iterator_range::empty (NFC) (#151905) 2025-08-04 07:40:46 -07:00
Kazu Hirata
b04968c4cd
[ExecutionEngine] Remove an unnecessary cast (NFC) (#151798)
value() already returns uint64_t.
2025-08-02 08:09:18 -07:00
Kazu Hirata
84576c7b5d
[ExecutionEngine] Remove an unnecessary cast (NFC) (#151082)
BaseObj is already of const MachOObjectFile &.
2025-07-29 08:18:53 -07:00
Kazu Hirata
f8ee63d9a9
[ExecutionEngine] Remove unnecessary casts (NFC) (#150785)
getArch() already returns Triple::ArchType.
2025-07-26 18:15:23 -07:00
Ami-zhang
4e35ae10c4
[RuntimeDyld][LoongArch] Support large code model (#148584)
Co-authored-by: Weining Lu <luweining@loongson.cn>
2025-07-21 09:28:24 +08:00
Kazu Hirata
8da1ac98ef
[llvm] Use std::tie to implement operator< (NFC) (#143728)
std::tie facilitates lexicographical comparisons through std::tuple's
built-in operator<.
2025-06-11 12:50:27 -07:00
wanglei
91edbe2231
[lldb][LoongArch] Fix expression function call failure
After upgrading the default code model from small to medium on
LoongArch, function calls using expression may fail. This is because the
function call instruction has changed from `bl` to `pcalau18i + jirl`,
but `RuntimeDyld` does not handle out-of-range jumps for this
instruction sequence.

This patch fixes: #136561

Reviewed By: SixWeining

Pull Request: https://github.com/llvm/llvm-project/pull/136563
2025-04-23 16:15:29 +08:00
dlav-sc
14cb8c56b2
[lldb] add required for lldb RISCV relocations in MCJIT (#126266)
After implementing CFI instructions in the function prologue, LLDB
testing for RISC-V started failing due to insufficient relocations
(e.g., R_RISCV_SET8, R_RISCV_SET16).

This patch adds support for the necessary RISC-V relocations in MCJIT.
2025-04-14 15:15:33 +03: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
0b181de206
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#132587) 2025-03-23 07:37:51 -07: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
Kazu Hirata
2d1634fab7
[ExecutionEngine] Avoid repeated map lookups (NFC) (#130461) 2025-03-09 00:47:42 -08:00
Kazu Hirata
8bf13afd4a
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#130239) 2025-03-07 00:59:50 -08:00
Kazu Hirata
178fb96f72
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#129466) 2025-03-03 01:02:57 -08:00
Fangrui Song
1e53f9523d
[CMake] Remove some always-true HAVE_XXX_H
These are unneeded even on AIX, PURE_WINDOWS, and ZOS (per #104706)

* HAVE_ERRNO_H: introduced by 1a93330ffa2ae2aa0b49461f05e6f0d51e8443f8 (2009) but unneeded.
  The guarded ABI is unconditionally used by lldb.
* HAVE_FCNTL_H
* HAVE_FENV_H
* HAVE_SYS_STAT_H

Pull Request: https://github.com/llvm/llvm-project/pull/123087
2025-01-15 09:53:21 -08: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
Kazu Hirata
1f4d91ecb8
[ExecutionEngine] Remove unused includes (NFC) (#116749)
Identified with misc-include-cleaner.
2024-11-19 19:41:59 -08:00
Rahul Joshi
5c8c90d821
[NFC][LLVM] Fix a couple of build warnings (#116490)
- Fix `HANDLE_EXTENSION` macro redefinition warning in LTOBackend.cpp
- Fix "unnecessary brackets" around rf/df variable definitions warning.
2024-11-17 07:54:41 -08:00
wanglei
4e668d5b27
[RuntimeDyld] Add LoongArch support
This is necessary for supporting function calls in LLDB expressions for
LoongArch.
This patch is inspired by #99336 and simply extracts the parts related
to RuntimeDyld.

Reviewed By: lhames

Pull Request: https://github.com/llvm/llvm-project/pull/114741
2024-11-08 10:42:31 +08:00
Kazu Hirata
11c6ea3d3b
[ExecutionEngine] Avoid repeated hash lookups (NFC) (#111275) 2024-10-06 09:22:27 -07:00
dlav-sc
87121403e2
[lldb][RISCV] function calls support in lldb expressions (#99336)
[lldb][RISCV] add jitted function calls to ABI
Function calls support in LLDB expressions for RISCV: 1 of 4

Augments corresponding functionality to RISCV ABI, which allows to jit
lldb expressions and thus make function calls inside them. Only function
calls with integer and void function arguments and return value are
supported.

[lldb][RISCV] add JIT relocations resolver
Function calls support in LLDB expressions for RISCV: 2 of 4

Adds required RISCV relocations resolving functionality in lldb
ExecutionEngine.

[lldb][RISCV] RISC-V large code model in lldb expressions
Function calls support in LLDB expressions for RISCV: 3 of 4

This patch sets large code model in MCJIT settings for RISC-V 64-bit targets
that allows to make assembly jumps at any 64bit address. This is needed,
because resulted jitted code may contain more that +-2GB jumps, that are
not available in RISC-V with medium code model.

[lldb][RISCV] doubles support in lldb expressions
Function calls support in LLDB expressions for RISCV: 4 of 4

This patch adds desired feature flags in MCJIT compiler to enable
hard-float instructions if target supports them and allows to use floats
and doubles in lldb expressions.
2024-10-02 12:08:22 +03:00
JOE1994
a75565a684 [llvm][ExecutionEngine] Strip unneeded calls to raw_string_ostream::str() (NFC)
Avoid excess layer of indirection.
2024-09-15 03:47:13 -04:00
Alastair Houghton
bdfd780490
[RuntimeDyld][Windows] Allocate space for dllimport things. (#106958)
We weren't taking account of the space we require in the stubs for
things that are dllimported, and as a result we could hit the assertion
failure for running out of stub space. Fix that.

Also add a couple of `override` specifiers that were missing last time
(#102586).

rdar://133473673
2024-09-02 12:34:12 +01:00
Alastair Houghton
87d904871f
Revert "[RuntimeDyld][Windows] Allocate space for dllimport things." (#106954)
Looks like I missed an `override` (maybe that warning was enabled recently?). Will revert and fix.

Reverts llvm/llvm-project#102586
2024-09-02 10:27:28 +01:00
Alastair Houghton
a0a253181e
[RuntimeDyld][Windows] Allocate space for dllimport things. (#102586)
We weren't taking account of the space we require in the stubs for
things that are dllimported, and as a result we could hit the assertion
failure for running out of stub space. Fix that.

rdar://133473673

---------

Co-authored-by: Saleem Abdulrasool <compnerd@compnerd.org>
Co-authored-by: Lang Hames <lhames@gmail.com>
Co-authored-by: Ben Barham <b.n.barham@gmail.com>
2024-09-02 10:07:11 +01:00
Rahul Joshi
1753008bbb
[NFC] Eliminate top-level "using namespace" from some headers. (#102751)
- Eliminate top-level "using namespace" from some headers.
2024-08-11 13:10:48 -07:00
Kazu Hirata
f11c0a1a0d
[ExecutionEngine] Use range-based for loops (NFC) (#98110) 2024-07-10 16:11:07 +09:00
Nikita Popov
f99746f30a
[Orc][RuntimeDyld] Return after handling error (#95364)
If OnLoaded failed, return after passing the error to OnEmitted instead
of also calling finalizeAsync (which would use values that have already
been moved and perform another call to OnEmitted).
2024-07-04 11:06:48 +02:00
Alastair Houghton
fb8ea85987
[RuntimeDyld][ELF] Fix unwanted sign extension. (#94482)
Casting the result of `Section.getAddressWithOffset()` goes wrong if we
are on a 32-bit platform whose addresses are regarded as signed; in that
case, just doing
```
(uint64_t)Section.getAddressWithOffset(...)
```
or
```
reinterpret_cast<uint64_t>(Section.getAddressWithOffset(...))
```
will result in sign-extension.

We use these expressions when constructing branch stubs, which is before
we know the final load address, so we can just switch to the
`Section.getLoadAddressWithOffset(...)` method instead.

Doing that is also more consistent, since when calculating relative
offsets for relocations, we use the load address anyway, so the code
currently only works because `Section.Address` is equal to
`Section.LoadAddress` at this point.

Fixes #94478.
2024-06-06 11:32:27 +10:00
Alastair Houghton
6957c00a8c
[RuntimeDyld][ELF][AArch64] Fix resolveAArch64ShortBranch. (#92245)
We don't know the load addresses when this function is called, so it
shouldn't be trying to use them to determine whether or not the branch
is short. Notably, this will fail in the case where the code is being
loaded into a target in such a way that the section offsets differ
between the process generating the code and the target process.

rdar://127673408
2024-05-29 09:27:30 +01:00
Eymen Ünay
f29352b63b
[RuntimeDyldChecker][AArch32] Add a PC offset to next_PC for ARM targets (#91746)
In ARM mode, the Program Counter (PC) points to the current instruction's
address + 8 instead of + 4. An offset is added to RuntimeDyldChecker to
use `next_pc` expression in JITLink tests with both Thumb and Arm.
2024-05-28 14:53:37 +03:00
Kazu Hirata
bb6df0804b
[llvm] Use StringRef::operator== instead of StringRef::equals (NFC) (#91441)
I'm planning to remove StringRef::equals in favor of
StringRef::operator==.

- StringRef::operator==/!= outnumber StringRef::equals by a factor of
  70 under llvm/ in terms of their usage.

- The elimination of StringRef::equals brings StringRef closer to
  std::string_view, which has operator== but not equals.

- S == "foo" is more readable than S.equals("foo"), especially for
  !Long.Expression.equals("str") vs Long.Expression != "str".
2024-05-08 10:33:53 -07:00
Nathan Sidwell
66f0984385
Reorder fields for better packing (#77998)
The RelocationEntry's fields are poorly ordered when considering
padding. This reordering reduces the size from 56 bytes to 40 bytes (on
LP64).
2024-03-11 07:35:02 -04:00
Kazu Hirata
a37e8b85ee [ExecutionEngine] Simplify a string comparison (NFC) 2024-02-03 21:43:08 -08:00
Stefan Gränitz
6a433d77b1
[llvm-jitlink] Allow optional stub-kind filter in stub_addr() expressions (#78369)
We use `jitlink-check` lines in LIT tests as the primary tool for
testing JITLink backends. Parsing and evaluation of the expressions is
implemented in `RuntimeDyldChecker`. The `stub_addr(obj, name)`
expression allows to obtain the linker-generated stub for the external
symbol `name` in object file `obj`.

This patch adds support for a filter parameter to select one out of many
stubs. This is necessary for the AArch32 JITLink backend, which must be
able to emit two different kinds of stubs depending on the instruction
set state (Arm/Thumb) of the relocation site. Since the new parameter is
optional, we don't have to update existing tests.

Filters are regular expressions without brackets that match exactly one
existing stub. Given object file `armv7.o` with two stubs for external
function `ext` of kinds `armv7_abs_le` and `thumbv7_abs_le`, we get the
following filter results e.g.:
```
stub_addr(armv7.o, ext, thumb)        thumbv7_abs_le
stub_addr(armv7.o, ext, thumbv7)      thumbv7_abs_le
stub_addr(armv7.o, ext, armv7_abs_le) armv7_abs_le
stub_addr(armv7.o, ext, v7_.*_le)     Error: "ext" has 2 candidate stubs in file "armv7.o". Please refine stub-kind filter "v7_.*_le" for disambiguation (encountered kinds are "thumbv7_abs_le", "armv7_abs_le").
stub_addr(armv7.o, ext, v8)           Error: "ext" has 2 stubs in file "armv7.o", but none of them matches the stub-kind filter "v8" (all encountered kinds are "thumbv7_abs_le", "armv7_abs_le").
```
2024-01-20 09:57:03 +01:00
Kazu Hirata
586ecdf205
[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-11 21:01:36 -08:00
Kazu Hirata
4a0ccfa865 Use llvm::endianness::{big,little,native} (NFC)
Note that llvm::support::endianness has been renamed to
llvm::endianness while becoming an enum class as opposed to an
enum. This patch replaces support::{big,little,native} with
llvm::endianness::{big,little,native}.
2023-10-12 21:21:45 -07:00
Kazu Hirata
a9d5056862 Use llvm::endianness (NFC)
Now that llvm::support::endianness has been renamed to
llvm::endianness, we can use the shorter form.  This patch replaces
support::endianness with llvm::endianness.
2023-10-10 21:54:15 -07:00
Kazu Hirata
6480fe2bbf [llvm] Drop unaligned from calls to llvm::support::endian::{read,write} (NFC)
The last template parameter of llvm::support::endian::{read,write}
defaults to unaligned, so we can drop that at call sites.
2023-10-09 00:14:37 -07:00
Eymen Ünay
9c017a99d5 [jitlink][rtdyld][checker] Re-apply 4b17c81d5a5 with fixes.
This re-applies 4b17c81d5a5, "[jitlink/rtdydl][checker] Add TargetFlag
dependent disassembler switching support", which was reverted in
4871a9ca546 due to bot failures.

The patch has been updated to add missing plumbing for Subtarget Features and
a CPU string, which should fix the failing tests.

https://reviews.llvm.org/D158280
2023-09-09 13:10:38 -07:00
Tom Weaver
4871a9ca54 Revert "[jitlink/rtdydl][checker] Add TargetFlag dependent disassembler switching support"
This reverts commit 4b17c81d5a5d3e0f514026c2b7f9b623d901cc04.

Caused buildbot failures:
https://lab.llvm.org/buildbot/#/builders/230/builds/18341
https://lab.llvm.org/buildbot/#/builders/109/builds/73169
https://lab.llvm.org/buildbot/#/builders/67/builds/12597
2023-09-08 13:41:11 +01:00
Eymen Ünay
4b17c81d5a [jitlink/rtdydl][checker] Add TargetFlag dependent disassembler switching support
Some targets such as AArch32 make use of TargetFlags to indicate ISA mode. Depending
on the TargetFlag, MCDisassembler and similar target specific objects should be
reinitialized with the correct Target Triple. Backends with similar needs can
easily extend this implementation for their usecase.

The drivers llvm-rtdyld and llvm-jitlink have their SymbolInfo's extended to take
TargetFlag into account. RuntimeDyldChecker can now create necessary TargetInfo
to reinitialize MCDisassembler and MCInstPrinter. The required triple is obtained
from the new getTripleFromTargetFlag function by checking the TargetFlag.

In addition, breaking changes for RuntimeDyld COFF Thumb tests are fixed by making
the backend emit a TargetFlag.

Reviewed By: lhames, sgraenitz

Differential Revision: https://reviews.llvm.org/D158280
2023-09-08 09:06:15 +02:00
Fangrui Song
111fcb0df0 [llvm] Fix duplicate word typos. NFC
Those fixes were taken from https://reviews.llvm.org/D137338
2023-09-01 18:25:16 -07:00
Eymen Ünay
94239712eb Fix typos in comments of ExecutionEngine (NFC)
Reviewed By: sgraenitz

Differential Revision: https://reviews.llvm.org/D157226
2023-08-14 07:58:25 +02:00
Saleem Abdulrasool
d4a5bef170 ExecutionEngine: support IMAGE_REL_AMD64_SECTION relocations
This relocation type is often used for debug information on Windows.  We
would previously abort due to the unreachable for the unhandled
relocation type.  Add support for this to prevent LLDB from aborting if
it encounters this relocation type.
2023-07-27 12:40:42 -07:00
Elliot Goodrich
b0abd4893f [llvm] Add missing StringExtras.h includes
In preparation for removing the `#include "llvm/ADT/StringExtras.h"`
from the header to source file of `llvm/Support/Error.h`, first add in
all the missing includes that were previously included transitively
through this header.
2023-06-25 15:42:22 +01:00
Lang Hames
f81ccb5209 [ExecutionEngine] Re-enable JIT tests on PowerPC.
These were previously re-enabled in d771f54107c, but had to be disabled again
in 2060a72b4d7 due to test failures.

This is a next step to landing https://reviews.llvm.org/D148192, which adds
a skeleton JITLink backend for PowerPC.

The fixes for those failures were (1) to explicitly specify IsLittleEndian =
true for the MachO YAML testcases, (2) disable some example tests for examples
that aren't supported on PowerPC yet, and (3) fixing the endianness of a
relocation read/write (for ELF R_AARCH64_TSTBR14) in RuntimeDyldELF.
2023-05-21 16:12:06 -07:00
Fangrui Song
ed92c369e5 [RuntimeDyld][ELF] Actually fix R_AARCH64_ABS{16,32} overflow check
7b58259481417bb22d144a9c12ee8f4fb0a046e0 is incorrect.
2023-04-05 06:59:09 -07:00