summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/MachO/ArchHandler_arm64.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/AArch64] Merge multiple switch cases into one. NFCI.Davide Italiano2017-04-151-4/+0
| | | | llvm-svn: 300384
* Fix wrong formatting in lld introduced in r286561 (NFC)Mehdi Amini2016-11-111-1/+1
| | | | | | Pointed out by Davide. llvm-svn: 286649
* Prevent at compile time converting from Error::success() to Expected<T>Mehdi Amini2016-11-111-15/+15
| | | | | | | | This would trigger an assertion at runtime otherwise. Differential Revision: https://reviews.llvm.org/D26482 llvm-svn: 286562
* Arm64 stubs alignment is 2, not 4.Pete Cooper2016-08-111-2/+2
| | | | | | This matches the behaviour of ld64 when looking at the alignment of the stubs section in the final image. llvm-svn: 278398
* Change getReferenceInfo/getPairReferenceInfo to use new Error handling. NFC.Pete Cooper2016-03-301-30/+31
| | | | | | | | | | | | 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
* Use unaligned read to fix UB. NFC.Pete Cooper2016-03-241-3/+4
| | | | | | | | | | | We were casting a potentially unaligned pointer to uint32_t and dereferencing. As the pointer ultimately comes from the object file, there's no way to guarantee alignment, so use the little32_t read instead. Also, little32_t knows about endianness, so in theory this may have broken on big endian machines. llvm-svn: 264231
* 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
* Fix EHFrame processing to add implicit references when needed.Pete Cooper2016-03-151-2/+36
| | | | | | | | | | | | | | | | | 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
* Always generate the fixup content for unwindFDEToFunction as we noPete Cooper2016-01-071-3/+11
| | | | | | longer emit it. llvm-svn: 257100
* Fix MachO arm64 delta32ToGOT reloc encoding in -r.Pete Cooper2016-01-061-1/+1
| | | | | | | | | | | | | The fixup content we encode here should be the offset from the fixup location back to the last nonlocal label. We were only encoding the address of the fixup, and not taking in to account the base address of the atom we are in. Updated the test case here to have a text section which will come before the data section where the relocation lives. .data being at offset 0 had previously been hiding this bug. llvm-svn: 256974
* Improved debugging printing. NFCPete Cooper2016-01-051-0/+17
| | | | llvm-svn: 256805
* Fix negDelta32 relocatable fixups for arm64 in mach-o.Pete Cooper2015-12-161-1/+1
| | | | | | | | | | | negDelta32 is only ever implicitly generated as the FDE->CIE reference. We therefore don't emit a relocation for it in the object file in -r mode. The value we write in to the FDE location therefore needs to point to the final target address of the CIE, and not the inAtomAddress as it was currently doing. llvm-svn: 255835
* Verify that macho-o delta64 relocs have the same offset.Pete Cooper2015-12-101-0/+3
| | | | | | | | | | The delta64 relocation is represented as the pair ARM64_RELOC_SUBTRACTOR and ARM64_RELOC_UNSIGNED. Those should always have the same offset, so this adds a check and tests to ensure this is the case. Also updated the error printing in this case to shows both relocs when erroring on pair. llvm-svn: 255274
* Don't bypass the GOT for delta32toGOT references.Pete Cooper2015-12-091-0/+6
| | | | | | | | | | | The gcc_except_tab was generating these references to point to the typeinfo in the data section. gcc_except_tab also had the DW_EH_PE_indirect flag set which means that at runtime we are going to dereference this entry as if it is in the GOT. Reviewed by Nick Kledzik in http://reviews.llvm.org/D15360. llvm-svn: 255085
* Fix Clang-tidy misc-use-override warnings, other minor fixes.Rui Ueyama2015-09-101-6/+2
| | | | | | Patch from Eugene Zelenko! llvm-svn: 247323
* Define make_dynamic_error_code(const char *).Rui Ueyama2015-04-141-2/+2
| | | | | | | | | | | | 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
* [Mach-O] Rename enum typename for consistency. NFCJean-Daniel Dupas2015-02-191-6/+6
| | | | | | | Typename shouldn't mix camel case and underscore. Thanks to Rui for the remark. llvm-svn: 229848
* [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
* [mach-o] add support for arm64 compact unwind infoNick Kledzik2014-12-021-11/+68
| | | | | | | Tim previously added generic compact unwind processing and x86_64 support. This patch adds arm64 support. llvm-svn: 223103
* Silence a -Wcast-qual warningDavid Majnemer2014-11-221-1/+1
| | | | llvm-svn: 222598
* [mach-o] enhance arm64 reloc parser to support local pointer relocationsNick Kledzik2014-11-181-1/+5
| | | | | | | | | | | The arm64 assembler almost always uses r_extern=1 relocations in which the r_symbolnum field is the index of the symbol the relocation references. But sometimes it will set r_extern=0 in which case the linker needs to read the content of the reloction to determine the target. Add test case that the r_extern=0 relocation round trips. llvm-svn: 222200
* [mach-o] fix typos. No function changeNick Kledzik2014-11-181-5/+1
| | | | llvm-svn: 222199
* [mach-o] enhance arm64 reloc parser to support local pointer relocationsNick Kledzik2014-11-181-5/+19
| | | | | | | | | | | The arm64 assembler almost always uses r_extern=1 relocations in which the r_symbolnum field is the index of the symbol the relocation references. But sometimes it will set r_extern=0 in which case the linker needs to read the content of the reloction to determine the target. Add test case that the r_extern=0 relocation round trips. llvm-svn: 222198
* [mach-o] fix typos. No function changeNick Kledzik2014-11-181-4/+3
| | | | llvm-svn: 222197
* Follow-up to r221913. Fix some -Wcast-qual warning reasons.Simon Atanasyan2014-11-141-4/+4
| | | | 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
* Fix warnings about missing override.Rafael Espindola2014-11-031-1/+1
| | | | llvm-svn: 221165
* [mach-o] explicitly cast little_n uses to ints to silence MSVCTim Northover2014-10-311-2/+2
| | | | | | Hopefully this'll fix the build failure in the bot. llvm-svn: 221007
* TMP: fix readN & writeN to not encourage UBTim Northover2014-10-271-49/+42
| | | | llvm-svn: 220730
* [mach-o] Support missing MH_SUBSECTIONS_VIA_SYMBOLSNick Kledzik2014-10-211-2/+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-5/+14
| | | | | | | | | | | | 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-0/+13
| | | | | | | | | | | 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
* Remove unused local typedef.Eric Christopher2014-09-101-1/+0
| | | | llvm-svn: 217532
* [mach-o] Add support for arm64 (AAarch64)Nick Kledzik2014-09-091-0/+727
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
OpenPOWER on IntegriCloud