aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ExecutionEngine
AgeCommit message (Collapse)AuthorFilesLines
2021-08-19Avoid unused variable when NDEBUGFrederik Gossen1-0/+2
2021-08-19[JITLink] Optimize GOTPCRELX Relocationsluxufan2-30/+75
This patch optimize the GOTPCRELX Reloations, which is described in X86-64 psabi chapter B.2. And Not all optimization of this chapter is implemented. 1. Convert call and jmp has been implemented 2. Convert mov, but the optimization that when the symbol is defined in the lower 32-bit address space, memory operand in `mov` can be convertted into immediate operand has not been implemented. 3. Conver Test and Binop has not been implemented. The new test file named ELF_got_plt_optimizations.s has been added, and I moved some test cases about optimization of got/plt from ELF_x86_64_small_pic_relocations.s to the new test file. By referencing the lld, so, the optimization `Convert call and jmp` is not same as what psabi says, and I have explained it in the comment. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D108280
2021-08-18Revert "[ORC-RT][ORC] Introduce ELF/*nix Platform and runtime support."Lang Hames4-785/+3
This reverts commit e256445bfff12013c3c4ad97da4aa69d25b175b5. This commit broke some of the bots (see e.g. https://lab.llvm.org/buildbot/#/builders/112/builds/8599). Reverting while I investigate.
2021-08-18[JILink][ELF] Include binding and visibility values in error messages.Lang Hames1-4/+8
This should make it easier to track down JITLink errors for unrecognized binding or visibility types, e.g. https://lab.llvm.org/buildbot#builders/112/builds/8599.
2021-08-18[ORC-RT][ORC] Introduce ELF/*nix Platform and runtime support.Lang Hames4-3/+785
This change adds support to ORCv2 and the Orc runtime library for static initializers, C++ static destructors, and exception handler registration for ELF-based platforms, at present Linux and FreeBSD on x86_64. It is based on the MachO platform and runtime support introduced in bb5f97e3ad1. Patch by Peter Housel. Thanks very much Peter! Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D108081
2021-08-17[NFC] Cleanup more AttributeList::addAttribute()Arthur Eubanks1-2/+1
2021-08-15[ExecutionEngine] Check for libunwind before calling __register_frameHarald van Dijk2-13/+19
libgcc and libunwind have different flavours of __register_frame. Both flavours are already correctly handled, except that the code to handle the libunwind flavour is guarded by __APPLE__. This change uses the presence of __unw_add_dynamic_fde in libunwind instead to detect whether libunwind is used, rather than hardcoding it as Apple vs. non-Apple. Fixes PR44074. Thanks to Albert Jin <albert.jin@gmail.com> and Chris Schafmeister <chris.schaf@verizon.net> for identifying the problem. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D106129
2021-08-15[JITLink] Unify x86-64 MachO and ELF 's optimize GOT/Stub functionluxufan3-153/+94
This patch unify optimizeELF_x86_64_GOTAndStubs and optimizeMachO_x86_64_GOTAndStubs into a pure optimize_x86_64_GOTAndStubs Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D108025
2021-08-14[JITLink][x86-64] Rename *Relaxable edges to *REXRelaxable.Lang Hames4-23/+26
The existing relaxable edges all assume a REX prefix. ELF includes non-REX relaxations, so rename these edges to make room for the new kinds.
2021-08-14[JITLink][x86-64] Rename BranchPCRel32ToPtrJumpStub(Relaxable -> Bypassable).Lang Hames3-10/+9
ELF allows for branch optimizations other than bypass, so rename this edge kind to avoid any confusion.
2021-08-13[JITLink] Update ELF_x86_64 's edge kind to generic edge kindluxufan3-136/+84
This patch uses a switch statement to map the ELF_x86_64's edge kind to generic edge kind, and merge the ELF_x86_64 's applyFixup function to the x86_64 's applyFixup function. Some edge kinds were not have corresponding generic edge kinds, so I added three generic edge kinds asa follows: 1. RequestGOTAndTransformToDelta64, which is similar to RequestGOTAndTransformToDelta32. 2. GOTDelta64. This generic kind is similar to Delta64, except the GOTDelta64 computes the delta relative to GOTSymbol 3. RequestGOTAndTransformToGOTDelta64. This edge kind was used to deal with ELF_x86_64's GOT64 edge kind, it request the fixGOTEdge function to change the target to GOT entry, and set the edge kind to generic edge kind GOTDelta64. These added generic edge kinds may named haphazardly, or can't express its meaning well. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D107967
2021-08-11[llvm][clang][NFC] updates inline licence infoChristopher Di Bella6-24/+18
Some files still contained the old University of Illinois Open Source Licence header. This patch replaces that with the Apache 2 with LLVM Exception licence. Differential Revision: https://reviews.llvm.org/D107528
2021-08-03[RuntimeDyldChecker] Delete comparision of integers of different signsluxufan1-2/+0
2021-08-03[RuntimeDyldChecker] Support offset in decode_operand exprluxufan1-5/+29
In RISCV's relocations, some relocations are comprised of two relocation types. For example, R_RISCV_PCREL_HI20 and R_RISCV_PCREL_LO12_I compose a PC relative relocation. In general the compiler will set a label in the position of R_RISCV_PCREL_HI20. So, to test the R_RISCV_PCREL_LO12_I relocation, we need decode instruction at position of the label points to R_RISCV_PCREL_HI20 plus 4 (the size of a riscv non-compress instruction). Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D105528
2021-07-30[JITLink][ELF][x86-64] Include relocation name in missing relocation errors.Lang Hames1-2/+14
This saves a level of manual table lookup for those of us who don't remember ELF relocation numbers off the top of our heads.
2021-07-27[ORC] Require ExecutorProcessControl when constructing an ExecutionSession.Lang Hames9-108/+160
Wrapper function call and dispatch handler helpers are moved to ExecutionSession, and existing EPC-based tools are re-written to take an ExecutionSession argument instead. Requiring an ExecutorProcessControl instance simplifies existing EPC based utilities (which only need to take an ES now), and should encourage more utilities to use the EPC interface. It also simplifies process termination, since the session can automatically call ExecutorProcessControl::disconnect (previously this had to be done manually, and carefully ordered with the rest of JIT tear-down to work correctly).
2021-07-26[ORC][ORC-RT] Add initial Objective-C and Swift support to MachOPlatform.Lang Hames2-17/+136
This allows ORC to execute code containing Objective-C and Swift classes and methods (provided that the language runtime is loaded into the executor).
2021-07-24Re-re-re-apply "[ORC][ORC-RT] Add initial native-TLV support to MachOPlatform."Lang Hames2-9/+122
The ccache builders have recevied a config update that should eliminate the build issues seen previously.
2021-07-23[JITLink] Add riscv.cppluxufan1-0/+44
2021-07-23[JITLink][RISCV] Initial Support RISCV64 in JITLinkluxufan3-0/+324
This patch is the initial support, it implements translation from object file to JIT link graph, and very few relocations were supported. Currently, the test file ELF_pc_indirect.s is passed, the HelloWorld program(compiled with mno-relax flag) can be linked correctly and run on instruction emulator correctly. In the downstream implementation, I have implemented the GOT, PLT function, and EHFrame and some optimization will be implement soon. I will organize the code in to patches, then gradually send it to upstream. Differential Revision: https://reviews.llvm.org/D105429
2021-07-23[ORC] Work around AIX build compiler: Replace lambda; NFCHubert Tong1-8/+19
By replacing a lambda expression with a functor class instance, this patch works around an issue encountered on AIX where the IBM XL compiler appears to make no progress for many hours. Reviewed By: jsji Differential Revision: https://reviews.llvm.org/D106554
2021-07-22Re-re-revert "[ORC][ORC-RT] Add initial native-TLV support to MachOPlatform."Lang Hames2-122/+9
This reverts commit 6b2a96285b9bbe92d2c5e21830f21458f8be976d. The ccache builders are still failing. Looks like they need to be updated to get the llvm-zorg config change in 490633945677656ba75d42ff1ca9d4a400b7b243. I'll re-apply this as soon as the builders are updated.
2021-07-22Re-re-apply "[ORC][ORC-RT] Add initial native-TLV support to MachOPlatform."Lang Hames2-9/+122
This reapplies commit a7733e9556b5a6334c910f88bcd037e84e17e3fc ("Re-apply [ORC][ORC-RT] Add initial native-TLV support to MachOPlatform."), and d4abdefc998a1ee19d5edc79ec233774cbf64f6a ("[ORC-RT] Rename macho_tlv.x86-64.s to macho_tlv.x86-64.S (uppercase suffix)"). These patches were reverted in 48aa82cacbff10e1c5395a03f86488bf449ba4da while I investigated bot failures (e.g. https://lab.llvm.org/buildbot/#/builders/109/builds/18981). The fix was to disable building of the ORC runtime on buliders using ccache (which is the same fix used for other compiler-rt projects containing assembly code). This fix was commited to llvm-zorg in 490633945677656ba75d42ff1ca9d4a400b7b243.
2021-07-21[ORC][ORC-RT] Revert MachO TLV patches while I investigate more bot failures.Lang Hames2-122/+9
This reverts commit d4abdefc998a1ee19d5edc79ec233774cbf64f6a ("[ORC-RT] Rename macho_tlv.x86-64.s to macho_tlv.x86-64.S (uppercase suffix)", and a7733e9556b5a6334c910f88bcd037e84e17e3fc ("Re-apply "[ORC][ORC-RT] Add initial native-TLV support to MachOPlatform."), while I investigate failures on ccache builders (e.g. https://lab.llvm.org/buildbot/#/builders/109/builds/18981)
2021-07-21Re-apply "[ORC][ORC-RT] Add initial native-TLV support to MachOPlatform."Lang Hames2-9/+122
Reapplies fe1fa43f16beac1506a2e73a9f7b3c81179744eb, which was reverted in 6d8c63946cc259c0af02584b7cc690dde11dea35, with fixes: 1. Remove .subsections_via_symbols directive from macho_tlv.x86-64.s (it's not needed here anyway). 2. Return error from pthread_key_create to the MachOPlatform to silence unused variable warning.
2021-07-21Revert "[ORC][ORC-RT] Add initial native-TLV support to MachOPlatform."Lang Hames2-122/+9
Reverts commit fe1fa43f16beac1506a2e73a9f7b3c81179744eb while I investigate failures on Linux.
2021-07-21[ORC][ORC-RT] Add initial native-TLV support to MachOPlatform.Lang Hames2-9/+122
Adds code to LLVM (MachOPlatform) and the ORC runtime to support native MachO thread local variables. Adding new TLVs to a JITDylib at runtime is supported. On the LLVM side MachOPlatform is updated to: 1. Identify thread local variables in the LinkGraph and lower them to GOT accesses to data in the __thread_data or __thread_bss sections. 2. Merge and report the address range of __thread_data and thread_bss sections to the runtime. On the ORC runtime a MachOTLVManager class introduced which records the address range of thread data/bss sections, and creates thread-local instances from the initial data on demand. An orc-runtime specific tlv_get_addr implementation is included which saves all register state then calls the MachOTLVManager to get the address of the requested variable for the current thread.
2021-07-21[JITLink][MachO] Detect MachO::S_THREAD_LOCAL_ZEROFILL sections as zero-fill.Lang Hames2-10/+17
This will be used in upcoming MachO native TLV support patches to LLVM and the ORC runtime.
2021-07-21[JITLink] Add support for moving blocks and symbols between sections.Lang Hames1-1/+4
LinkGraph::transferBlock can be used to move a block and all associated symbols from one section to another. LinkGraph::mergeSections moves all blocks and sections from a source section to a destination section.
2021-07-19[ORC] Explicitly convert to ArrayRefs to silence errors.Lang Hames1-2/+3
This aims to fix build failures like https://lab.llvm.org/buildbot#builders/165/builds/3761.
2021-07-19[ORC][ORC-RT] Introduce ORC-runtime based MachO-Platform.Lang Hames3-238/+673
Adds support for MachO static initializers/deinitializers and eh-frame registration via the ORC runtime. This commit introduces cooperative support code into the ORC runtime and ORC LLVM libraries (especially the MachOPlatform class) to support macho runtime features for JIT'd code. This commit introduces support for static initializers, static destructors (via cxa_atexit interposition), and eh-frame registration. Near-future commits will add support for MachO native thread-local variables, and language runtime registration (e.g. for Objective-C and Swift). The llvm-jitlink tool is updated to use the ORC runtime where available, and regression tests for the new MachOPlatform support are added to compiler-rt. Notable changes on the ORC runtime side: 1. The new macho_platform.h / macho_platform.cpp files contain the bulk of the runtime-side support. This includes eh-frame registration; jit versions of dlopen, dlsym, and dlclose; a cxa_atexit interpose to record static destructors, and an '__orc_rt_macho_run_program' function that defines running a JIT'd MachO program in terms of the jit- dlopen/dlsym/dlclose functions. 2. Replaces JITTargetAddress (and casting operations) with ExecutorAddress (copied from LLVM) to improve type-safety of address management. 3. Adds serialization support for ExecutorAddress and unordered_map types to the runtime-side Simple Packed Serialization code. 4. Adds orc-runtime regression tests to ensure that static initializers and cxa-atexit interposes work as expected. Notable changes on the LLVM side: 1. The MachOPlatform class is updated to: 1.1. Load the ORC runtime into the ExecutionSession. 1.2. Set up standard aliases for macho-specific runtime functions. E.g. ___cxa_atexit -> ___orc_rt_macho_cxa_atexit. 1.3. Install the MachOPlatformPlugin to scrape LinkGraphs for information needed to support MachO features (e.g. eh-frames, mod-inits), and communicate this information to the runtime. 1.4. Provide entry-points that the runtime can call to request initializers, perform symbol lookup, and request deinitialiers (the latter is implemented as an empty placeholder as macho object deinits are rarely used). 1.5. Create a MachO header object for each JITDylib (defining the __mh_header and __dso_handle symbols). 2. The llvm-jitlink tool (and llvm-jitlink-executor) are updated to use the runtime when available. 3. A `lookupInitSymbolsAsync` method is added to the Platform base class. This can be used to issue an async lookup for initializer symbols. The existing `lookupInitSymbols` method is retained (the GenericIRPlatform code is still using it), but is deprecated and will be removed soon. 4. JIT-dispatch support code is added to ExecutorProcessControl. The JIT-dispatch system allows handlers in the JIT process to be associated with 'tag' symbols in the executor, and allows the executor to make remote procedure calls back to the JIT process (via __orc_rt_jit_dispatch) using those tags. The primary use case is ORC runtime code that needs to call bakc to handlers in orc::Platform subclasses. E.g. __orc_rt_macho_jit_dlopen calling back to MachOPlatform::rt_getInitializers using __orc_rt_macho_get_initializers_tag. (The system is generic however, and could be used by non-runtime code). The new ExecutorProcessControl::JITDispatchInfo struct provides the address (in the executor) of the jit-dispatch function and a jit-dispatch context object, and implementations of the dispatch function are added to SelfExecutorProcessControl and OrcRPCExecutorProcessControl. 5. OrcRPCTPCServer is updated to support JIT-dispatch calls over ORC-RPC. 6. Serialization support for StringMap is added to the LLVM-side Simple Packed Serialization code. 7. A JITLink::allocateBuffer operation is introduced to allocate writable memory attached to the graph. This is used by the MachO header synthesis code, and will be generically useful for other clients who want to create new graph content from scratch.
2021-07-18Reland [Orc] Add verylazy example for C-bindingsValentin Churavy1-7/+191
This patch relands https://reviews.llvm.org/D104799, but fixes the memory handling causing leak sanitizer failures. This reverts commit a56fe117e04f7d4b953a4226af412dad59425fb5.
2021-07-18Revert "[Orc] Add verylazy example for C-bindings"Valentin Churavy1-191/+7
Broke ASAN buildbot, will reland with fixes This reverts commit b5a6ad8c893a642bcb08ab81b251952c545405d9.
2021-07-18[Orc] Remove unnecessary <string> include dependency from Orc headers. NFC.Simon Pilgrim3-4/+3
At most these use the StringRef/Twine wrappers and don't have any implicit uses of std::string. Move the include down to any cpp implementation where std::string is actually used.
2021-07-18[Orc] Add verylazy example for C-bindingsValentin Churavy1-7/+191
Still WIP, based on the Kaleidoscope/BuildingAJIT/Chapter4. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D104799
2021-07-17[ORC] Remove LLVM-side MachO Platform runtime support.Lang Hames2-535/+0
Support for this functionality is moving to the ORC runtime.
2021-07-10[ORC] Flesh out ExecutorAddress, rename CommonOrcRuntimeTypes header.Lang Hames1-33/+34
Renames CommonOrcRuntimeTypes.h to ExecutorAddress.h and moves ExecutorAddress into the 'orc' namespace (rather than orc::shared). Also makes ExecutorAddress a class, adds an ExecutorAddrDiff type and some arithmetic operations on the pair (subtracting two addresses yields an addrdiff, adding an addrdiff and an address yields an address).
2021-07-08[ORC] Improve computeLocalDeps / computeNamedSymbolDependencies performance.Lang Hames2-130/+167
The computeNamedSymbolDependencies and computeLocalDeps methods on ObjectLinkingLayerJITLinkContext are responsible for computing, for each symbol in the current MaterializationResponsibility, the set of non-locally-scoped symbols that are depended on. To calculate this we have to consider the effect of chains of dependence through locally scoped symbols in the LinkGraph. E.g. .text .globl foo foo: callq bar ## foo depneds on external 'bar' movq Ltmp1(%rip), %rcx ## foo depends on locally scoped 'Ltmp1' addl (%rcx), %eax retq .data Ltmp1: .quad x ## Ltmp1 depends on external 'x' In this example symbol 'foo' depends directly on 'bar', and indirectly on 'x' via 'Ltmp1', which is locally scoped. Performance of the existing implementations appears to have been mediocre: Based on flame graphs posted by @drmeister (in #jit on the LLVM discord server) the computeLocalDeps function was taking up a substantial amount of time when starting up Clasp (https://github.com/clasp-developers/clasp). This commit attempts to address the performance problems in three ways: 1. Using jitlink::Blocks instead of jitlink::Symbols as the nodes of the dependencies-introduced-by-locally-scoped-symbols graph. Using either Blocks or Symbols as nodes provides the same information, but since there may be more than one locally scoped symbol per block the block-based version of the dependence graph should always be a subgraph of the Symbol-based version, and so faster to operate on. 2. Improved worklist management. The older version of computeLocalDeps used a fixed worklist containing all nodes, and iterated over this list propagating dependencies until no further changes were required. The worklist was not sorted into a useful order before the loop started. The new version uses a variable work-stack, visiting nodes in DFS order and only adding nodes when there is meaningful work to do on them. Compared to the old version the new version avoids revisiting nodes which haven't changed, and I suspect it converges more quickly (due to the DFS ordering). 3. Laziness and caching. Mappings of... jitlink::Symbol* -> Interned Name (as SymbolStringPtr) jitlink::Block* -> Immediate dependencies (as SymbolNameSet) jitlink::Block* -> Transitive dependencies (as SymbolNameSet) are all built lazily and cached while running computeNamedSymbolDependencies. According to @drmeister these changes reduced Clasp startup time in his test setup (averaged over a handful of starts) from 4.8 to 2.8 seconds (with ORC/JITLink linking ~11,000 object files in that time), which seems like enough to justify switching to the new algorithm in the absence of any other perf numbers.
2021-07-08[ORC] Replace MachOJITDylibInitializers::SectionExtent with ExecutorAddressRangeLang Hames1-30/+41
MachOJITDylibInitializers::SectionExtent represented the address range of a section as an (address, size) pair. The new ExecutorAddressRange type generalizes this to an address range (for any object, not necessarily a section) represented as a (start-address, end-address) pair. The aim is to express more of ORC (and the ORC runtime) in terms of simple types that can be serialized/deserialized via SPS. This will simplify SPS-based RPC involving arguments/return-values of these types.
2021-07-02[ORC] Rename SPSTargetAddress to SPSExecutorAddress.Lang Hames3-5/+5
Also removes SPSTagTargetAddress, which was accidentally introduced at some point (and never used).
2021-07-01[Orc] At CBindings for LazyRexportsValentin Churavy1-1/+52
At C bindings and an example for LLJIT with lazy reexports Differential Revision: https://reviews.llvm.org/D104672
2021-07-01[ORC] Add wrapper-function support methods to ExecutorProcessControl.Lang Hames1-8/+57
Adds support for both synchronous and asynchronous calls to wrapper functions using SPS (Simple Packed Serialization). Also adds support for wrapping functions on the JIT side in SPS-based wrappers that can be called from the executor. These new methods simplify calls between the JIT and Executor, and will be used in upcoming ORC runtime patches to enable communication between ORC and the runtime.
2021-07-01[ORC] Rename TargetProcessControl to ExecutorProcessControl. NFC.Lang Hames7-140/+140
This is a first step towards consistently using the term 'executor' for the process that executes JIT'd code. I've opted for 'executor' as the preferred term over 'target' as target is already heavily overloaded ("the target machine for the executor" is much clearer than "the target machine for the target").
2021-06-30[Orc] Fix name of LLVMOrcIRTransformLayerSetTransformValentin Churavy1-1/+1
In https://reviews.llvm.org/D103855 we added access to IRTransformLayer, but I just noticed that the function name is following the wrong pattern. Differential Revision: https://reviews.llvm.org/D104840
2021-06-29[perf] Fix a data race in the PerfJITEventListenerEugene Zhulenev1-0/+3
Concurrent JIT compilation + PerfJITEventListener triggers tsan error Reviewed By: cota Differential Revision: https://reviews.llvm.org/D104977
2021-06-29[JITLink][ELF] Move ELF section and symbol parsing into ELFLinkGraphBuilder.Lang Hames3-367/+399
Move architecture independent ELF parsing/graph-building code from ELFLinkGraphBuilder_x86_64 to the ELFLinkGraphBuilder base class template.
2021-06-26[JITLink][ELF] Add generic ELFLinkGraphBuilder template.Lang Hames4-7/+84
ELFLinkGraphBuilder<ELFT> will hold generic parsing and LinkGraph-building code that can be shared between JITLink ELF backends for different architectures. For now it's just a stub. The plan is to incrementally move functionality down from ELFLinkGraphBuilder_x86_64 into the new template.
2021-06-19[ORC][C-bindings] Add access to LLJIT IRTransformLayer, ThreadSafeModule utils.Lang Hames1-0/+30
This patch was derived from Valentin Churavy's work in https://reviews.llvm.org/D104480. It adds support for setting the transform on an IRTransformLayer, and for accessing the IRTransformLayer in LLJIT. It also adds access to the ThreadSafeModule::withModuleDo method for thread-safe access to modules. A new example has been added to show how to use these APIs to optimize a module during materialization. Thanks Valentin! Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D103855
2021-06-18[ORC][C-bindings] Re-order object transform function arguments.Lang Hames1-1/+1
ObjInOut is an in-out parameter not a return value argument, so by convention it should come after the context value (Ctx).
2021-06-18[ORC] Add support for dumping objects to the C API.Lang Hames1-0/+47
Provides ObjectTransformLayer APIs, a getter to access the ObjectTransformLayer member of LLJIT, and the DumpObjects utility to make construction of a dump-to-disk transform easy. An example showing how the new APIs can be used has been added in llvm/examples/OrcV2Examples/OrcV2CBindingsDumpObjects.