1120 Commits

Author SHA1 Message Date
Lang Hames
05b1a2cb3e Revert "[ORC] Add N_SO and N_OSO stabs entries to MachO debug objects."
This reverts commit db51e572893e9e4403d65920dc5e87a8885b059c.

Reverted while I investigate build failures, e.g.
https://lab.llvm.org/buildbot/#/builders/234/builds/12900
2023-09-22 11:03:35 -07:00
Lang Hames
db51e57289 [ORC] Add N_SO and N_OSO stabs entries to MachO debug objects.
No testcase: This code generates an in-memory object file that is shared with
the debugger. The object file is malformed in ways that don't matter to the
debugger, but mean that it can't be inspected by most tools.
2023-09-22 10:56:40 -07:00
Sunho Kim
209c242845 [ORC] Add writePointers to ExecutorProcessControl's MemoryAccess
Add pointer write functionality to MemoryAccess that is needed for implementing redirection manager. It also refactors the code a bit by introducing InProcessMemoryAccess class.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D157378
2023-09-20 03:49:08 +09:00
Jie Fu
54a38c9c9c [ORC] Fix -Wunused-but-set-variable in JITLoaderPerf.cpp (NFC)
/data/llvm-project/llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderPerf.cpp:118:10: error: variable 'Written' set but not used [-Werror,-Wunused-but-set-variable]
  size_t Written = 0;
         ^
