summaryrefslogtreecommitdiff
path: root/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
Commit message (Collapse)AuthorAge
* [RuntimeDyld, PowerPC] Fix/improve handling of TOC relocationsUlrich Weigand2014-06-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Current PPC64 RuntimeDyld code to handle TOC relocations has two problems: - With recent linkers, in addition to the relocations that implicitly refer to the TOC base (R_PPC64_TOC*), you can now also use the .TOC. magic symbol with any other relocation to refer to the TOC base explicitly. This isn't currently used much in ELFv1 code (although it could be), but it is essential in ELFv2 code. - In a complex JIT environment with multiple modules, each module may have its own .toc section, and TOC relocations in one module must refer to *its own* TOC section. The current findPPC64TOC implementation does not correctly implement this; in fact, it will always return the address of the first TOC section it finds anywhere. (Note that at the time findPPC64TOC is called, we don't even *know* which module the relocation originally resided in, so it is not even possible to fix this routine as-is.) This commit fixes both problems by handling TOC relocations earlier, in processRelocationRef. To do this, I've removed the findPPC64TOC routine and replaced it by a new routine findPPC64TOCSection, which works analogously to findOPDEntrySection in scanning the sections of the ObjImage provided by its caller, processRelocationRef. This solves the issue of finding the correct TOC section associated with the current module. This makes it straightforward to implement both R_PPC64_TOC relocations, and relocations explicitly refering to the .TOC. symbol, directly in processRelocationRef. There is now a new problem in implementing the R_PPC64_TOC16* relocations, because those can now in theory involve *three* different sections: the relocation may be applied in section A, refer explicitly to a symbol in section B, and refer implicitly to the TOC section C. The final processing of the relocation thus may only happen after all three of these sections have been assigned final addresses. There is currently no obvious means to implement this in its general form with the common-code RuntimeDyld infrastructure. Fortunately, ppc64 code usually makes no use of this most general form; in fact, TOC16 relocations are only ever generated by LLVM for symbols residing themselves in the TOC, which means "section B" == "section C" in the above terminology. This special case can easily be handled with the current infrastructure, and that is what this patch does. [ Unhandled cases result in an explicit error, unlike the current code which silently returns the wrong TOC base address ... ] This patch makes the JIT work on both BE and LE (ELFv2 requires additional patches, of course), and allowed me to successfully run complex JIT scenarios (via mesa/llvmpipe). Reviewed by Hal Finkel. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211885 91177308-0d34-0410-b5e6-96231b3b80d8
* Pass a unique_ptr<MemoryBuffer> to the constructors in the Binary hierarchy.Rafael Espindola2014-06-24
| | | | | | | Once the objects are constructed, they own the buffer. Passing a unique_ptr makes that clear. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211595 91177308-0d34-0410-b5e6-96231b3b80d8
* [RuntimeDyld] Fix ppc64 stub relocations on little-endianUlrich Weigand2014-06-20
| | | | | | | | | | | | | | | | | When RuntimeDyldELF creates stub functions, it needs to install relocations that will resolve to the final address of the target routine. Since those are 16-bit relocs, they need to be applied to the least-significant halfword of the instruction. On big-endian ppc64, this means that addresses have to be adjusted by 2, which is what the code currently does. However, on a little-endian system, the address must *not* be adjusted; the least-significant halfword is the first one. This patch updates the RuntimeDyldELF code to take the target byte order into account. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211384 91177308-0d34-0410-b5e6-96231b3b80d8
* [RuntimeDyld] Support more PPC64 relocationsUlrich Weigand2014-06-20
| | | | | | | | | | | | This adds support for several missing PPC64 relocations in the straight-forward manner to RuntimeDyldELF.cpp. Note that this actually fixes a failure of a large-model test case on PowerPC, allowing the XFAIL to be removed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211382 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove 'using std::errro_code' from lib.Rafael Espindola2014-06-13
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210871 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove all uses of 'using std::error_code' from headers.Rafael Espindola2014-06-13
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210866 91177308-0d34-0410-b5e6-96231b3b80d8
* [RuntimeDyld] Add support for MachO __jump_table and __pointers sections, andLang Hames2014-05-12
| | | | | | | | | | | | | SECTDIFF relocations on 32-bit x86. This fixes several of the MCJIT regression test failures that show up on 32-bit builds. <rdar://problem/16886294> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208635 91177308-0d34-0410-b5e6-96231b3b80d8
* [ARM64] Try and make the ELF MCJIT *slightly* less broken for ARM64.James Molloy2014-04-30
| | | | | | | | | A bunch of switch cases were missing, not just for ARM64 but also for AArch64_BE. I've fixed all those, but there's zero testing as ExecutionEngine tests are disabled when crosscompiling and I don't have a native platform available to test on. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207626 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix the build with MSVC 2013 by explicitly requesting llvm::make_uniqueReid Kleckner2014-04-29
| | | | | | | MSVC 2013 provides std::make_unique, which it finds with ADL when one of the parameters is std::unique_ptr, leading to an ambiguous overload. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207597 91177308-0d34-0410-b5e6-96231b3b80d8
* PR19553: Memory leak in RuntimeDyldELF::createObjectImageFromFileDavid Blaikie2014-04-29
| | | | | | | | | | | | | | | | This starts in MCJIT::getSymbolAddress where the unique_ptr<object::Binary> is release()d and (after a cast) passed to a single caller, MCJIT::addObjectFile. addObjectFile calls RuntimeDyld::loadObject. RuntimeDld::loadObject calls RuntimeDyldELF::createObjectFromFile And the pointer is never owned at this point. I say this point, because the alternative codepath, RuntimeDyldMachO::createObjectFile certainly does take ownership, so this seemed like a good hint that this was a/the right place to take ownership. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207580 91177308-0d34-0410-b5e6-96231b3b80d8
* [C++] Use 'nullptr'.Craig Topper2014-04-24
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207083 91177308-0d34-0410-b5e6-96231b3b80d8
* [Modules] Fix potential ODR violations by sinking the DEBUG_TYPEChandler Carruth2014-04-22
| | | | | | | definition below all the header #include lines. This updates most of the miscellaneous other lib/... directories. A few left though. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206845 91177308-0d34-0410-b5e6-96231b3b80d8
* Add ARM big endian Target (armeb, thumbeb)Christian Pirker2014-03-28
| | | | | | | | Reviewed at http://llvm-reviews.chandlerc.com/D3095 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205007 91177308-0d34-0410-b5e6-96231b3b80d8
* AArch64_BE Elf support for MC-JIT runtime dynamic linkerChristian Pirker2014-03-26
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204816 91177308-0d34-0410-b5e6-96231b3b80d8
* [RuntimeDyld] clang-format files.Juergen Ributzka2014-03-21
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204507 91177308-0d34-0410-b5e6-96231b3b80d8
* [RuntimeDyld] Allow processRelocationRef to process more than one relocation ↵Juergen Ributzka2014-03-21
| | | | | | | | | | | | | entry at a time. Some targets require more than one relocation entry to perform a relocation. This change allows processRelocationRef to process more than one relocation entry at a time by passing the relocation iterator itself instead of just the relocation entry. Related to <rdar://problem/16199095> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204439 91177308-0d34-0410-b5e6-96231b3b80d8
* [ppc64] Patch in TOC restore code after all external function callsUlrich Weigand2014-03-11
| | | | | | | | | | | | | | | | | | When resolving a function call to an external routine, the dynamic loader must patch the "nop" after the branch instruction to a load that restores the TOC register. Current code does that, but only with the *first* instance of a call to any particular external routine, i.e. at the point where it also allocates the call stub. With subsequent calls to the same routine, current code neglects to patch in the TOC restore code. This is a bug, and leads to corrupt TOC pointers in those cases. Fixed by patching in restore code every time. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203580 91177308-0d34-0410-b5e6-96231b3b80d8
* [C++11] Add 'override' keyword to virtual methods that override their base ↵Craig Topper2014-03-08
| | | | | | class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203344 91177308-0d34-0410-b5e6-96231b3b80d8
* Replace OwningPtr<T> with std::unique_ptr<T>.Ahmed Charles2014-03-06
| | | | | | | | | | This compiles with no changes to clang/lld/lldb with MSVC and includes overloads to various functions which are used by those projects and llvm which have OwningPtr's as parameters. This should allow out of tree projects some time to move. There are also no changes to libs/Target, which should help out of tree targets have time to move, if necessary. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203083 91177308-0d34-0410-b5e6-96231b3b80d8
* Consistently check 'IsCode' when allocating sections in RuntimeDyld (viaLang Hames2014-02-18
| | | | | | | | | | | | | | | | findOrEmitSection). Vaidas Gasiunas's patch, r201259, fixed one instance where we were always allocating sections as text. This patch fixes the remaining buggy call sites. No test case: This isn't breaking anything that I know of, it's just inconsistent. <rdar://problem/15943542> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201605 91177308-0d34-0410-b5e6-96231b3b80d8
* [AArch64] Add missing PCRel relocations for AArch64 in RuntimeDyldELFBradley Smith2014-02-11
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201149 91177308-0d34-0410-b5e6-96231b3b80d8
* Change the begin and end methods in ObjectFile to match the style guide.Rafael Espindola2014-02-10
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201108 91177308-0d34-0410-b5e6-96231b3b80d8
* Simplify the handling of iterators in ObjectFile.Rafael Espindola2014-01-30
| | | | | | | | | | | | None of the object file formats reported error on iterator increment. In retrospect, that is not too surprising: no object format stores symbols or sections in a linked list or other structure that requires chasing pointers. As a consequence, all error checking can be done on begin() and end(). This reduces the text segment of bin/llvm-readobj in my machine from 521233 to 518526 bytes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200442 91177308-0d34-0410-b5e6-96231b3b80d8
* Enable EHABI by defaultRenato Golin2014-01-29
| | | | | | | | | | | | | | | | | | | | | | After all hard work to implement the EHABI and with the test-suite passing, it's time to turn it on by default and allow users to disable it as a work-around while we fix the eventual bugs that show up. This commit also remove the -arm-enable-ehabi-descriptors, since we want the tables to be printed every time the EHABI is turned on for non-Darwin ARM targets. Although MCJIT EHABI is not working yet (needs linking with the right libraries), this commit also fixes some relocations on MCJIT regarding the EH tables/lib calls, and update some tests to avoid using EH tables when none are needed. The EH tests in the test-suite that were previously disabled on ARM now pass with these changes, so a follow-up commit on the test-suite will re-enable them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200388 91177308-0d34-0410-b5e6-96231b3b80d8
* Re-apply r196639: Add support for archives and object file caching under MCJIT.Lang Hames2014-01-08
| | | | | | | | | | I believe the bot failures on linux systems were due to overestimating the alignment of object-files within archives, which are only guaranteed to be two-byte aligned. I have reduced the alignment in RuntimeDyldELF::createObjectImageFromFile accordingly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198737 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r196639 while I investigate a bot failure.Lang Hames2013-12-07
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196641 91177308-0d34-0410-b5e6-96231b3b80d8
* Add support for archives and object file caching under MCJIT.Lang Hames2013-12-07
| | | | | | | | Patch by Andy Kaylor, with minor edits to resolve merge conflicts. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196639 91177308-0d34-0410-b5e6-96231b3b80d8
* [mips] Resolve relocation for the stubs in MCJIT when load address is knownPetar Jovanovic2013-11-19
| | | | | | | | | | | Instead of processing relocation for branch to stubs right away, emit a modified relocation and add it to queue to be resolved later when final load address is known. This resolves seven MIPS MCJIT issues that were caused by missing relocation fixups at the end. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195157 91177308-0d34-0410-b5e6-96231b3b80d8
* Adding support for deregistering EH frames with MCJIT.Andrew Kaylor2013-10-16
| | | | | | | | Patch by Yaron Keren git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192753 91177308-0d34-0410-b5e6-96231b3b80d8
* Adding multiple object support to MCJIT EH frame handlingAndrew Kaylor2013-10-11
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192504 91177308-0d34-0410-b5e6-96231b3b80d8
* Adding multiple GOT handling to RuntimeDyldELFAndrew Kaylor2013-10-05
| | | | | | | | Patch by Ashok Thirumurthi git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192020 91177308-0d34-0410-b5e6-96231b3b80d8
* This threads SectionName through the allocateCodeSection/allocateDataSection ↵Filip Pizlo2013-10-02
| | | | | | | | | | | | | | | | | | | | APIs, both in C++ and C land. It's useful for the memory managers that are allocating a section to know what the name of the section is. At a minimum, this is useful for low-level debugging - it's customary for JITs to be able to tell you what memory they allocated, and as part of any such dump, they should be able to tell you some meta-data about what each allocation is for. This allows clients that supply their own memory managers to do this. Additionally, we also envision the SectionName being useful for passing meta-data from within LLVM to an LLVM client. This changes both the C and C++ APIs, and all of the clients of those APIs within LLVM. I'm assuming that it's safe to change the C++ API because that API is allowed to change. I'm assuming that it's safe to change the C API because we haven't shipped the API in a release yet (LLVM 3.3 doesn't include the MCJIT memory management C API). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191804 91177308-0d34-0410-b5e6-96231b3b80d8
* Adding PIC support for ELF on x86_64 platformsAndrew Kaylor2013-08-19
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188726 91177308-0d34-0410-b5e6-96231b3b80d8
* Adding comments to document RuntimeDyld relocation handlingAndrew Kaylor2013-08-19
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188697 91177308-0d34-0410-b5e6-96231b3b80d8
* Fixed RuntimeDyldELF absolute relocations.Richard Mitton2013-08-16
| | | | | | | | | If an ELF relocation is pointed at an absolute address, it will have a symbol ID of zero. RuntimeDyldELF::processRelocationRef was not previously handling this case, and was instead trying to handle it as a section-relative fixup. I think this is the right fix here, but my elf-fu is poor on some of the more exotic platforms, so I'd appreciate it if anyone with greater knowledge could verify this. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188572 91177308-0d34-0410-b5e6-96231b3b80d8
* [Object] Split the ELF interface into 3 parts.Michael J. Spencer2013-08-08
| | | | | | | | * ELFTypes.h contains template magic for defining types based on endianess, size, and alignment. * ELFFile.h defines the ELFFile class which provides low level ELF specific access. * ELFObjectFile.h contains ELFObjectFile which uses ELFFile to implement the ObjectFile interface. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188022 91177308-0d34-0410-b5e6-96231b3b80d8
* [PowerPC] Support powerpc64le as a syntax-checking target.Bill Schmidt2013-07-26
| | | | | | | | | | | | | | | | | | | | | | | | This patch provides basic support for powerpc64le as an LLVM target. However, use of this target will not actually generate little-endian code. Instead, use of the target will cause the correct little-endian built-in defines to be generated, so that code that tests for __LITTLE_ENDIAN__, for example, will be correctly parsed for syntax-only testing. Code generation will otherwise be the same as powerpc64 (big-endian), for now. The patch leaves open the possibility of creating a little-endian PowerPC64 back end, but there is no immediate intent to create such a thing. The LLVM portions of this patch simply add ppc64le coverage everywhere that ppc64 coverage currently exists. There is nothing of any import worth testing until such time as little-endian code generation is implemented. In the corresponding Clang patch, there is a new test case variant to ensure that correct built-in defines for little-endian code are generated. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187179 91177308-0d34-0410-b5e6-96231b3b80d8
* AArch64: don't mask off shift bits when processing JIT relocations.Tim Northover2013-07-25
| | | | | | | This should actually make the MCJIT tests pass again on AArch64. I don't know how I missed their failure before. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187120 91177308-0d34-0410-b5e6-96231b3b80d8
* [mips] Use pristine object file while processing relocations.Akira Hatanaka2013-07-24
| | | | | | | | | | | | | | | | | | | | | Similar to ARM change r182800, dynamic linker will read bits/addends from the original object rather than from the object that might have been patched previously. For the purpose of relocations for MCJIT stubs on MIPS, we internally use otherwise unused MIPS relocations. The change also enables MCJIT unit tests for MIPS (EL/BE), and the following two tests now pass: - MCJITTest.return_global and - MCJITTest.multiple_functions. These issues have been tracked as Bug 16250. Patch by Petar Jovanovic. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187019 91177308-0d34-0410-b5e6-96231b3b80d8
* AArch64: correct CodeGen of MOVZ/MOVK combinations.Tim Northover2013-07-01
| | | | | | | | | | | | According to the AArch64 ELF specification (4.6.8), it's the assembler's responsibility to make sure the shift amount is correct in relocated MOVZ/MOVK instructions. This wasn't being obeyed by either the MCJIT CodeGen or RuntimeDyldELF (which happened to work out well for JIT tests). This commit should make us compliant in this area. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185360 91177308-0d34-0410-b5e6-96231b3b80d8
* Handle (at least don't crash on) relocations with no symbols.Rafael Espindola2013-06-05
| | | | | | Should fix the MCJIT tests on PPC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183288 91177308-0d34-0410-b5e6-96231b3b80d8
* Handle relocations that don't point to symbols.Rafael Espindola2013-06-05
| | | | | | | | In ELF (as in MachO), not all relocations point to symbols. Represent this properly by using a symbol_iterator instead of a SymbolRef. Update llvm-readobj ELF's dumper to handle relocatios without symbols. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183284 91177308-0d34-0410-b5e6-96231b3b80d8
* Update RuntimeDyldELF::findOPDEntrySection the new relocation iterators.Rafael Espindola2013-06-03
| | | | | | | This was missing from r182908. I didn't noticed it at the time because the MCJIT tests were disabled when building with cmake on ppc64 (which I fixed in r183143). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183147 91177308-0d34-0410-b5e6-96231b3b80d8
* ARM: use pristine object file while processing relocationsTim Northover2013-05-28
| | | | | | | | | | | | | | Previously we would read-modify-write the target bits when processing relocations for the MCJIT. This had the problem that when relocations were processed multiple times for the same object file (as they can be), the result is not idempotent and the values became corrupted. The solution to this is to take any bits used in the destination from the pristine object file as LLVM emitted it. This should fix PR16013 and remote MCJIT on ARM ELF targets. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182800 91177308-0d34-0410-b5e6-96231b3b80d8
* AArch64: make RuntimeDyld relocations idempotentTim Northover2013-05-19
| | | | | | | | | | AArch64 ELF uses .rela relocations so there's no need to actually make use of the bits we're setting in the destination However, we should make sure all bits are cleared properly since multiple runs of resolveRelocations are possible and these could combine to produce invalid results if stale versions remain in the code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182214 91177308-0d34-0410-b5e6-96231b3b80d8
* r182085 introduced a change that triggered an assertion on ARM. This is an ↵David Tweed2013-05-17
| | | | | | | | | immediate fix which doesn't resolve the deeper problem. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182098 91177308-0d34-0410-b5e6-96231b3b80d8
* Change getRelocationAdditionalInfo to be ELF only.Rafael Espindola2013-05-09
| | | | | | | It was only implemented for ELF where it collected the Addend, so this patch also renames it to getRelocationAddend. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181502 91177308-0d34-0410-b5e6-96231b3b80d8
* PowerPC: Fix unimplemented relocation on ppc64Adhemerval Zanella2013-05-06
| | | | | | | | This patch handles the R_PPC64_REL64 relocation type for powerpc64 for mcjit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181220 91177308-0d34-0410-b5e6-96231b3b80d8
* Add EH support to the MCJIT.Rafael Espindola2013-05-05
| | | | | | | | | This gets exception handling working on ELF and Macho (x86-64 at least). Other than the EH frame registration, this patch also implements support for GOT relocations which are used to locate the personality function on MachO. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181167 91177308-0d34-0410-b5e6-96231b3b80d8
* AArch64: implement 64-bit absolute relocation in MCJITTim Northover2013-05-04
| | | | | | | | | This is about the simplest relocation, but surprisingly rare in actual code. It occurs in (for example) the MCJIT test test-ptr-reloc.ll. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181134 91177308-0d34-0410-b5e6-96231b3b80d8