726 Commits

Author SHA1 Message Date
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
Fangrui Song
7b58259481 [RuntimeDyld][ELF] Fix off-by-1 issues in R_AARCH64_ABS{16,32} overflow checks 2023-04-05 06:52:54 -07:00
Graham Markall
2e1b838a88 [RuntimeDyld] RuntimeDyldELF: Clear GOTOffsetMap when resetting GOT section.
When the GOT section ID is reset, the GOTOffsetMap must also be cleared,
otherwise spurious matches can be located when handling GOT relocations
in subsequently-linked objects.

Fixes Issue #61402 - see https://github.com/llvm/llvm-project/issues/61402.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D146938
2023-04-03 11:37:07 -07:00
Archibald Elliott
d768bf994f [NFC][TargetParser] Replace uses of llvm/Support/Host.h
The forwarding header is left in place because of its use in
`polly/lib/External/isl/interface/extract_interface.cc`, but I have
added a GCC warning about the fact it is deprecated, because it is used
in `isl` from where it is included by Polly.
2023-02-10 09:59:46 +00:00
Moritz Sichert
cb19b83baa [RuntimeDyld][ELF] Fixed relocations referencing undefined TLS symbols
The classification of TLS symbols in ELF was changed from ST_Data to
ST_Other in the following commit:
018a484cd26d72fb4c9e7fd75e5f5bc7838dfc73

RuntimeDyldELF::processRelocationRef() needs to be updated to also
handle ST_Other symbols so that it handles TLS relocations correctly.
The current tests did not fail because we have a shortcut for global
symbols that are already defined.

Differential Revision: https://reviews.llvm.org/D143568
2023-02-08 17:49:53 +01:00
Archibald Elliott
62c7f035b4 [NFC][TargetParser] Remove llvm/ADT/Triple.h
I also ran `git clang-format` to get the headers in the right order for
the new location, which has changed the order of other headers in two
files.
2023-02-07 12:39:46 +00:00
Archibald Elliott
f09cf34d00 [Support] Move TargetParsers to new component
This is a fairly large changeset, but it can be broken into a few
pieces:
- `llvm/Support/*TargetParser*` are all moved from the LLVM Support
  component into a new LLVM Component called "TargetParser". This
  potentially enables using tablegen to maintain this information, as
  is shown in https://reviews.llvm.org/D137517. This cannot currently
  be done, as llvm-tblgen relies on LLVM's Support component.
- This also moves two files from Support which use and depend on
  information in the TargetParser:
  - `llvm/Support/Host.{h,cpp}` which contains functions for inspecting
    the current Host machine for info about it, primarily to support
    getting the host triple, but also for `-mcpu=native` support in e.g.
    Clang. This is fairly tightly intertwined with the information in
    `X86TargetParser.h`, so keeping them in the same component makes
    sense.
  - `llvm/ADT/Triple.h` and `llvm/Support/Triple.cpp`, which contains
    the target triple parser and representation. This is very intertwined
    with the Arm target parser, because the arm architecture version
    appears in canonical triples on arm platforms.
- I moved the relevant unittests to their own directory.

And so, we end up with a single component that has all the information
about the following, which to me seems like a unified component:
- Triples that LLVM Knows about
- Architecture names and CPUs that LLVM knows about
- CPU detection logic for LLVM

Given this, I have also moved `RISCVISAInfo.h` into this component, as
it seems to me to be part of that same set of functionality.

If you get link errors in your components after this patch, you likely
need to add TargetParser into LLVM_LINK_COMPONENTS in CMake.

Differential Revision: https://reviews.llvm.org/D137838
2022-12-20 11:05:50 +00:00
Guillaume Chatelet
828ce42a59 [Alignment] Use Align in SectionRef::getAlignment()
Differential Revision: https://reviews.llvm.org/D139110
2022-12-16 12:09:57 +00:00
Fangrui Song
79e3e65b26 [ExecutionEngine] llvm::Optional => std::optional 2022-12-14 10:18:08 +00:00
Moritz Sichert
a667aa4de0 [RuntimeDyld] Added support for relocation of indirect functions
In ELF, symbols of type STT_GNU_IFUNC need to be resolved by calling the
function at the symbol's address. This is implemented by adding special
stubs for all symbols of that type.

Differential Revision: https://reviews.llvm.org/D105465
2022-11-02 10:46:11 +01:00
Fangrui Song
de9d80c1c5 [llvm] LLVM_FALLTHROUGH => [[fallthrough]]. NFC
With C++17 there is no Clang pedantic warning or MSVC C5051.
2022-08-08 11:24:15 -07:00
Kazu Hirata
e20d210eef [llvm] Qualify auto (NFC)
Identified with readability-qualified-auto.
2022-08-07 23:55:27 -07:00
Nicolai Hähnle
ede600377c ManagedStatic: remove many straightforward uses in llvm
(Reapply after revert in e9ce1a588030d8d4004f5d7e443afe46245e9a92 due to
Fuchsia test failures. Removed changes in lib/ExecutionEngine/ other
than error categories, to be checked in more detail and reapplied
separately.)