1 error generated.
2023-09-18 13:06:16 +08:00
Prem Chintalapudi
88e3358f33 [ORC][JITLink] Non-debuginfo JITLink perf jitdump support.
This patch ports PerfJITEventListener to a JITLink plugin, but adds unwind
record support and drops debuginfo support temporarily. Debuginfo can be
enabled in the future by providing a way to obtain a DWARFContext from a
LinkGraph.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D146169
2023-09-18 04:10:29 +00:00
Kai Luo
7d9039e11d [JITLink][PowerPC][RFC] Make JITLink default in LLJIT for ppc64 elfv2abi
JITLink for ppc64 has implemented all relocations implemented in rtdyld for ppc64 and has passed all existed lit tests and unittests in llvm/clang/compiler-rt. I propose making JITLink for ppc64 default in LLJIT.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D159175
2023-09-18 02:18:23 +00:00
Arthur Eubanks
0a1aa6cda2
[NFC][CodeGen] Change CodeGenOpt::Level/CodeGenFileType into enum classes (#66295)
This will make it easy for callers to see issues with and fix up calls
to createTargetMachine after a future change to the params of
TargetMachine.

This matches other nearby enums.

For downstream users, this should be a fairly straightforward
replacement,
e.g. s/CodeGenOpt::Aggressive/CodeGenOptLevel::Aggressive
or s/CGFT_/CodeGenFileType::
2023-09-14 14:10:14 -07:00
Lang Hames
5293109774 Re-apply 75c487602a "[ORC] Add a MachOBuilder utility, use it to..." with fixes.
This re-applies 75c487602a8 ([ORC] Add a MachOBuilder utility, use it to build
MachO debug objects), which was reverted in 99e70cc3a5 due to build
failures. The MachoBuilder class has been refactored to fix the errors.
2023-09-11 10:56:54 -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
Lang Hames
99e70cc3a5 Revert "[ORC] Add a MachOBuilder utility, use it to build MachO debug objects."
This reverts commit 75c487602a8af130ec0aedf398e318cb57063f2d while I
investigate some build failures, e.g.
https://lab.llvm.org/buildbot/#/builders/217/builds/27769
2023-09-07 10:40:56 -07:00
Lang Hames
75c487602a [ORC] Add a MachOBuilder utility, use it to build MachO debug objects.
Adds a utility for creating MachO objects. In this patch we use this utility to
construct "debug objects" for the debugger support plugin; however, this utility
should be reusable for other purposes, e.g. constructing object files for
registration with the ObjC runtime.

The debug objects in this patch are created by the MachO JIT debugging-support
plugin. The debug objects hold the debug info for object files loaded under the
JIT, and are registered with the debugger via the GDB-JIT interface. Previously
the plugin created these objects manually using direct writes to a buffer, but
this was difficult to read and modify and had become an impediment to improving
debugger support (e.g. getting source debugging working in the presence of
dead-stripping). Using the MachOBuilder utility should make the debugger
support plugin easier to maintain and improve.

This initial change to MachO JIT'd code debugging aims for feature parity with
the existing plugin (though the debug objects produced are slightly different).
Improvements to JIT'd code debugging will be tackled in follow-up patches.
2023-09-07 10:34:57 -07:00
Lang Hames
36465e34e8 [ORC] Fix missing std::move.
Should fix error in https://lab.llvm.org/buildbot/#/builders/84/builds/41540.
2023-08-23 14:31:42 -07:00
Lang Hames
122ebe3b50 [ORC] Use EPC bootstrap symbols to communicate eh-frame registration fn addrs.
By using bootstrap symbols to communicate these addresseses, rather than dlsym
lookups, we no longer need them to be exported from the main executable. On ELF,
where symbols aren't exported from the main executable by default, this
eliminates a common source of missing symbol errors and allows for smaller
executables (if exports from the main executable aren't otherwise needed and
can be removed).
2023-08-23 14:19:12 -07:00
Lang Hames
8211050cb5 [LLJIT] Generalize LLJITBuilder::ProcessSymbolsJITDylibSetupFunction.
For many interesting process-symbols setups we need access to the LLJIT instance
(e.g. to mangle symbols, or inspect the process triple). This patch updates the
ProcessSymbolsJITDylibSetupFunction to take an LLJIT reference and return the
process symbols JITDylib, which the callback must now create.
2023-08-22 19:15:28 -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
Sunho Kim
5c98617ccc [JITLink] Add public APIs for getting stub creation functions.
Creating stubs in JITLink require creating architecture-specific edges. In order to allow user to create stubs in cross-architecture manner, this patch exposes these stub creations functions by returning "stub creators" for given triple.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D155557
2023-08-05 09:49:30 +09:00
Kai Luo
5cb2a78ac2 [Orc][PowerPC] Enable ELFNixPlatform support for ppc64le
Since jitlink for ppc64le is ready for general use, test cases in compiler-rt for ELFNixPlatform support can be enabled.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D156399
2023-08-02 02:20:59 +00:00
Lang Hames
e0b3f45d87 [ORC] Automatically suspend and resume lookups that depend on in-use generators.
Access to individual DefinitionGenerators is serialized in order to make
generators easier to implement: serializing access means that tryToGenerate
methods don't have to handle concurrent, potentially overlapping, requests.

Prior to this patch serialization was achieved by having each lookup acquire a
lock on each generator, however this causes the lookup thread to block if the
generator is in use. In the common case where many objects reference some
common library symbol that is provided by a generator this may cause many
threads to block concurrently preventing progress on other work.

This patch changes the model so that lookups are automatically suspended if
they need to use a generator that is already in use, and then automatically
resumed once the generator is free. This is achieved by reusing the lookup
suspension machinery that was introduced in 069919c9ba3 for optionally
asynchronous generators.
2023-07-31 12:17:17 -07:00
Lang Hames
144236a455 [ORC] Remove stray debugging output accidentally committed in 7bd481d9afc. 2023-07-30 15:21:32 -07:00
Lang Hames
7bd481d9af [ORC] Add ExecutionSession::removeJITDylibs (plural), use it in endSession.
The ExecutionSession::removeJITDylibs operation will remove all JITDylibs in
the given list (i.e. first clear them, then remove them from the session).

ExecutionSession::endSession is updated to remove JITDylibs rather than just
clearing them. This prevents new code from being added to any JITDylib once
endSession has been called.
2023-07-30 08:51:42 -07:00
Jeff Niu
e76ac8074f [llvm][orc] Consider other ELF init sections as well
ELF object files can contain `.ctors` and `.dtors` sections that also
participate as initializers.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D154802
2023-07-26 13:44:41 -07:00
Fangrui Song
8bba3f0edb [ORC] Stabilize output stream order
It currently depends on the StringMap iteration order, which is not
guaranteed to be deterministic. Use MapVector to stabilize the order.
2023-07-22 09:52:14 -07:00
Lang Hames
199034e8ac [ORC] In defineMaterializing, error out early if tracker is defunct.
An in-flight materialization may try to claim responsibility for new symbols
(via MaterializationResponsibility::defineMaterializing) after the tracker that
is associated with the materialization is removed, leaving the tracker defunct.

Failure to error out early here could leave the JITDylib in an invalid state,
with defineMaterializing associating new symbols with the already-defunct
tracker. Erroring out early prevents this.
2023-07-16 17:37:56 -07:00
Lang Hames
1126cffe06 [ORC] Assert that ExecutionSession is still open when JITDylibs are created. 2023-07-16 16:37:09 -07:00
Jon Roelofs
0dcc78a1a6
ORC: drop a FIXME that was addressed in dc078e6eaacf. NFC 2023-07-14 13:48:42 -07:00
Lang Hames
4db6c717c4 [ORC] Switch from strncpy to memcpy to silence more GCC warnings.
GCC warns when strncpy doesn't copy the null terminator. See discussion at
https://reviews.llvm.org/rG9d701c8a8d65.
2023-07-14 10:51:13 -07:00
Lang Hames
59715e7ff3 Switch to strncpy to silence GCC stringop overflow warnings.
Thanks to Simon Pilgrim for letting me know about these in
https://reviews.llvm.org/rG9d701c8a8d65.
2023-07-13 11:16:54 -07:00
Lang Hames
93ff2110e5 [ORC][AArch64] Guard against negative offsets in writeIndirectStubsBlock.
In OrcAArch64::writeIndirectStubsBlock, masks the high bits of the immediate
operand to the stub's ldr instruction so that negative offsets to the stub
pointer do not overflow.

No testcase -- this fixes most of the OrcLazy testcases for AArch64 (at least on
Darwin), but we still need to fix the exception-handling test before we can turn
them on.
2023-07-06 17:59:21 -07:00
Kazu Hirata
8876220948 [ExecutionEngine] Remove unused functions
This patch removes:

  cloneModuleFlagsMetadata
  moveFunctionBody
  moveGlobalVariableInitializer

Their last uses were removed by:

  commit 6154c4115cd4b78d0171892aac21e340e72e32bd
  Author: Lang Hames <lhames@gmail.com>
  Date:   Mon Sep 7 21:21:28 2020 -0700

Differential Revision: https://reviews.llvm.org/D152668
2023-06-13 00:24:38 -07:00
Kazu Hirata
6c3ea866e9 [llvm] Migrate {starts,ends}with_insensitive to {starts,ends}_with_insensitive (NFC)
This patch migrates uses of StringRef::{starts,ends}with_insensitive
to StringRef::{starts,ends}_with_insensitive so that we can use names
similar to those used in std::string_view.  I'm planning to deprecate
StringRef::{starts,ends}with_insensitive once the migration is
complete across the code base.

Differential Revision: https://reviews.llvm.org/D150426
2023-05-12 15:37:37 -07:00
Lang Hames
81cb43f44d [ORC][MachOPlatform] Don't add InitSectionSymbols for __objc_imageinfo.
The __objc_imageinfo section may be deleted (leaving dangling references to any
symbols that it contains), and shouldn't have any dependencies anyway. This
patch verifies that the section has no dependencies and then skips the section.

rdar://108469243
2023-05-05 00:52:03 -07:00
Fangrui Song
0d333bf0e3 Remove ExplicitEmulatedTLS and simplify -femulated-tls handling
Currently clangDriver passes -femulated-tls and -fno-emulated-tls to cc1.
cc1 forwards the option to LLVMCodeGen and ExplicitEmulatedTLS is used
to decide the value. Simplify this by moving the Clang decision to
clangDriver and moving the LLVM decision to InitTargetOptionsFromCodeGenFlags.
2023-04-23 11:55:12 -07:00
Lang Hames
b92839c954 Re-apply "[ORC][LLJIT] Use JITLink by default on ELF/x86-64." with fixes.
This reapplies 85c649bc02a, which was reverted in 35767e43d62 due to failures
with some example programs. The fix was to add export_executable_symbols to the
example programs.
2023-04-23 10:20:09 +00:00
Nikita Popov
35767e43d6 Revert "[ORC][LLJIT] Use JITLink by default on ELF/x86-64."
This reverts commit 85c649bc02a6605f541b09b33a200a78275ed90f.

Has been causing test failures in OrcV2Examples for the past few
days.
2023-04-20 14:22:08 +02:00
NAKAMURA Takumi
a2d1611b7b [CMake] Reduce deps 2023-04-20 08:45:38 +09:00
Valentin Churavy
c2114bd8e1
Revert "Non-debuginfo JITLink perf jitdump support"
This reverts commit 76e1521b0acff739c0425d0fcbb9360fc17f1af8.
2023-04-18 18:21:48 -04:00
Prem Chintalapudi
76e1521b0a
Non-debuginfo JITLink perf jitdump support
This patch ports PerfJITEventListener to a JITLink plugin, but adds unwind record support and drops debuginfo support temporarily. Debuginfo can be enabled in the future by providing a way to obtain a DWARFContext from a LinkGraph.

See D146060 for an experimental implementation that adds debuginfo parsing.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D146169
2023-04-18 17:15:59 -04:00
Lang Hames
85c649bc02 [ORC][LLJIT] Use JITLink by default on ELF/x86-64.
This patch switches LLJIT's default JIT linker for ELF/x86-64 from RuntimeDyld
to JITLink.

Most clients should not be affected, but if you were explicitly accessing the
old RTDyldObjectLinkingLayer (e.g. to install JITEventListeners) you will need
to either force use of RuntimeDyld (following the example in
llvm/examples/OrcV2Examples/LLJITWithCustomObjectLinkingLayer), or switch to
using JITLink plugins instead.
2023-04-17 16:41:00 +00:00
Lang Hames
21b5ebd245 [ORC][LLJIT] Add LLJITBuilder convenience function to enable debugger support.
Clients can now call LLJITBuilder::setEnableDebuggerSupport to enable
registration of debug info via the GDB-JIT registration protocol for JIT'd
code.

Calling LLJITBuilder::setEnableDebuggerSupport(true) will cause LLJITBuilder to
add either a DebugObjectManagerPlugin (if the object format on the triple is
ELF), or a GDBJITDebugInfoRegistrationPlugin (if the object format on the
triple is MachO). At present there is no support for debugging when using COFF.

This debugger registration support will only work when JITLink is used as the
underlying JIT linker.

This patch only addresses registration of JIT'd code by the JIT. To debug JIT'd
code you may also need to enable JIT'd code debugging in your debugger. E.g.
when debugging MachO JIT'd code under LLDB you will currently need to run
(lldb) set set plugin.jit-loader.gdb.enable on
to tell LLDB to listen for JIT'd code registration.
2023-04-16 12:23:33 -07:00
Lang Hames
9d701c8a8d [ORC] Fix fallout from switch to _objc_map/load_images-based registration.
In f448d44663a we switched to calling _objc_map_images and _objc_load_images
for MachO language metadata registration. This patch fixes some bugs arising
from that change:

(1) __objc_imageinfo processing was moved to a post-allocation pass, but this
    prevents us from discarding the redundant copies. This commit moves
    processing back to a pre-prune pass and inserts a symbol for the uniqued
    __objc_image section. Runtime objects use an edge pointing to this symbol
    to access the address.

(2) We were assuming that _objc_map_images & _objc_load_images were available
    in the Objective-C runtime on 10.15, but these functions didn't become
    available until later. This commit bumps the macOS version requirement to
    13.1 where the functions should be available.

(3) The ORC-RT trivial-swift-types-section.S test was missing an
    __objc_unwindinfo section, which triggered an assert that should have
    been an error. The assert has been turned into an error, and the testcase
    has been updated to include an __objc_imageinfo.

rdar://107846455
2023-04-11 16:48:26 -07:00
Owen Shepherd
0beeadf203 [ORC] Link atomic on platforms without hardware support for atomics.
Fixes error about missing reference to __atomic_fetch_add_8 when linking
LLVMOrcJit on ARMv6.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D147937
2023-04-11 04:15:21 +00:00
Lang Hames
2c7f511877 [ORC][MachO] Remove unused variables. 2023-04-08 16:48:13 -07:00
Lang Hames
376e90fdb4 [ORC] Fix reference to struct member in f448d44663a.
A map value was converted from a tuple to a struct during development, but I
missed a use in an assert.
2023-04-08 16:11:14 -07:00
Lang Hames
f448d44663 [ORC][ORC-RT][MachO] Use _objc_(map|load)_images for ObjC & Swift registration.
This patch drops the individual registration calls to the ObjC and Swift
runtimes (for selectors, classes, etc.), and instead creates a Mach header and
load commands that can be passed to _objc_map_images and _objc_load_images to
trigger registration and execution of +load methods. This approach supports
categories (for which there is no current registration API), and more closely
follows dyld's ObjC & Swift registration path.
2023-04-08 15:54:02 -07:00
Lang Hames
e3d2b584aa [ORC][LLJIT] Improve debugging output, tighten assertion.
Clients can provide an ExecutionSession or an ExecutorProcessControl object to
LLJITBuilder, but should not provide both.
2023-04-08 13:02:56 -07:00
Lang Hames
231107a8b5 Re-apply "[ORC] LLJIT updates: ExecutorNativePlatform, default ..." with fixes.
This reapplies 371cb1af61d, which was reverted in 0b2240eda01 due to bot
failures.

The clang-repl test failure is fixed by dropping the process symbols definition
generator that was manually attached to the main JITDylib, since LLJIT now
exposes process symbols by default. (The bug was triggered when JIT'd code used
the process atexit provided by the generator, rather than the JIT atexit which
has been moved into the platform JITDylib).

Any LLJIT clients that see crashes in static destructors should likewise remove
any process symbol generators attached to their main JITDylib.
2023-04-08 02:40:58 +00:00
Lang Hames
0b2240eda0 Revert "[ORC] LLJIT updates: ExecutorNativePlatform, default link order, ..."
This reverts commit 371cb1af61d668234a242b34c773c146cb9077e7, which broke some
unit tests (see e.g. https://lab.llvm.org/buildbot#builders/139/builds/38754).
2023-04-07 05:32:21 +00:00
Lang Hames
371cb1af61 [ORC] LLJIT updates: ExecutorNativePlatform, default link order, Process JD.
This commit includes several related ergonomic improvements to LLJIT.

(1) Adds a default JITDylibSearchOrder to be appended to the initial link order
of JITDylibs created via LLJIT::createJITDylib (dropping any duplicate entries).

This was introduced to support automatic reflection of process symbols (see
(2) below), but has been made visible to clients as it's generically useful,
e.g. if clients have some extra set of libraries that they want to be visible
to JIT'd code by default.

The default JITDylibSearchOrder is only appended to the link order of JITDylibs
created via LLJIT::createJITDylib, and will not be apply to JITDylibs created by
directly calling the underlying ExecutionSession -- in that case clients can set
up the link order manually.

(2) Makes process symbols visible to JIT'd code by default via the new "Process"
JITDylib, which is added to the default link order.

LLJIT clients usually want symbols in the executor process to be accessible to
JIT'd code. Until now clients have been left to set this up themselves by adding
a DynamicLibrarySearchGenerator to the Main JITDylib. This patch adds a new
process symbols JITDylib that will be created by default (with an
EPCDynamicLibrarySearchGenerator attached) and added to the default link order,
making process symbols available to JIT'd code.

Clients who do not want process symbols to be visible to JIT'd code by default
can call setLinkProcessSymbolsByDefault(false) on their LLJITBuilder to disable
this:

LLJITBuilder()
  ...
  .setLinkProcessSymbolsByDefault(false)
  ...
  .create();

Clients can also call setProcessSymbolsJITDylibSetup to take over responsibility
for configuring the process symbols JITDylib (the callback that the client
supplies will be called on the bare process symbols JITDylib immediately after
it is created).

If setLinkProcessSymbolsByDefault(false) is called and no JITDylib setup
callback has been set then the process symbols JITDylib will not be created and
LLJIT::getProcessSymbolsJITDylib will return null.

(3) Adds an ExecutorNativePlatform utility that makes it easier to enable
native platform features.

Some object format features (e.g. native static initializers and thread locals)
require runtime support in the executing process. Support for these features in
ORC is implemented cooperatively between the ORC runtime and the LLVM Platform
subclasses (COFFPlatform, ELFNixPlatform, and MachOPlatform).
ExecutorNativePlatfrom simplifies the process of loading the ORC runtime and
creating the appropriate platform class for the executor process.

ExecutorNativePlatform takes a path to the ORC runtime (or a MemoryBuffer
containing the runtime) and other required runtimes for the executor platform
(e.g. MSVC on Windows) and then configures LLJIT with an appropriate platform
class based on the executor's target triple:

LLJITBuilder()
  .setPlatformSetUp(ExecutorNativePlatform("/path/to/orc-runtime.a"));

(The ORC runtime is built as part of compiler-rt, and the exact name of the
archive is platform dependent).

The ORC runtime and platform symbols will be added to a new "Platform" JITDylib,
which will be added to the *front* of the default link order (so JIT'd code will
prefer symbol definitions in the platform/runtime to definitions in the executor
process).

ExecutorNativePlatform assumes that the Process JITDylib is available, as
the ORC runtime may depend on symbols provided by the executor process.

Differential Revision: https://reviews.llvm.org/D144276
2023-04-07 04:44:51 +00:00