summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ExecutionEngine/JITLink
Commit message (Collapse)AuthorAgeFilesLines
* [JITLink][MachO] Fix common symbol size plumbing.Lang Hames2019-12-191-1/+1
| | | | This fixes the underlying bug that was exposed by 298e183e813.
* [ORC][JITLink] Add support for weak references, and improve handling of staticLang Hames2019-11-284-9/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | libraries. This patch substantially updates ORCv2's lookup API in order to support weak references, and to better support static archives. Key changes: -- Each symbol being looked for is now associated with a SymbolLookupFlags value. If the associated value is SymbolLookupFlags::RequiredSymbol then the symbol must be defined in one of the JITDylibs being searched (or be able to be generated in one of these JITDylibs via an attached definition generator) or the lookup will fail with an error. If the associated value is SymbolLookupFlags::WeaklyReferencedSymbol then the symbol is permitted to be undefined, in which case it will simply not appear in the resulting SymbolMap if the rest of the lookup succeeds. Since lookup now requires these flags for each symbol, the lookup method now takes an instance of a new SymbolLookupSet type rather than a SymbolNameSet. SymbolLookupSet is a vector-backed set of (name, flags) pairs. Clients are responsible for ensuring that the set property (i.e. unique elements) holds, though this is usually simple and SymbolLookupSet provides convenience methods to support this. -- Lookups now have an associated LookupKind value, which is either LookupKind::Static or LookupKind::DLSym. Definition generators can inspect the lookup kind when determining whether or not to generate new definitions. The StaticLibraryDefinitionGenerator is updated to only pull in new objects from the archive if the lookup kind is Static. This allows lookup to be re-used to emulate dlsym for JIT'd symbols without pulling in new objects from archives (which would not happen in a normal dlsym call). -- JITLink is updated to allow externals to be assigned weak linkage, and weak externals now use the SymbolLookupFlags::WeaklyReferencedSymbol value for lookups. Unresolved weak references will be assigned the default value of zero. Since this patch was modifying the lookup API anyway, it alo replaces all of the "MatchNonExported" boolean arguments with a "JITDylibLookupFlags" enum for readability. If a JITDylib's associated value is JITDylibLookupFlags::MatchExportedSymbolsOnly then the lookup will only match against exported (non-hidden) symbols in that JITDylib. If a JITDylib's associated value is JITDylibLookupFlags::MatchAllSymbols then the lookup will match against any symbol defined in the JITDylib.
* [JITLink] Make sure MachO/x86-64 handles 32-bit signed addends correctly.Lang Hames2019-11-271-4/+4
| | | | These need to be sign extended when loading into Edge addends.
* [cmake] Explicitly mark libraries defined in lib/ as "Component Libraries"Tom Stellard2019-11-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Most libraries are defined in the lib/ directory but there are also a few libraries defined in tools/ e.g. libLLVM, libLTO. I'm defining "Component Libraries" as libraries defined in lib/ that may be included in libLLVM.so. Explicitly marking the libraries in lib/ as component libraries allows us to remove some fragile checks that attempt to differentiate between lib/ libraries and tools/ libraires: 1. In tools/llvm-shlib, because llvm_map_components_to_libnames(LIB_NAMES "all") returned a list of all libraries defined in the whole project, there was custom code needed to filter out libraries defined in tools/, none of which should be included in libLLVM.so. This code assumed that any library defined as static was from lib/ and everything else should be excluded. With this change, llvm_map_components_to_libnames(LIB_NAMES, "all") only returns libraries that have been added to the LLVM_COMPONENT_LIBS global cmake property, so this custom filtering logic can be removed. Doing this also fixes the build with BUILD_SHARED_LIBS=ON and LLVM_BUILD_LLVM_DYLIB=ON. 2. There was some code in llvm_add_library that assumed that libraries defined in lib/ would not have LLVM_LINK_COMPONENTS or ARG_LINK_COMPONENTS set. This is only true because libraries defined lib lib/ use LLVMBuild.txt and don't set these values. This code has been fixed now to check if the library has been explicitly marked as a component library, which should now make it easier to remove LLVMBuild at some point in the future. I have tested this patch on Windows, MacOS and Linux with release builds and the following combinations of CMake options: - "" (No options) - -DLLVM_BUILD_LLVM_DYLIB=ON - -DLLVM_LINK_LLVM_DYLIB=ON - -DBUILD_SHARED_LIBS=ON - -DBUILD_SHARED_LIBS=ON -DLLVM_BUILD_LLVM_DYLIB=ON - -DBUILD_SHARED_LIBS=ON -DLLVM_LINK_LLVM_DYLIB=ON Reviewers: beanz, smeenai, compnerd, phosek Reviewed By: beanz Subscribers: wuzish, jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, mgorny, mehdi_amini, sbc100, jgravelle-google, hiraditya, aheejin, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, steven_wu, rogfer01, MartinMosbeck, brucehoult, the_o, dexonsmith, PkmX, jocewei, jsji, dang, Jim, lenary, s.egerton, pzheng, sameer.abuasal, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70179
* [JITLink] Refactor EH-frame handling to support eh-frames with existing relocs.Lang Hames2019-11-066-320/+537
| | | | | | | | | | | | | | | | | | Some targets (E.g. MachO/arm64) use relocations to fix some CFI record fields in the eh-frame section. When relocations are used the initial (pre-relocation) content of the eh-frame section can no longer be interpreted by following the eh-frame specification. This causes errors in the existing eh-frame parser. This patch moves eh-frame handling into two LinkGraph passes that are run after relocations have been parsed (but before they are applied). The first] pass breaks up blocks in the eh-frame section into per-CFI-record blocks, and the second parses blocks of (potentially multiple) CFI records and adds the appropriate edges to any CFI fields that do not have existing relocations. These passes can be run independently of one another. By handling eh-frame splitting/fixing with LinkGraph passes we can both re-use existing relocations for CFI record fields and avoid applying eh-frame fixups before parsing the section (which would complicate the linker and require extra temporary allocations of working memory).
* [JITLink] Move block ownership from LinkGraph to Section.Lang Hames2019-10-301-4/+0
| | | | This enables easy iteration over blocks in a specific section.
* [JITLink] Add a utility for splitting blocks at a given index.Lang Hames2019-10-301-0/+79
| | | | | | | | LinkGraph::splitBlock will split a block at a given index, returning a new block covering the range [ 0, index ) and modifying the original block to cover the range [ index, original-block-size ). Block addresses, content, edges and symbols will be updated as necessary. This utility will be used in upcoming improvements to JITLink's eh-frame support.
* [JITLink] Tighten section sorting criteria to fix a flaky test case.Lang Hames2019-10-281-1/+3
| | | | | | | | | | Sections may have zero size and zero-sized sections may share a start address with other zero-sized sections. For the section overlap test to function correctly zero-sized sections must be ordered before any non-zero sized ones. This should fix the intermittent failures in the test/ExecutionEngine/JITLink/X86/MachO_zero_fill_alignment.s test case that have been observed on some builders.
* [JITLink] Switch to slab allocation for InProcessMemoryManager, re-enable test.Lang Hames2019-10-151-10/+40
| | | | | | | | | | | | | | InProcessMemoryManager used to make separate memory allocation calls for each permission level (RW, RX, RO), which could lead to target-out-of-range errors if data and code were placed too far apart (this was the source of failures in the JITLink/AArch64 testcase when it was first landed). This patch updates InProcessMemoryManager to allocate a single slab which is subdivided between text and data. This should guarantee that accesses remain in-range provided that individual object files do not exceed 1Mb in size. This patch also re-enables the JITLink/AArch64 testcase. llvm-svn: 374948
* [JITLink] Fix MachO/arm64 GOTPAGEOFF encoding.Lang Hames2019-10-111-2/+5
| | | | | | | | The original implementation failed to shift the immediate down. This should fix some of the bot failures due to r374476. llvm-svn: 374499
* Fix compilation warning due to typo.Michael Liao2019-10-101-1/+1
| | | | llvm-svn: 374479
* [JITLink] Add an initial implementation of JITLink for MachO/AArch64.Lang Hames2019-10-103-0/+737
| | | | | | | | | This implementation has support for all relocation types except TLV. Compact unwind sections are not yet supported, so exceptions/unwinding will not work. llvm-svn: 374476
* [JITLink] Silence GCC warnings. NFC.Martin Storsjo2019-10-041-1/+1
| | | | | | | | Use parentheses in an expression with mixed && and ||. Differential Revision: https://reviews.llvm.org/D68447 llvm-svn: 373779
* Fix MSVC "not all control paths return a value" warning. NFCI.Simon Pilgrim2019-10-041-0/+2
| | | | llvm-svn: 373730
* Fix MSVC "result of 32-bit shift implicitly converted to 64 bits" warning. NFCI.Simon Pilgrim2019-10-041-1/+1
| | | | llvm-svn: 373729
* [JITLink] Explicitly destroy bumpptr-allocated blocks to avoid a memory leak.Lang Hames2019-10-041-0/+6
| | | | llvm-svn: 373693
* [JITLink] Fix an unused variable warning.Lang Hames2019-10-041-3/+2
| | | | llvm-svn: 373692
* [JITLink] Switch from an atom-based model to a "blocks and symbols" model.Lang Hames2019-10-0413-1223/+1396
| | | | | | | | | | | | | | | | | | | | | | | | In the Atom model the symbols, content and relocations of a relocatable object file are represented as a graph of atoms, where each Atom represents a contiguous block of content with a single name (or no name at all if the content is anonymous), and where edges between Atoms represent relocations. If more than one symbol is associated with a contiguous block of content then the content is broken into multiple atoms and layout constraints (represented by edges) are introduced to ensure that the content remains effectively contiguous. These layout constraints must be kept in mind when examining the content associated with a symbol (it may be spread over multiple atoms) or when applying certain relocation types (e.g. MachO subtractors). This patch replaces the Atom model in JITLink with a blocks-and-symbols model. The blocks-and-symbols model represents relocatable object files as bipartite graphs, with one set of nodes representing contiguous content (Blocks) and another representing named or anonymous locations (Symbols) within a Block. Relocations are represented as edges from Blocks to Symbols. This scheme removes layout constraints (simplifying handling of MachO alt-entry symbols, and hopefully ELF sections at some point in the future) and simplifies some relocation logic. llvm-svn: 373689
* [JITLink][ORC] Track eh-frame section size for registration/deregistration.Lang Hames2019-08-271-9/+23
| | | | | | | | | | | | | | | On MachO, processing of the eh-frame section should stop if the end of the __eh_frame section is reached, regardless of whether or not there is a null CFI length field at the end of the section. This patch tracks the eh-frame section size and threads it through the appropriate APIs so that processing can be terminated correctly. No testcase yet: This patch is all API plumbing (rather than modification of linked memory) which the existing infrastructure does not provide a way of testing. Committing without a testcase until I have an idea of how to write one. llvm-svn: 370074
* [JITLink] Don't under-align zero-fill sections.Lang Hames2019-08-271-26/+13
| | | | | | | If content sections have lower alignment than zero-fill sections then bump the overall segment alignment to avoid under-aligning the zero-fill sections. llvm-svn: 370072
* [llvm] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere2019-08-152-2/+2
| | | | | | | | Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. llvm-svn: 369013
* Recommit r368812 "[llvm/Object] - Convert SectionRef::getName() to return ↵George Rimar2019-08-141-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Expected<>" Changes: no changes. A fix for the clang code will be landed right on top. Original commit message: SectionRef::getName() returns std::error_code now. Returning Expected<> instead has multiple benefits. For example, it forces user to check the error returned. Also Expected<> may keep a valuable string error message, what is more useful than having a error code. (Object\invalid.test was updated to show the new messages printed.) This patch makes a change for all users to switch to Expected<> version. Note: in a few places the error returned was ignored before my changes. In such places I left them ignored. My intention was to convert the interface used, and not to improve and/or the existent users in this patch. (Though I think this is good idea for a follow-ups to revisit such places and either remove consumeError calls or comment each of them to clarify why it is OK to have them). Differential revision: https://reviews.llvm.org/D66089 llvm-svn: 368826
* Revert r368812 "[llvm/Object] - Convert SectionRef::getName() to return ↵George Rimar2019-08-141-4/+3
| | | | | | | | Expected<>" It broke clang BB: http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/16455 llvm-svn: 368813
* [llvm/Object] - Convert SectionRef::getName() to return Expected<>George Rimar2019-08-141-3/+4
| | | | | | | | | | | | | | | | | | | | | | | SectionRef::getName() returns std::error_code now. Returning Expected<> instead has multiple benefits. For example, it forces user to check the error returned. Also Expected<> may keep a valuable string error message, what is more useful than having a error code. (Object\invalid.test was updated to show the new messages printed.) This patch makes a change for all users to switch to Expected<> version. Note: in a few places the error returned was ignored before my changes. In such places I left them ignored. My intention was to convert the interface used, and not to improve and/or the existent users in this patch. (Though I think this is good idea for a follow-ups to revisit such places and either remove consumeError calls or comment each of them to clarify why it is OK to have them). Differential revision: https://reviews.llvm.org/D66089 llvm-svn: 368812
* [JITLink] Add support for MachO/x86-64 UNSIGNED relocs with length=2.Lang Hames2019-08-031-2/+22
| | | | | | | | | MachO/x86-64 UNSIGNED relocs are almost always 64-bit (length=3), but UNSIGNED relocs of length=2 are allowed if the target resides in the low 32-bits. This patch adds support for such relocations in JITLink (previously they would have triggered an unsupported relocation error). llvm-svn: 367764
* [JITLink] Fix error message formatting.Lang Hames2019-08-031-1/+1
| | | | llvm-svn: 367763
* [JITLink][ORC] Add EHFrameRegistrar interface, use in EHFrameRegistrationPlugin.Lang Hames2019-07-041-0/+9
| | | | | | | | Replaces direct calls to eh-frame registration with calls to methods on an EHFrameRegistrar instance. This allows clients to substitute a registrar that registers frames in a remote process via IPC/RPC. llvm-svn: 365098
* [JITLink] Move JITLinkMemoryManager into its own header.Lang Hames2019-06-143-90/+106
| | | | llvm-svn: 363444
* Reverted r361134 because of a failing test left unattended for a long time.Galina Kistanova2019-05-221-6/+8
| | | | | | | | http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/17792/steps/test-check-all/logs/stdio Failing Tests (1): LLVM :: CodeGen/AMDGPU/regbank-reassign.mir llvm-svn: 361430
* Disable EHFrameSupport in JITLink/RuntimeDyld on AIXXing Xue2019-05-221-1/+2
| | | | | | | | | | | | | | | | | | | Summary: EH Frames aren't supported on AIX with the system compiler, but the definition of HAVE_EHTABLE_SUPPORT misses this which causes linking problems on AIX. This patch updates the definition of HAVE_EHTABLE_SUPPORT in both JITLink and RuntimeDyld. Author: daltenty Reviewers: sfertile, xingxue, hubert.reinterpretcase Reviewed By: xingxue Subscribers: hiraditya, jsji, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62203 llvm-svn: 361410
* [Support] Renamed member 'Size' to 'AllocatedSize' in MemoryBlock and ↵Lang Hames2019-05-201-2/+3
| | | | | | | | | | | | | | | OwningMemoryBlock. Rename member 'Size' to 'AllocatedSize' in order to provide a hint that the allocated size may be different than the requested size. Comments are added to clarify this point. Updated the InMemoryBuffer in FileOutputBuffer.cpp to track the requested buffer size. Patch by Machiel van Hooren. Thanks Machiel! https://reviews.llvm.org/D61599 llvm-svn: 361195
* Use llvm::sort. NFCFangrui Song2019-05-201-8/+6
| | | | llvm-svn: 361134
* Recommit [Object] Change object::SectionRef::getContents() to return ↵Fangrui Song2019-05-161-5/+5
| | | | | | | | | | | | Expected<StringRef> r360876 didn't fix 2 call sites in clang. Expected<ArrayRef<uint8_t>> may be better but use Expected<StringRef> for now. Follow-up of D61781. llvm-svn: 360892
* Revert r360876 "[Object] Change object::SectionRef::getContents() to return ↵Hans Wennborg2019-05-161-5/+5
| | | | | | | | | | | | Expected<StringRef>" It broke the Clang build, see llvm-commits thread. > Expected<ArrayRef<uint8_t>> may be better but use Expected<StringRef> for now. > > Follow-up of D61781. llvm-svn: 360878
* [Object] Change object::SectionRef::getContents() to return Expected<StringRef>Fangrui Song2019-05-161-5/+5
| | | | | | | | Expected<ArrayRef<uint8_t>> may be better but use Expected<StringRef> for now. Follow-up of D61781. llvm-svn: 360876
* [JITLink][MachO] Use getSymbol64TableEntry for 64-bit MachO files.Lang Hames2019-05-161-1/+1
| | | | | | | Fixes a think-o. No test case: The nlist and nlist64 data structures happen to line up for this field, so there's no way to construct a failing test case. llvm-svn: 360830
* [JITLink][MachO] Honor the no-dead-strip flag on nlist entries.Lang Hames2019-05-131-1/+8
| | | | llvm-svn: 360618
* [JITLink] Track section alignment and make sure it is respected during layout.Lang Hames2019-05-134-11/+43
| | | | | | | Previously we had only honored alignments on individual atoms, but tools/runtimes may assume that the section alignment is respected too. llvm-svn: 360555
* [JITLink] Add a test for zero-filled content.Lang Hames2019-05-121-1/+1
| | | | | | | | Also updates RuntimeDyldChecker and llvm-rtdyld to support zero-fill tests by returning a content address of zero (but no error) for zero-fill atoms, and treating loads from zero as returning zero. llvm-svn: 360547
* [ORC] Make a narrowing-cast explicit to silence a compiler warning.Lang Hames2019-05-101-1/+1
| | | | llvm-svn: 360478
* [JITLink][MachO] Mark atoms in sections 'no-dead-strip' set live by default.Lang Hames2019-05-102-36/+66
| | | | | | | | If a MachO section has the no-dead-strip attribute set then its atoms should be preserved, regardless of whether they're public or referenced elsewhere in the object. llvm-svn: 360477
* [JITLink] Fixed a signedness bug when processing X86_64_RELOC_SUBTRACTOR.Lang Hames2019-05-091-2/+2
| | | | | | | | Subtractor relocation addends are signed, so we need to read them via signed int pointers. Accidentally treating 32-bit addends as unsigned leads to out-of-range errors when we try to add very large (>INT32_MAX) bogus addends. llvm-svn: 360392
* [ORC] Simplify logic for updating edges when should-discard atoms are pruned.Lang Hames2019-05-091-16/+4
| | | | llvm-svn: 360384
* [JITLink] Improve/fix some JITLink debugging output.Lang Hames2019-05-092-9/+11
| | | | | | | | Adds full edge details (rather than just edge targets) when out-of-range errors are generated. Also fixes a bug where debugging output accessed an invalidated DenseMap iterator by moving the debugging output above the invalidation point. llvm-svn: 360383
* [Support] Add error handling to sys::Process::getPageSize().Lang Hames2019-05-081-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch changes the return type of sys::Process::getPageSize to Expected<unsigned> to account for the fact that the underlying syscalls used to obtain the page size may fail (see below). For clients who use the page size as an optimization only this patch adds a new method, getPageSizeEstimate, which calls through to getPageSize but discards any error returned and substitues a "reasonable" page size estimate estimate instead. All existing LLVM clients are updated to call getPageSizeEstimate rather than getPageSize. On Unix, sys::Process::getPageSize is implemented in terms of getpagesize or sysconf, depending on which macros are set. The sysconf call is documented to return -1 on failure. On Darwin getpagesize is implemented in terms of sysconf and may also fail (though the manpage documentation does not mention this). These failures have been observed in practice when highly restrictive sandbox permissions have been applied. Without this patch, the result is that getPageSize returns -1, which wreaks havoc on any subsequent code that was assuming a sane page size value. <rdar://problem/41654857> Reviewers: dblaikie, echristo Subscribers: kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59107 llvm-svn: 360221
* Reapply r360194 "[JITLink] Add support for MachO .alt_entry atoms." with fixes.Lang Hames2019-05-074-29/+128
| | | | | | | | | This patch modifies MachOAtomGraphBuilder to use setLayoutNext rather than addEdge, and fixes a bug in the section layout algorithm that could result in atoms appearing more than once in the section ordering (which resulted in those atoms being assigned invalid addresses during layout). llvm-svn: 360205
* Revert r360194 "[JITLink] Add support for MachO .alt_entry atoms."Lang Hames2019-05-073-110/+11
| | | | | | The testcase is asserting on some bots - reverting while I investigate. llvm-svn: 360200
* [JITLink] Add support for MachO .alt_entry atoms.Lang Hames2019-05-073-11/+110
| | | | | | | | | | | | | | | | The MachO .alt_entry directive is applied to a symbol to indicate that it is locked (in terms of address layout and liveness) to its predecessor atom. I.e. it is an alternate entry point, at a fixed offset, for the previous atom. This patch updates MachOAtomGraphBuilder to check for the .alt_entry flag on symbols and add a corresponding LayoutNext edge to the atom-graph. It also updates MachOAtomGraphBuilder_x86_64 to generalize handling of the X86_64_RELOC_SUBTRACTOR relocation: previously either the minuend or subtrahend of the subtraction had to be the same as the atom being fixed up, now it is only necessary for the minuend or subtrahend to be locked (via any chain of alt_entry directives) to the atom being fixed up. llvm-svn: 360194
* [JITLink] Add two useful Section operations: find by name, get address range.Lang Hames2019-05-041-9/+2
| | | | | | | | These operations were already used in eh-frame registration, and are likely to be used in other runtime registrations, so this commit moves them into a header where they can be re-used. llvm-svn: 359950
* [JITLink] Make sure we explicitly deallocate memory on failure.Lang Hames2019-05-012-4/+11
| | | | | | | | | | | | JITLinkGeneric phases 2 and 3 (focused on applying fixups and finalizing memory, respectively) may fail for various reasons. If this happens, we need to explicitly de-allocate the memory allocated in phase 1 (explicitly, because deallocation may also fail and so is implemented as a method returning error). No testcase yet: I am still trying to decide on the right way to test totally platform agnostic code like this. llvm-svn: 359643
OpenPOWER on IntegriCloud