851 Commits

Author SHA1 Message Date
Lang Hames
bfb0a518e7 [llvm-jitlink] Use -num-threads=0 for regression tests relying on debug output.
ORC and JITLink debugging output write the dbgs() raw_ostream, which isn't
thread-safe. Use -num-threads=0 to force single-threaded linking for tests that
produce debugging output.

The llvm-jitlink tool is updated to suggest -num-threads=0 when debugging
output is enabled.
2025-01-08 14:01:33 +11:00
Haojian Wu
e576c5bed7 Fix an incorrect -show-graph command-line flag in COFF_comdat_weak_plus_strong.s test
The flag -show-graph has been renamed to -show-graphs in 01bdd8cffcaf97636b5fb6ee4933e62c872528d3
2025-01-03 15:17:50 +01:00
Lang Hames
ad192f9f20 [ORC] Restrict check-dwarf-filename test to Darwin for now.
This test is failing on Windows (see e.g.
https://lab.llvm.org/buildbot/#/builders/146/builds/1983), probably due to
incomplete debugger support there (the test registers debug info in-process, so
non-Darwin builds shouldn't be expected to have the right symbols).
2025-01-03 20:46:55 +11:00
Lang Hames
93a68a5188 [ORC] Testcase requires asserts as it depends on debugging output. 2025-01-03 17:30:19 +11:00
Lang Hames
b6c06d1a8d [ORC] Fix bug in source file name finding in DebuggerSupportPlugin.
The debug section map was using MachO section names (with the "__" prefix), but
DWARFContext expects section names with the object format prefix stripped off.
This was preventing DWARFContext from accessing the debug_str section,
resulting in bogus source name strings.
2025-01-03 15:45:43 +11:00
ZhaoQi
8e404509cc
[JITLink][RISCV] Add feature relax for addsub tests. NFC (#121204)
R_RISCV_{ADD*/SUB*} relocations are kept only when feature relax
enabled. So it is better to add relax to the test, so that relocs can be
reserved for processing by the jitlink. That's what this test really
wants to test.
2025-01-03 09:07:44 +08:00
ZhaoQi
4c5c5e2f41
[JITLink][LoongArch] Add R_LARCH_{B16,B21} relocations support (#121096) 2025-01-02 18:09:06 +08:00
Lang Hames
096551537b "Reapply "[llvm-jitlink] Use concurrent linking by default." with more fixes.
This reapplies edca1d9bad2 which was reverted in 7ec139ad4bc due to bot
failures.

LocalDependencyPropagation.s is updated to use -num-threads=0 in order to
avoid interleaving debugging output.

ELFNixPlatform.h is updated to protect the deferred runtime function calls
map during bootstrap.
2025-01-02 15:08:21 +11:00
Lang Hames
f2d18a4d00 Reapply "[ORC] Introduce LazyReexportsManager, ... (#118923)" with fixes.
This re-applies 570ecdcf8b4, which was reverted in 74e8a37ff32 due to bot
failures. This commit renames sysv_resolve.cpp to resolve.cpp, which was the
cause of the config errors.
2024-12-09 03:22:51 +00:00
Lang Hames
74e8a37ff3 Revert "Reapply "[ORC] Introduce LazyReexportsManager, … (#118923)" with fixes"
This reverts commit 41652c6c92958a87b8505b9b1e6f008856e392ac while I investigate
more bot failures.
2024-12-09 12:38:59 +11:00
Lang Hames
41652c6c92 Reapply "[ORC] Introduce LazyReexportsManager, … (#118923)" with fixes
This reapplies 570ecdcf8b4, which was reverted in 6073dd923b8 due to bot
failures.

The test failures on Linux were fixed by:
1. Removing an overly restrictive assertion (query dependence on a symbol no
longer implies a MaterializingInfo for that symbol)
2. Adding reentry and resolver files to the ORC runtime CMakeLists.txt for
Linux.
3. Adding the __orc_rt_reentry -> __orc_rt_sysv_reentry alias to ELFNixPlatform.
2024-12-09 12:08:07 +11:00
Lang Hames
6073dd923b Revert "[ORC] Introduce LazyReexportsManager, JITLinkTrampolines, … (#118923)"
This reverts commit 570ecdcf8b44aec853ce381a5f6b77222b041afa while I investigate
bot failures, e.g. https://lab.llvm.org/buildbot/#/builders/17/builds/4446.
2024-12-07 22:15:27 +11:00
Lang Hames
570ecdcf8b
[ORC] Introduce LazyReexportsManager, JITLinkTrampolines, ORC-RT base… (#118923)
…d reentry.

These utilities provide new, more generic and easier to use support for
lazy compilation in ORC.

LazyReexportsManager is an alternative to LazyCallThroughManager. It
takes requests for lazy re-entry points in the form of an alias map:
lazy-reexports = {
  ( <entry point symbol #1>, <implementation symbol #1> ),
  ( <entry point symbol #2>, <implementation symbol #2> ),
  ...
  ( <entry point symbol #n>, <implementation symbol #n> )
}

LazyReexportsManager then:
1. binds the entry points to the implementation names in an internal
table.
2. creates a JIT re-entry trampoline for each entry point.
3. creates a redirectable symbol for each of the entry point name and
binds redirectable symbol to the corresponding reentry trampoline.

When an entry point symbol is first called at runtime (which may be on
any thread of the JIT'd program) it will re-enter the JIT via the
trampoline and trigger a lookup for the implementation symbol stored in
LazyReexportsManager's internal table. When the lookup completes the
entry point symbol will be updated (via the RedirectableSymbolManager)
to point at the implementation symbol, and execution will proceed to the
implementation symbol.

Actual construction of the re-entry trampolines and redirectable symbols
is delegated to an EmitTrampolines functor and the
RedirectableSymbolsManager respectively.

JITLinkReentryTrampolines.h provides a JITLink-based implementation of
the EmitTrampolines functor. (AArch64 only in this patch, but other
architectures will be added in the near future).

Register state save and reentry functionality is added to the ORC
runtime in the __orc_rt_sysv_resolve and __orc_rt_resolve_implementation
functions (the latter is generic, the former will need custom
implementations for each ABI and architecture to be supported, however
this should be much less effort than the existing OrcABISupport
approach, since the ORC runtime allows this code to be written as native
assembly).

The resulting system:
1. Works equally well for in-process and out-of-process JIT'd code.
2. Requires less boilerplate to set up.

Given an ObjectLinkingLayer and PlatformJD (JITDylib containing the ORC
runtime), setup is just:

```c++
auto RSMgr = JITLinkRedirectableSymbolManager::Create(OLL);
if (!RSMgr)
  return RSMgr.takeError();

auto LRMgr = createJITLinkLazyReexportsManager(OLL, **RSMgr, PlatformJD);
if (!LRMgr)
  return LRMgr.takeError();
```

after which lazy reexports can be introduced with:

```c++
JD.define(lazyReexports(LRMgr, <alias map>));
```

LazyObectLinkingLayer is updated to use this new method, but the LLVM-IR
level CompileOnDemandLayer will continue to use LazyCallThroughManager
and OrcABISupport until the new system supports a wider range of
architectures and ABIs.

The llvm-jitlink utility's -lazy option now uses the new scheme. Since
it depends on the ORC runtime, the lazy-link.ll testcase and associated
helpers are moved to the ORC runtime.
2024-12-07 21:08:39 +11:00
wanglei
ca9f358b14
[JITLink][LoongArch] Add support for R_LARCH_CALL36 relocation
This relocation is used for function calls with medium code model.

Reviewed By: lhames, SixWeining

Pull Request: https://github.com/llvm/llvm-project/pull/117127
2024-11-22 09:50:23 +08:00
Lang Hames
3f540e1a21 [JITLink] Restrict execution of MachO_ptrauth-globals.s test to arm64 hosts.
Should fix the bot failures on Darwin x86-64 machines.
2024-11-22 11:44:13 +11:00
Lang Hames
a432f11a52 [JITLink][arm64] Support arm64e JIT'd code (initially enabled for MachO only).
Adds two new JITLink passes to create and populate a pointer-signing function
that can be called via an allocation-action attached to the LinkGraph:

* createEmptyPointerSigningFunction creates a pointer signing function in a
custome section, reserving sufficient space for the signing code. It should
be run as a post-prune pass (to ensure that memory is reserved prior to
allocation).
* lowerPointer64AuthEdgesToSigningFunction pass populates the signing function
by walking the graph, decoding the ptrauth info (encoded in the edge addend) and
writing an instruction sequence to sign all ptrauth fixup locations.

rdar://61956998
2024-11-21 14:59:52 +11:00
Lang Hames
61d1b7c5ed [ORC] Tweak lazy-link testcase's UNSUPPORTED condition for armv8a some more.
The change in c0cbcb4efe8 was insufficient: The armv8a subarch is a property of
the compiled testcase, not the test target triple. Having double-checked the
EPCIndirectionUtils::Create method we want to disable this test for all arm.*
prefixes except arm64 (we want the test to continue working on Darwin).
2024-11-18 13:54:53 +11:00
Lang Hames
c0cbcb4efe [ORC] Tweak lazy-link testcase's UNSUPPORTED condition for armv8a.
The previous attempt in 6349c1c28195 didn't seem to work: the test is still
failing as of https://lab.llvm.org/buildbot/#/builders/154/builds/7609.
2024-11-18 13:19:19 +11:00
Lang Hames
6349c1c281 [ORC] Disable lazy-linking test on armv8 and powerpc.
These architectures are not supported yet.
2024-11-18 12:59:25 +11:00
Lang Hames
224290d448
[ORC] Add LazyObjectLinkingLayer, lazy-linking support to llvm-jitlink (#116002)
LazyObjectLinkingLayer can be used to add object files that will not be linked
into the executor unless some function that they define is called at runtime.
(References to data members defined by these objects will still trigger
immediate linking)

To implement lazy linking, LazyObjectLinkingLayer uses the lazyReexports
utility to construct stubs for each function in a given object file, and an
ObjectLinkingLayer::Plugin to rename the function bodies at link-time. (Data
symbols are not renamed)

The llvm-jitlink utility is extended with a -lazy option that can be
passed before input files or archives to add them using the lazy linking
layer rather than the base ObjectLinkingLayer.
2024-11-18 11:17:36 +11:00
Douglas
d822c099ee
[JITLink] Use rsplit on -sectcreate argument in llvm-jitlink (#115511)
This accounts for cases where the file path may contain an `@` symbol.
In such cases, the split occurs too early causing argument parsing to
fail.
2024-11-10 19:19:02 +11: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
Lang Hames
097718bfe2 [ORC] Enable lli -jit-kind=orc-lazy tests on aarch64. 2024-11-05 14:41:31 +11:00
Lang Hames
841227a5d9 Re-apply "Revert "[JITLink] Use MapVector to stabilize iteration.."" with fixes.
This re-applies 244ea406259, which was reverted in 0019d061854 while I
investigated a bot failure. The fix for the failure will be committed as a
follow-up.
2024-11-01 10:35:49 -07:00
Lang Hames
0019d06185 Revert "Revert "[JITLink] Use MapVector to stabilize iteration order""
This reverts commit 244ea4062590b4fbda56bbae6cd3700159db19bf while I test a fix
for a build failure: https://lab.llvm.org/buildbot/#/builders/174/builds/7685.
2024-10-31 19:18:34 -07:00
Lang Hames
fe5215281d [JITLink][COFF] Delete trailing whitespace in testcase. NFC. 2024-11-01 04:50:24 +11:00
Lang Hames
244ea40625 Revert "[JITLink] Use MapVector to stabilize iteration order"
This reverts commit f8f4235612b9668bbcbb6a58634fcb756794045e and replaces the
MapVector with a sorted vector in the debug dump: We only need to sort the
sections for debug dumping, and don't want LinkGraph API clients assuming
anything about the section iteration order.
2024-11-01 04:50:24 +11:00
Jameson Nash
5716f836d2
[JITLink] Fix i686 R_386_32 and other relocation values (#111091)
Fix R_386_32 and other relocations by correcting Addend computations.
2024-10-16 15:48:43 +11:00
Xing Guo
210140ab6a
[JITLink] Add support for R_X86_64_SIZE* relocations. (#110081)
This patch adds support for R_X86_64_SIZE32/R_X86_64_SIZE64 relocation
types by introducing edge kinds x86_64::Size32/x86_64::Size64. The
calculation for these relocations is: Z + A, where:

Z - Represents the size of the symbol whose index resides in the
    relocation entry.

A - Represents the addend used to compute the value of the relocation
    field.

Ref: [System V Application Binary Interface
x86-64](https://gitlab.com/x86-psABIs/x86-64-ABI/-/jobs/artifacts/master/raw/x86-64-ABI/abi.pdf?job=build)
2024-10-16 09:42:40 +08:00
Lang Hames
30f5a3ca15 [MCJIT][ORC] Change test guards to 'UNSUPPORTED: system-darwin'.
These tests were guarded with 'UNSUPPORTED: target={{.*}}-darwin{{.*}}', but
that check may unintentionally pass if LLVM is configured with a host triple
that specifies a specific Darwin flavor, e.g. macOS with
-DLLVM_HOST_TRIPLE:STRING=aarch64-apple-macosx13.0. All darwin flavors should
set 'system-darwin', so this is a safer feature to check.

rdar://134942819
2024-09-27 16:44:38 +10:00
Xing Guo
57bee1e432
[JITLink] Add support for R_X86_64_PC16 relocation type. (#109630)
This patch adds support for R_X86_64_PC16 relocation type and
x86_64::Delta16 edge kind. This patch also adds missing test cases for
R_X86_64_PC32, R_X86_64_PC64 relocation types.
2024-09-24 21:21:42 +08:00
Xing Guo
38666e6515
[Test][JITLink] Correctly generate the R_X86_64_PC8 relocation. (#109283)
Previously, ELF_R_X86_64_PC8.s doesn't produce the R_X86_64_PC8
relocation. This patch helps fix it by emitting a byte `main - .` to the
.rodata section.
2024-09-22 20:19:15 +08:00
Lang Hames
255870d7b5 [JITLink] Update splitBlock to support splitting into multiple blocks.
LinkGraph::splitBlock used to take a single split-point to split a Block into
two. In the common case where a block needs to be split repeatedly (e.g. in
eh-frame and compact-unwind sections), iterative calls to splitBlock could
lead to poor performance as symbols and edges are repeatedly shuffled to new
blocks.

This commit updates LinkGraph::splitBlock to take a sequence of split offsets,
allowing a block to be split into an arbitrary number of new blocks. Internally,
Symbols and Edges only need to be moved once (directly to whichever new block
they will be associated with), leading to better performance.

On some large MachO object files in an out of tree project this change improved
the performance of splitBlock by several orders of magnitude.

rdar://135820493
2024-09-22 09:52:08 +10:00
Lang Hames
224b280043 [ORC] Gate testcase for 3e1d4ec671c on x86-64 and aarch64 target support.
The testcase requires both of these targets.
2024-08-16 10:53:47 +10:00
Lang Hames
3e1d4ec671
[ORC] loadRelocatableObject: universal binary support, clearer errors (#104406)
ORC supports loading relocatable object files into a JIT'd process. The
raw "add object file" API (ObjectLayer::add) accepts plain relocatable
object files as llvm::MemoryBuffers only and does not check that the
object file's format or architecture are compatible with the process
that it will be linked in to. This API is flexible, but places the
burden of error checking and universal binary support on clients.

This commit introduces a new utility, loadRelocatableObject, that takes
a path to load and a target triple and then:
1. If the path does not exist, returns a FileError containing the
invalid path.
2. If the path points to a MachO universal binary, identifies and
returns MemoryBuffer covering the slice that matches the given triple
(checking that the slice really does contains a valid MachO relocatable
object with a compatible arch).
3. If the path points to a regular relocatable object file, verifies
that the format and architecture are compatible with the triple.

Clients can use loadRelocatableObject in the common case of loading
object files from disk to simplify their code.

Note: Error checking for ELF and COFF is left as a FIXME.

rdar://133653290
2024-08-16 09:52:36 +10:00
Vladislav Khmelevsky
199c400387
[JITLink][AArch64] Add LD64_GOTPAGE_LO15 rel support (#100854)
This relocation is used in order to address GOT entries using 15 bit
offset in ldr instruction. The offset is calculated relative to GOT
section page address.
2024-08-07 12:27:22 +04:00
Lang Hames
63e179929e [ORC] Re-add test files that were accidentally left out of e7698a13e31. 2024-07-24 16:36:05 +10:00
Lang Hames
e7698a13e3 Re-apply "[ORC][JITLink] Treat common symbols as weak definitions." with fixes.
This reapplies 785d376d123, which was reverted in c49837f5f68 due to bot
failures. The fix was to relax some asserts to allow common symbols to be
resolved with either common or weak flags, rather than requiring one or the
other.
2024-07-24 16:35:26 +10:00
Lang Hames
c49837f5f6 Revert "[ORC][JITLink] Treat common symbols as weak definitions."
This reverts commit 785d376d1231167688dd12f93c5c0a5d46cd4086 while I
investigate some bot failures (e.g.
https://lab.llvm.org/buildbot/#/builders/3/builds/1983).
2024-07-24 13:26:17 +10:00
Lang Hames
785d376d12 [ORC][JITLink] Treat common symbols as weak definitions.
Duplicate common definitions should be coaleseced, rather than being treated as
duplicate definitions. Strong definitions should override common definitions.

rdar://132314264
2024-07-24 13:12:14 +10:00
Ben Langmuir
342bd4b893
[orc] Add the name of static archives to the name of their member objects (#99407)
Changes "MyObj.o" to "/path/to/libMyLib.a(MyObj.o)".

This allows us to differentiate between objects that have the same
basename but came from different archives. It also fixes a bug where if
two such objects were both linked and both have initializer sections
their initializer symbol would cause a duplicate symbol error.

rdar://131782514
2024-07-18 08:54:43 -07:00
Connie
9ddfe62f5c
[LLVM][test][nfc] Updating test to work with internal shell (#98370)
The RUN line attempts to set the JITDUMPDIR environment variable, which
fails in llvm-lit's internal shell. This patch prefixes JITDUMPDIR with
env so that the behavior of setting the variable is as expected in the
internal shell.
2024-07-11 09:34:24 -07:00
Eymen Ünay
9efa63359e [JITLink][AArch32] Fix buildbot failure by restricting test to assert build
The expressive test added in PR #97030 requires debug option in cli.
2024-06-29 18:59:47 +03:00
Eymen Ünay
cd0f89109b
[JITLink][AArch32] Fix Unaligned Data Symbol Address Resolution (#97030)
The ARM architecture uses the LSB bit for ARM/Thumb mode switch
flagging. This is true for alignments of 2 and 4 but in data
relocations the alignment is 1 allowing the LSB bit to be set.
Now only `ELF::STT_FUNC` typed symbols are used in the 
TargetFlag mechanism.

The test is a minimal example of the issue mentioned below.

Fixes #95911 "Orc global constructor order test fails on 32
bit ARM".
2024-06-29 18:27:06 +03:00
Fangrui Song
04c27852e4
[MC,COFF] Change how we handle section symbols
13a79bbfe583e1d8cc85d241b580907260065eb8 (2017) unified `BeginSymbol` and
section symbol for ELF. This patch does the same for COFF.

* In getCOFFSection, all sections now have a `BeginSymbol` (section
  symbol). We do not need a dummy symbol name when `getBeginSymbol` is
  needed (used by AsmParser::Run and DWARF generation).
* Section symbols are in the global symbol table. `call .text` will
  reference the section symbol instead of an undefined symbol. This
  matches GNU assembler. Unlike GNU, redefining the section symbol will
  cause a "symbol 'foo0' is already defined" error (see
  `section-sym-err.s`).

Pull Request: https://github.com/llvm/llvm-project/pull/96459
2024-06-25 14:00:47 -07:00
Maksim Panchenko
ae6f730b2f
[JITLink] Add x86_64::Delta8 edge kind, ELF::R_X86_64_PC8 support (#95869)
Add support for ELF::R_X86_64_PC8 relocation via new x86_64::Delta8 edge
kind.
2024-06-18 09:31:52 -07:00
David Spickett
d97951e57a Reland "[ORC] Preserve order of constructors with same priority (#95532)"
This reverts commit edd6f0c544785d6f6276a24b94222e0064413cd1.

The newly added test uncovered a pre-existing issue on Arm 32 bit,
so as we did https://github.com/llvm/llvm-project/issues/94994, disable
it while we find the problem.
2024-06-18 12:26:32 +00:00
Jonas Hahnfeld
edd6f0c544 Revert "[ORC] Preserve order of constructors with same priority (#95532)"
The test fails on 32-bit ARMv8:
https://lab.llvm.org/buildbot/#/builders/154/builds/170

This reverts commit e5d0627c5a78f8cf4ff79816547b528ec52d6590.
2024-06-18 09:11:07 +02:00
Jonas Hahnfeld
e5d0627c5a
[ORC] Preserve order of constructors with same priority (#95532)
Constructors with the same priority should keep their relative order
that was specified. This is important for `clang-repl` with many `const`
variables after commit 05137ecfca ("[clang-repl] Emit const variables
only once").
2024-06-18 08:13:13 +02:00
Nikita Popov
deab451e7a
[IR] Remove support for icmp and fcmp constant expressions (#93038)
Remove support for the icmp and fcmp constant expressions.

This is part of:
https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179

As usual, many of the updated tests will no longer test what they were
originally intended to -- this is hard to preserve when constant
expressions get removed, and in many cases just impossible as the
existence of a specific kind of constant expression was the cause of the
issue in the first place.
2024-06-04 08:31:03 +02:00