Bulk remove many of the more trivial uses of ManagedStatic in the llvm
directory, either by defining a new getter function or, in many cases,
moving the static variable directly into the only function that uses it.

Differential Revision: https://reviews.llvm.org/D129120
2022-07-10 10:29:15 +02:00
Nicolai Hähnle
e9ce1a5880 Revert "ManagedStatic: remove many straightforward uses in llvm"
This reverts commit e6f1f062457c928c18a88c612f39d9e168f65a85.

Reverting due to a failure on the fuchsia-x86_64-linux buildbot.
2022-07-10 09:54:30 +02:00
Nicolai Hähnle
e6f1f06245 ManagedStatic: remove many straightforward uses in llvm
Bulk remove many of the more trivial uses of ManagedStatic in the llvm
directory, either by defining a new getter function or, in many cases,
moving the static variable directly into the only function that uses it.

Differential Revision: https://reviews.llvm.org/D129120
2022-07-10 09:15:08 +02:00
Vladislav Khmelevsky
b27d6ffe4e [RuntimeDyld] Fix R_AARCH64_TSTBR14 relocation
Wrong mask was used to get branch instruction imm value.

Differential Revision: https://reviews.llvm.org/D128740
2022-07-05 16:40:42 +03:00
Jez Ng
d4bcb45db7 [MC][re-land] Omit DWARF unwind info if compact unwind is present where eligible
This reverts commit d941d597837d9e1405086f008c9bd6a71e7263c9.

Differential Revision: https://reviews.llvm.org/D122258
2022-06-12 17:24:19 -04:00
Jez Ng
d941d59783 Revert "[MC] Omit DWARF unwind info if compact unwind is present where eligible"
This reverts commit ef501bf85d8c869248e51371f0e74bcec0e7b229.
2022-06-12 10:47:08 -04:00
Jez Ng
ef501bf85d [MC] Omit DWARF unwind info if compact unwind is present where eligible
Previously, omitting unnecessary DWARF unwinds was only done in two
cases:
* For Darwin + aarch64, if no DWARF unwind info is needed for all the
  functions in a TU, then the `__eh_frame` section would be omitted
  entirely. If any one function needed DWARF unwind, then MC would emit
  DWARF unwind entries for all the functions in the TU.
* For watchOS, MC would omit DWARF unwind on a per-function basis, as
  long as compact unwind was available for that function.

This diff makes it so that we omit DWARF unwind on a per-function basis
for Darwin + aarch64 as well. In addition, we introduce the flag
`--emit-dwarf-unwind=` which can toggle between `always`,
`no-compact-unwind` (only emit DWARF when CU cannot be emitted for a
given function), and the target platform `default`.  `no-compact-unwind`
is particularly useful for newer x86_64 platforms: we don't want to omit
DWARF unwind for x86_64 in general due to possible backwards compat
issues, but we should make it possible for people to opt into this
behavior if they are only targeting newer platforms.

**Motivation:** I'm working on adding support for `__eh_frame` to LLD,
but I'm concerned that we would suffer a perf hit. Processing compact
unwind is already expensive, and that's a simpler format than EH frames.
Given that MC currently produces one EH frame entry for every compact
unwind entry, I don't think processing them will be cheap. I tried to do
something clever on LLD's end to drop the unnecessary EH frames at parse
time, but this made the code significantly more complex. So I'm looking
at fixing this at the MC level instead.

**Addendum:** It turns out that there was a latent bug in the X86
backend when `OmitDwarfIfHaveCompactUnwind` is naively enabled, which is
not too surprising given that this combination has not been heretofore
used.

For functions that have unwind info that cannot be encoded with CU, MC
would end up dropping both the compact unwind entry (OK; existing
behavior) as well as the DWARF entries (not OK).  This diff fixes things
so that we emit the DWARF entry, as well as a CU entry with encoding
`UNWIND_X86_MODE_DWARF` -- this basically tells the unwinder to look for
the DWARF entry. I'm not 100% sure the `UNWIND_X86_MODE_DWARF` CU entry
is necessary, this was the simplest fix. ld64 seems to be able to handle
both the absence and presence of this CU entry. Ultimately ld64 (and
LLD) will synthesize `UNWIND_X86_MODE_DWARF` if it is absent, so there
is no impact to the final binary size.

Reviewed By: davide, lhames

Differential Revision: https://reviews.llvm.org/D122258
2022-06-12 10:03:56 -04:00