summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [MACH-O] Fix the ASM code generated for __stub_helpers sectionRui Ueyama2017-08-241-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Patch by Patricio Villalobos. I discovered that lld for darwin is generating the wrong code for lazy bindings in the __stub_helper section (at least for osx 10.12). This is the way i can reproduce this problem, using this program: #include <stdio.h> int main(int argc, char **argv) { printf("C: printf!\n"); puts("C: puts!\n"); return 0; } Then I link it using i have tested it in 3.9, 4.0 and 4.1 versions: $ clang -c hello.c $ lld -flavor darwin hello.o -o h1 -lc When i execute the binary h1 the system gives me the following error: C: printf! dyld: lazy symbol binding failed: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB has segment 4 which is too large (0..3) dyld: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB has segment 4 which is too large (0..3) Trace/BPT trap: 5 Investigating the code, it seems that the problem is that the asm code generated in the file StubPass.cpp, specifically in the line 323,when it adds, what it seems an arbitrary number (12) to the offset into the lazy bind opcodes section, but it should be calculated depending on the MachONormalizedFileBinaryWrite::lazyBindingInfo result. I confirmed this bug by patching the code manually in the binary and writing the right offset in the asm code (__stub_helper). This patch fixes the content of the atom that contains the assembly code when the offset is known. Differential Revision: https://reviews.llvm.org/D35387 llvm-svn: 311734
* [MachO/X86_64] Simplify isDataInCodeTransition().Davide Italiano2017-04-151-8/+1
| | | | llvm-svn: 300385
* Prevent at compile time converting from Error::success() to Expected<T>Mehdi Amini2016-11-111-2/+2
| | | | | | | | This would trigger an assertion at runtime otherwise. Differential Revision: https://reviews.llvm.org/D26482 llvm-svn: 286562
* Change getReferenceInfo/getPairReferenceInfo to use new Error handling. NFC.Pete Cooper2016-03-301-29/+25
| | | | | | | | | | | | Adds a GenericError class to lld/Core which can carry a string. This is analygous to the dynamic_error we currently use in lld/Core. Use this GenericError instead of make_dynamic_error_code. Also, provide an implemention of GenericError::convertToErrorCode which for now converts it in to the dynamic_error_code we used to have. This will go away once all the APIs are converted. llvm-svn: 264910
* Fix more cases of UB from allocating 0 sized data. NFC.Pete Cooper2016-03-231-3/+4
| | | | | | | | | | | | The size of a section can be zero, even when it contains atoms, so long as all of the atoms are also size 0. In this case we were allocating space for a 0 sized buffer. Changed this to only allocate when we need the space, but also cleaned up all the code to use MutableArrayRef instead of uint8_t* so its much much safer as we get bounds checking on all of our section creation logic. llvm-svn: 264204
* Move empty atom check to target independent code. NFC.Pete Cooper2016-03-221-5/+0
| | | | | | | | | | Turns out that checking only x86 for empty atoms to fix UBSan then requires the same code in the other targets too. Better to just check this in the main run loop instead of in each target. Should be NFC, other than fixing UBSan failures. llvm-svn: 264116
* Avoid memcpy from nullptr. NFC.Pete Cooper2016-03-221-0/+5
| | | | | | | | | | This was caught by the UBSan bot. When the atom has no size, we would issue a memcpy with size0 and a nullptr for the source. Also, this code should never have references inside an empty atom so add an assert for that while we're here. llvm-svn: 264115
* Fix EHFrame processing to add implicit references when needed.Pete Cooper2016-03-151-0/+4
| | | | | | | | | | | | | | | | | The current code for processCIE and processFDE returns out if it sees any references. The problem with this is that some references could be explicit in the binary, while others are implicit as they can be inferred from the content of the EHFrame itself. This change walks the references we have against the references we need, and verifies that all explicit references are in the correct place, and generates any missing implicit ones. Reviewed by Lang Hames and Nick Kledzik. Differential Revision: http://reviews.llvm.org/D15439 llvm-svn: 263590
* Use __nl_symbol_ptr instead of __got in the stubs pass on x86 archs.Pete Cooper2016-02-091-0/+3
| | | | | | | | | | The non lazy atoms generated in the stubs pass use an image cache to hold all of the pointers. On arm archs, this is the __got section, but on x86 archs it should be __nl_symbol_ptr. rdar://problem/24572729 llvm-svn: 260271
* Aligned __stub_helper section to 4-bytes.Pete Cooper2016-02-091-0/+2
| | | | | | | | | | | | ld64 aligns most of the stub's to 2 byte alignment, expect for the stub helper common atoms which are 4 byte aligned. This adds a new field to StubInfo which tracks this alignment and ensures that this is the alignment we get in the final image. rdar://problem/24570220 llvm-svn: 260248
* Add pointerKind() method to the MachO ArchHandler's. NFC.Pete Cooper2016-02-021-0/+4
| | | | | | | | The ObjCPass is going to need to create pointer sized relocations in the ObjC sections. This method will be used to give us a target independent way of getting the correct kind for the refererence. llvm-svn: 259441
* Fix Clang-tidy misc-use-override warnings, other minor fixes.Rui Ueyama2015-09-101-9/+4
| | | | | | Patch from Eugene Zelenko! llvm-svn: 247323
* Define make_dynamic_error_code(const char *).Rui Ueyama2015-04-141-4/+4
| | | | | | | | | | | | The function took either StringRef or Twine. Since string literals are ambiguous when resolving the overloading, many code calls used this function with explicit type conversion. That led awkward code like make_dynamic_error_code(Twine("Error occurred")). This patch adds a function definition for string literals, so that you can directly call the function with literals. llvm-svn: 234841
* [Core,MachO,Test] Remove trailing whitespace.Shankar Easwaran2015-02-221-11/+11
| | | | llvm-svn: 230192
* [Mach-O] Rename enum typename for consistency. NFCJean-Daniel Dupas2015-02-191-4/+4
| | | | | | | Typename shouldn't mix camel case and underscore. Thanks to Rui for the remark. llvm-svn: 229848
* Update ARM and x86 ArchHandler to check switch completeness. NFCJean-Daniel Dupas2015-02-151-8/+10
| | | | | | Define an explicit type for arch specific reference kinds to make sure all cases are covered in switch statements. llvm-svn: 229314
* Break some test. Revert until I got a proper fixJean-Daniel Dupas2015-02-141-35/+33
| | | | llvm-svn: 229249
* Update ARM and x86 ArchHandler to match 64bits counterparts. NFCJean-Daniel Dupas2015-02-141-33/+35
| | | | | | | | | | | | | | | | | | Summary: Define an explicit type for arch specific reference kind and use it in switch statement to make the compiler emit warnings if some case is not cover. It will help to catch such errors when we add new mach-o reference kind. Reviewers: shankarke, kledzik Reviewed By: shankarke Subscribers: shankarke, aemerson, llvm-commits Projects: #lld Differential Revision: http://reviews.llvm.org/D7612 llvm-svn: 229246
* [cleanup] Re-sort #include lines using llvm/utils/sort_includes.pyChandler Carruth2015-01-141-1/+0
| | | | | | | | This is just a mechanical cleanup, no functionality changed. This just fixes very minor inconsistencies with how #include lines were spaced and sorted in LLD. llvm-svn: 225978
* Follow-up to r221913. Fix some -Wcast-qual warning reasons.Simon Atanasyan2014-11-141-10/+14
| | | | llvm-svn: 221974
* [mach-o] Fix lazy binding offsetsNick Kledzik2014-11-111-1/+3
| | | | | | | | | | The way lazy binding works in mach-o is that the linker generates a helper function and has the stub (PLT) initially jump to it. The helper function pushes an extra parameter then jumps into dyld. The extra parameter is an offset into the lazy binding info where dyld will find the information about which symbol to bind and way lazy binding pointer to update. llvm-svn: 221654
* [mach-o] explicitly cast little_n uses to ints to silence MSVCTim Northover2014-10-311-6/+6
| | | | | | Hopefully this'll fix the build failure in the bot. llvm-svn: 221007
* TMP: fix readN & writeN to not encourage UBTim Northover2014-10-271-34/+38
| | | | llvm-svn: 220730
* [mach-o] Support missing MH_SUBSECTIONS_VIA_SYMBOLSNick Kledzik2014-10-211-1/+2
| | | | | | | | | | | | | All compiler generated mach-o object files are marked with MH_SUBSECTIONS_VIA_SYMBOLS. But hand written assembly files need to opt-in if they are written correctly. The flag means the linker can break up a sections at symbol addresses and dead strip or re-order functions. This change recognizes object files without the flag and marks its atoms as not dead strippable and adds a layout-after chain of references so that the atoms cannot be re-ordered. llvm-svn: 220348
* Sort include files according to convention.Shankar Easwaran2014-10-181-2/+0
| | | | llvm-svn: 220131
* [mach-o] avoid overly clever std::find_ifTim Northover2014-10-151-0/+4
| | | | | | | The bots were complaining (possibly because of a lack of traits on the iterator I was trying to use). No functional change. llvm-svn: 219843
* [mach-o] make __unwind_info defer to __eh_frame when necessary.Tim Northover2014-10-151-0/+11
| | | | | | | | | | | | Not all situations are representable in the compressed __unwind_info format, and when this happens the entry needs to point to the more general __eh_frame description. Just x86_64 implementation for now. rdar://problem/18208653 llvm-svn: 219836
* [macho] Create references from __eh_frame FDEs to their function.Tim Northover2014-10-151-0/+4
| | | | | | | | | | | | | We'll also need references back to the CIE eventually, but for now making sure we can work out what an FDE is referring to is enough. The actual kind of reference needs to be different between architectures, probably because of MachO's chronic shortage of relocation types but I don't really want to know in case I find out something that distresses me even more. rdar://problem/18208653 llvm-svn: 219824
* [mach-o] Add Pass to create are shim Atoms for ARM interworking.Nick Kledzik2014-10-141-0/+4
| | | | | | | | | | | | | | | Arm code has two instruction encodings "thumb" and "arm". When branching from one code encoding to another, you need to use an instruction that switches the instruction mode. Usually the transition only happens at call sites, and the linker can transform a BL instruction in BLX (or vice versa). But if the compiler did a tail call optimization and a function ends with a branch (not branch and link), there is no pc-rel BX instruction. The ShimPass looks for pc-rel B instructions that will need to switch mode. For those cases it synthesizes a shim which does the transition, then modifies the original atom with the B instruction to target to the shim atom. llvm-svn: 219655
* [mach-o] create __unwind_info section on x86_64Tim Northover2014-09-301-3/+16
| | | | | | | | | | | This is a minimally useful pass to construct the __unwind_info section in a final object from the various __compact_unwind inputs. Currently it doesn't produce any compressed pages, only works for x86_64 and will fail if any function ends up without __compact_unwind. rdar://problem/18208653 llvm-svn: 218703
* [mach-o] Add support for arm64 (AAarch64)Nick Kledzik2014-09-091-1/+4
| | | | | | | | | | Most of the changes are in the new file ArchHandler_arm64.cpp. But a few things had to be fixed to support 16KB pages (instead of 4KB) which iOS arm64 requires. In addition the StubInfo struct had to be expanded because arm64 uses two instruction (ADRP/LDR) to load a global which requires two relocations. The other mach-o arches just needed one relocation. llvm-svn: 217469
* [mach-o] Add support for LC_DATA_IN_CODENick Kledzik2014-07-241-0/+33
| | | | | | | | | | | | | | Sometimes compilers emit data into code sections (e.g. constant pools or jump tables). These runs of data can throw off disassemblers. The solution in mach-o is that ranges of data-in-code are encoded into a table pointed to by the LC_DATA_IN_CODE load command. The way the data-in-code information is encoded into lld's Atom model is that that start and end of each data run is marked with a Reference whose offset is the start/end of the data run. For arm, the switch back to code also marks whether it is thumb or arm code. llvm-svn: 213901
* [mach-o] add support for old x86 __eh_frame sectionsNick Kledzik2014-07-211-24/+45
| | | | | | | Over time the symbols and relocations have changed for dwarf unwind info in the __eh_frame section. Add test cases for older and new style. llvm-svn: 213585
* [mach-o] Add support for x86 pointers which use scattered relocationsNick Kledzik2014-07-181-4/+20
| | | | llvm-svn: 213344
* [mach-o] Add support for x86 CALL instruction that uses a scattered relocationNick Kledzik2014-07-181-14/+47
| | | | llvm-svn: 213340
* [mach-o] implement more x86 and x86_64 relocation supportNick Kledzik2014-07-171-25/+184
| | | | | | | | | Add support for adding section relocations in -r mode. Enhance the test cases which validate the parsing of .o files to also round trip. They now write out the .o file and then parse that, verifying all relocations survived the round trip. llvm-svn: 213333
* [mach-o] refactor KindHandler into ArchHandler and simplify passes.Nick Kledzik2014-07-161-0/+331
All architecture specific handling is now done in the appropriate ArchHandler subclass. The StubsPass and GOTPass have been simplified. All architecture specific variations in stubs are now encoded in a table which is vended by the current ArchHandler. llvm-svn: 213187
OpenPOWER on IntegriCloud