aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-02-20[llvm-jitlink] Use '@' rather than ':' for separator in -sectcreate.Lang Hames1-2/+2
This should avoid the issue with Windows paths that have caused failures on some builders.
2024-02-20[ORC] Add SectCreateMaterializationUnit, llvm-jitlink -sectcreate option.Lang Hames1-0/+61
The SectCreateMaterializationUnit creates a LinkGraph with a single named section containing a single named block whose content is given by a MemoryBuffer. It is intended to support emulation of ld64's -sectcreate option.
2024-01-30[llvm-jitlink] Fix detectStubKind() for big endian systems (#79970)Stefan Gränitz1-4/+5
This function is used in `jitlink-check` lines in LIT tests. In #78371 I missed to swap initial instruction bytes for systems that store the constants as big-endian.
2024-01-23[JITLink][AArch32] Multi-stub support for armv7/thumbv7 (#78371)Stefan Gränitz1-1/+45
We want to emit stubs that match the instruction set state of the relocation site. This is important for branches that have no built-in switch for the instruction set state. It's the case for Jump24 relocations. Relocations on instructions that support switching on the fly will be rewritten in a relaxation step in the future. This affects Call relocations on `BL`/`BLX` instructions. In this patch, the StubManager gains a second stub symbol slot for each target and selects which one to use based on the relocation type. For testing, we select the appropriate slot with a stub-kind filter, i.e. `arm` or `thumb`. With that we can implement Armv7 stubs and test that we can have both kinds of stubs for a single external symbol.
2024-01-22[llvm-jitlink] Use SmallVectorImpl when referencing StubInfos (NFC)Nikita Popov1-2/+2
The element type is declared as SmallVector<T, 1>, but we assign to SmallVector<T> &. These types are not the same on 32-bit systems, resulting in a compilation error. Fix this by using SmallVectorImpl<T> & instead, which is independent of the small size.
2024-01-20[llvm-jitlink] Allow optional stub-kind filter in stub_addr() expressions ↵Stefan Gränitz1-9/+77
(#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-19[llvm-jitlink] Refactor GOT and stubs registration (NFC) (#78365)Stefan Gränitz1-0/+30
Add methods `registerGOTEntry()` and `registerStubEntry()` in `Session::FileInfo` to factor out generic code from the individual object type implementations.
2023-12-11[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)Kazu Hirata1-3/+3
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-06Re-apply "[llvm-jitlink] Add Process and Platform JITDylibs, ..." with fixes.Lang Hames1-64/+157
This reapplies 3d0dd1a7d6, which was reverted in df2485b215a due to bot failures. This patch addresses the issues seen on the bots by disabling two Linux atexit tests in the ORC runtime whose behavior could not be maintained now that the ORC runtime is being loaded into a separate Platform JITDylib. https://github.com/llvm/llvm-project/issues/74641 has been filed to fix the issue with atexit.
2023-12-05Revert "[llvm-jitlink] Add Process and Platform JITDylibs, generalize alias..."Lang Hames1-157/+64
This reverts commit 3d0dd1a7d62 while I investigate bot failures (e.g. https://lab.llvm.org/buildbot/#/builders/272/builds/2573)
2023-12-05[llvm-jitlink] Add Process and Platform JITDylibs, generalize alias option.Lang Hames1-64/+157
The Process JITDylib holds reflected process symbols. The Platform JITDylib holds ORC runtime symbols if the ORC runtime is loaded. The Platform and Process JITDylibs are appended to the link order of all other JITDylibs, including the main JITDylib, after any explicitly specified libraries. This scheme is similar to the one introduced in LLJIT in 371cb1af61d, and makes it easier to introduce aliases for process and platform symbols in a way that affects all JITDylibs uniformly. Since the Process and Platform JITDylibs are created implicitly the -alias option is generalized to allow source and destination JITDylibs to be explicitly specified, i.e. the -alias option now supports general re-exports. Testcases are updated to account for the change.
2023-12-02[llvm] Stop including list (NFC)Kazu Hirata1-1/+0
Identified with clangd.
2023-10-12Use llvm::endianness::{big,little,native} (NFC)Kazu Hirata1-1/+2
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-09-28Re-apply "[ORC] Add N_SO and N_OSO stabs entries to MachO debug..." with fixes.Lang Hames1-1/+1
This re-applies db51e572893, which was reverted in 05b1a2cb3e6 due to bot failures. The DebuggerSupportPlugin now depends on DWARF, so it has been moved to the new OrcDebugging library (as has the enableDebuggerSupport API).
2023-09-28[ORC] Add DWARFContext generation from LinkGraphs, use in perf support.Prem Chintalapudi1-3/+6
This patch adds line numbers to perf jitdump records emitted by the PerfSupportPlugin, by parsing and using a DWARFContext from preserved debug sections. To avoid making the OrcJIT library depend on DebugInfoDWARF this patch introduces a new OrcDebugging library. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D146391
2023-09-28[ORC] Rename MemLifetimePolicy to MemLifetime.Lang Hames1-1/+1
The *Policy suffix came from the earlier MemAllocPolicy type, where it was included to distinguish the type from a memory-allocation operation. MemLifetime is a noun already, so the *Policy suffix is just dead weight now.
2023-09-18[ORC][JITLink] Non-debuginfo JITLink perf jitdump support.Prem Chintalapudi1-4/+19
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-09[jitlink][rtdyld][checker] Re-apply 4b17c81d5a5 with fixes.Eymen Ünay1-8/+6
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-08Revert "[jitlink/rtdydl][checker] Add TargetFlag dependent disassembler ↵Tom Weaver1-6/+8
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[jitlink/rtdydl][checker] Add TargetFlag dependent disassembler switching ↵Eymen Ünay1-8/+6
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-07-24[llvm-jitlink] Don't return immediately in -noexec mode, just skip execution.Lang Hames1-4/+1
Skipping execution rather than bailing out early means that: 1. Explicit teardown of JIT'd code will happen at the same point (via the call to ExecutionSession::endSession) regardless of whether -noexec is used. 2. The -show-times option will work with -noexec.
2023-07-24[llvm-jitlink] Move statistics code into a separate file.Lang Hames1-104/+1
Further isolates statistics gathering / reporting code from the rest of llvm-jitlink.
2023-07-19[llvm-jitlink] Generalize statistics gathering / reporting.Lang Hames1-33/+100
Moves the llvm-jitlink tool statistics out of the Session struct and into a new LLVMJITLinkStatistics class. Also removes the `-show-sizes` option. Each statistic added will now have its own option. The two previous stats (total size of all blocks before pruning and after fixups) are now available as -pre-prune-total-block-size and -post-fixup-total-block-size. This change should make it easier to add new statistics.
2023-05-13[llvm-jitlink] Pass object features when creating MCSubtargetInfoJob Noorman1-11/+19
The reason for this patch is to allow the MCDisassembler used in tests to disassemble instructions that are only available when a specific feature is enabled. For example, on RISC-V it's currently not possible to use decode_operand() on a compressed instruction. This patch fixes this. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D149523
2023-05-12[llvm] Migrate {starts,ends}with_insensitive to ↵Kazu Hirata1-5/+5
{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-04-18Revert "Non-debuginfo JITLink perf jitdump support"Valentin Churavy1-19/+4
This reverts commit 76e1521b0acff739c0425d0fcbb9360fc17f1af8.
2023-04-18Non-debuginfo JITLink perf jitdump supportPrem Chintalapudi1-4/+19
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-03[Orc] Add AutoRegisterCode option for DebugObjectManagerPluginStefan Gränitz1-1/+1
Configure the plugin to automatically call the debugger rendezvous breakpoint `__jit_debug_register_code()` for every translation unit (enabled) or never at all (disabled). Default API and behavior remain unchanged. If AutoRegisterCode is turned off, it's the client's own responsibility to call the rendezvous breakpoint function at an appropriate time. Depending on the complexity of the debugger's rendezvous breakpoint implementation, this can provide significant performance improvements in cases where many debug objects are added in sequence. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D147310
2023-03-27[ORC] Move most ORC APIs to ExecutorAddr, introduce ExecutorSymbolDef.Lang Hames1-9/+9
ExecutorAddr was introduced in b8e5f918166 as an eventual replacement for JITTargetAddress. ExecutorSymbolDef is introduced in this patch as a replacement for JITEvaluatedSymbol: ExecutorSymbolDef is an (ExecutorAddr, JITSymbolFlags) pair, where JITEvaluatedSymbol was a (JITTargetAddress, JITSymbolFlags) pair. A number of APIs had already migrated from JITTargetAddress to ExecutorAddr, but many of ORC's internals were still using the older type. This patch aims to address that. Some public APIs are affected as well. If you need to migrate your APIs you can use the following operations: * ExecutorAddr::toPtr replaces jitTargetAddressToPointer and jitTargetAddressToFunction. * ExecutorAddr::fromPtr replace pointerToJITTargetAddress. * ExecutorAddr(JITTargetAddress) creates an ExecutorAddr value from a JITTargetAddress. * ExecutorAddr::getValue() creates a JITTargetAddress value from an ExecutorAddr. JITTargetAddress and JITEvaluatedSymbol will remain in JITSymbol.h for now, but the aim will be to eventually deprecate and remove these types (probably when MCJIT and RuntimeDyld are deprecated).
2023-03-24[llvm-jitlink] Remove unnecessary header include left in 01bdd8cffca.Lang Hames1-1/+0
2023-03-24[llvm-jitlink] Rename -show-graph option to -show-graphs, make it a regex.Lang Hames1-8/+17
The original -show-graph option dumped the LinkGraph for all graphs loaded into the session, but can make it difficult to see small graphs (e.g. reduced test cases) among the surrounding larger files (especially the ORC runtime). The new -show-graphs option takes a regex and dumps only those graphs matching the regex. This allows testcases to specify exactly which graphs to dump.
2023-03-20[llvm-jitlink] Fix typo in description of llvm-jitlink's -alias option.Lang Hames1-1/+2
2023-03-18Re-apply "[JITLink][ORC] Rename MemDeallocPolicy to MemLifetime..." with fixes.Lang Hames1-2/+1
This reapplies 2cc64df0bd6a802eab592dbc282463c3e4a4281c, which was reverted in 5379c46d490640bfa80283e00240b6f1006092b4 due to bot failures. The new patch contains fixes to ELFLinkGraphBuilder.h to better handle non-SHT_ALLOC sections (these were being accidentally skipped in the previous patch), and to skip SHT_NULL sections.
2023-03-17Revert "[JITLink][ORC] Rename MemDeallocPolicy to MemLifetimePolicy, add ..."Lang Hames1-1/+2
This reverts commit 2cc64df0bd6a802eab592dbc282463c3e4a4281c while I investigate bot failures (e.g. https://lab.llvm.org/buildbot/#/builders/3/builds/23081).
2023-03-17[JITLink][ORC] Rename MemDeallocPolicy to MemLifetimePolicy, add NoAlloc option.Lang Hames1-2/+1
The original MemDeallocPolicy had two options: * Standard: allocated memory lives until deallocated or abandoned. * Finalize: allocated memory lives until all finalize actions have been run, then is destroyed. This patch introduces a new 'NoAlloc' option. NoAlloc indicates that the section should be ignored by the JITLinkMemoryManager -- the memory manager should allocate neither working memory nor executor address space to blocks in NoAlloc sections. The NoAlloc option is intended to support metadata sections (e.g. debug info) that we want to keep in the graph and have fixed up if necessary, but don't want allocated or transmitted to the executor (or we want that allocation and transmission to be managed manually by plugins). Since NoAlloc blocks are ignored by the JITLinkMemoryManager they will not have working memory allocated to them by default post-allocation. Clients wishing to modify the content of a block in a NoAlloc section should call `Block::getMutableMemory(LinkGraph&)` to get writable memory allocated on the LinkGraph's allocator (this memory will exist for the lifetime of the graph). If no client requests mutable memory prior to the fixup phase then the generic link algorithm will do so when it encounters the first edge in any given block. Addresses of blocks in NoAlloc sections are initialized by the LinkGraph creator (a LinkGraphBuilder, if the graph is generated from an object file), and should not be modified by the JITLinkMemoryManager. Plugins are responsible for updating addresses if they add/remove content from these sections. The meaning of addresses in NoAlloc-sections is backend/plugin defined, but for fixup purposes they will be treated the same as addresses in Standard/Finalize sections. References from Standard/Finalize sections to NoAlloc sections are expected to be common (these represent metadata tracking executor addresses). References from NoAlloc sections to Standard/Finalize sections are expected to be rare/non-existent (they would represent JIT'd code / data tracking metadata in the controller, which would be surprising). LinkGraphBuilders and specific backends may impose additional constraints on edges between Standard/Finalize and NoAlloc sections where required for correctness. Differential Revision: https://reviews.llvm.org/D146183
2023-03-01[ORC] Drop StaticLibraryDefinitionGenerator Load/Create overloads with triples.Lang Hames1-2/+1
We can get the triple from the ExecutionSession, so clients shouldn't have to provide it.
2023-02-21[ORC] Add an ExecutionSession::getTargetTriple convenience function.Lang Hames1-15/+10
Forwards to ExecutorProcessControl::getTargetTriple, and saves clients the trouble of spelling 'getExecutorProcessControl()' everywhere.
2023-02-17[llvm-jitlink] Discard allocation actions in -noexec mode.Lang Hames1-2/+4
Allocation actions may run JIT'd code, which isn't permitted in -noexec mode. Testcases that depend on actions running should be moved to the ORC runtime.
2022-12-19[ORC] Add JITDylib argument to ResourceManager notify-removing/transferring ops.Lang Hames1-2/+2
In some cases it's helpful to group trackers by JITDylib. E.g. Platform classes may want to track initializer symbols with a `JITDylib -> Tracker -> [ Symbol ]` map. This makes it easy to collect all symbols for the JITDylib, while still allowing efficient removal of a single tracker. Passing the JITDylib as an argument to ResourceManager::notifyRemovingResources and ResourceManager::notifyTransferringResources supports such use-cases.
2022-10-03[llvm-jitlink] Teach InProcessDeltaMapper to honor -slab-page-size option.Lang Hames1-14/+31
The -slab-page-size option is used to set a simulated page size in -no-exec tests. In order for this to work we need to use read/write permissions only on all simulated pages in order to ensure that no simulated page is made read-only by a permission change to the underlying real page. The aim of this patch is to make it safe to enable ExecutionEngine regression tests on arm64. Those tests will be enabled in a follow-up patch.
2022-09-28[llvm-jitlink] Remove JITLinkSlabAllocator classAnubhab Ghosh1-244/+0
This class was used for testing JITLink with -noexec option and also included slab allocation support. Its functionality has been replaced with InProcessDeltaMapper and MapperJITLinkMemoryManager. Differential Revision: https://reviews.llvm.org/D134781
2022-09-27[llvm-jitlink] Remove stray global.Lang Hames1-1/+1
This was accidentally introduced in an earlier commit.
2022-09-12[llvm] Use x.empty() instead of llvm::empty(x) (NFC)Kazu Hirata1-4/+4
I'm planning to deprecate and eventually remove llvm::empty. I thought about replacing llvm::empty(x) with std::empty(x), but it turns out that all uses can be converted to x.empty(). That is, no use requires the ability of std::empty to accept C arrays and std::initializer_list. Differential Revision: https://reviews.llvm.org/D133677
2022-09-10[ORC][ORC_RT][COFF] Remove public bootstrap method.sunho1-9/+2
Removes public bootstrap method that is not really necessary and not consistent with other platform API. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D132780
2022-09-10[ORC][ORC_RT][COFF] Support dynamic VC runtime.sunho1-1/+3
Supports dynamic VC runtime. It implements atexits handling which is required to load msvcrt.lib successfully. (the object file containing atexit symbol somehow resolves to static vc runtim symbols) It also default to dynamic vc runtime which tends to be more robust. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D132525
2022-08-28[Orc] Use MapperJITLinkMemoryManager with SharedMemoryMapper in llvm-jitlink ↵Anubhab Ghosh1-3/+46
tool MapperJITLinkMemoryManager combined with SharedMemoryMapper can be used in place of EPCGenericJITLinkMemoryManager when running on top of same physical memory. This commit enables it when --use-shared-memory is passed. Differential Revision: https://reviews.llvm.org/D132369
2022-08-27[Orc] Use MapperJITLinkMemoryManager with InProcessMapper in llvm-jitlink toolAnubhab Ghosh1-4/+89
MapperJITLinkMemoryManager has slab allocation. Combined with InProcessMapper, it can replace InProcessMemoryManager. It can also replace JITLinkSlabAllocator through the InProcessDeltaMapper that adds an offset to the executor addresses for use in tests. Differential Revision: https://reviews.llvm.org/D132315
2022-08-13[ORC_RT][COFF] Initial platform support for COFF/x86_64.Sunho Kim1-16/+67
Initial platform support for COFF/x86_64. Completed features: * Statically linked orc runtime. * Full linking/initialization of static/dynamic vc runtimes and microsoft stl libraries. * SEH exception handling. * Full static initializers support * dlfns * JIT side symbol lookup/dispatch Things to note: * It uses vc runtime libraries found in vc toolchain installations. * Bootstrapping state is separated because when statically linking orc runtime it needs microsoft stl functions to initialize the orc runtime, but static initializers need to be ran in order to fully initialize stl libraries. * Process symbols can't be used blidnly on msvc platform; otherwise duplicate definition error gets generated. If process symbols are used, it's destined to get out-of-reach error at some point. * Atexit currently not handled -- will be handled in the follow-up patches. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D130479
2022-08-03[ORC] Ensure that llvm_orc_registerJITLoaderGDBAllocAction is linked into tools.Lang Hames1-1/+2
Add a reference to llvm_orc_registerJITLoaderGDBAllocAction from the linkComponents function in the lli, llvm-jitlink, and llvm-jitlink-executor tools. This ensures that llvm_orc_registerJITLoaderGDBAllocAction is not dead-stripped in optimized builds, which may cause failures in these tools. The llvm_orc_registerJITLoaderGDBAllocAction function was originally added with MachO debugging support in 69be352a1961a, but that patch failed to update the linkComponents functions. http://llvm.org/PR56817
2022-07-29[ORC][COFF] Handle COFF import files of static archive.Sunho Kim1-91/+138
Handles COFF import files of static archive. Changes static library genrator to build up object file map keyed by symbol name that excludes the symbols from dllimported symbols so that static generator will not be responsible for them. It exposes the list of dynamic libraries that need to be imported. Client should properly load the libraries in this list beforehand. Object file map is also an improvment from the past in terms of performance. Archive.findSym does a slow O(n) linear serach of symbol list to find the symbol. (we call findSym O(n) times, thus full time complexity is O(n^2); we were the only user of findSym function in fact) There is a room for improvements in how to load the libraries in the list. We currently just hand the responsibility over to the clinet. A better way would be let ORC read this list and hand them over to JITLink side that would also help validation (e.g. not trying to generate stub for non dllimported targets) Nevertheless, we will have to exclude the symbols from COFF import object file list and need a way to access this list, which this patch offers. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D129952