summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Fix a bunch more of -Wpessimizing-move issues.Pete Cooper2016-03-311-4/+4
| | | | | | Thanks to Rui for pointing out this warning was firing. llvm-svn: 264978
* Fix a bunch of -Wpessimizing-move issues.Pete Cooper2016-03-311-1/+1
| | | | | | Thanks to Rui for pointing out this warning was firing. llvm-svn: 264977
* Convert a few macho reader/writer helpers to new error handling. NFC.Pete Cooper2016-03-311-21/+25
| | | | | | | | These methods were responsible for some of the few remaining calls to llvm::errorCodeToError. Converting them makes us have more Error's in the api and fewer error_code's. llvm-svn: 264974
* Convert lld file writing to llvm::Error. NFC.Pete Cooper2016-03-301-7/+7
| | | | | | | This converts the writeFile method, as well as some of the ones it calls in the normalized binary file writer and yaml writer. llvm-svn: 264961
* Use a memcpy to avoid unaligned store UB.Pete Cooper2016-03-241-6/+9
| | | | | | | On a 32-bit output, we may write LC_MAIN (which contains a uint64_t) to an unaligned address. This changes it to use a memcpy instead which is UB safe. llvm-svn: 264232
* Use a memcpy to avoid unaligned store UB.Pete Cooper2016-03-231-5/+8
| | | | | | | On a 32-bit output, we may write LC_SOURCE_VERSION (which contains a uint64_t) to an unaligned address. This changes it to use a memcpy instead which is UB safe. llvm-svn: 264202
* Don't memcpy from a null source. Found by UBSanPete Cooper2016-03-221-0/+2
| | | | llvm-svn: 264114
* Add cmdline options for LC_DATA_IN_CODE load command.Pete Cooper2016-02-091-7/+8
| | | | | | | | | | | | Also added the defaults for whether to generate this load command, which the cmdline options are able to override. There was also a difference to ld64 which is fixed here in that ld64 will generate an empty data in code command if requested. rdar://problem/24472630 llvm-svn: 260191
* Generate LC_FUNCTION_STARTS load command.Pete Cooper2016-02-091-43/+56
| | | | | | | | | | | | | | This load command generates data in the LINKEDIT section which is a list of ULEB128 delta's to all of the functions in the __text section. It is then 0 terminated and pointer aligned to pad. ld64 exposes the -function-starts and no-function-starts cmdline options to override behaviour from the defaults based on file types. rdar://problem/24472630 llvm-svn: 260188
* Set max segment protection level.Pete Cooper2016-02-061-6/+6
| | | | | | | | | | | The initial segment protection was also being used to set the maximum segment protection level. Instead, the maximum should be set according to the architecture we are linking. For example on Mac OS it should be RWX on most pages, but on iOS is often on R_X. rdar://problem/24515136 llvm-svn: 259966
* Move creation of "__LINKEDIT" segment. NFC.Pete Cooper2016-02-061-24/+28
| | | | | | | | | | | | We currently tag on a "__LINKEDIT" when we are emitting the segments. However, an upcoming patch aims to set the initprot and maxprot segment members to their correct values, and in order to share code, its better to create this segment for real and handle it in buildFileOffsets the same way ld64 does. The commit for segment protections will add a test for this all being correct so no test here until that code is committed. llvm-svn: 259960
* Set CPU_SUBTYPE_LIB64 in mach_header.Pete Cooper2016-02-041-1/+14
| | | | | | | | | | | On Mac OS 10.5 and later, with X86_64 and outputting a dynamic executable, ld64 set the CPU_SUBTYPE_LIB64 mask on the cpusubtype in the mach_header. This adds the same functionality to lld. rdar://problem/24507177 llvm-svn: 259826
* Add support for the source_version cmdline option.Pete Cooper2016-02-041-0/+15
| | | | | | | | | This is of the form A.B.C.D.E and to match ld64's behaviour, is always output to files, even when the version is 0. rdar://problem/24472630 llvm-svn: 259746
* Generate version min load commands when the platform is unknown.Pete Cooper2016-02-041-26/+42
| | | | | | | | | | | In the case where we are emitting to an object file, the platform is possibly unknown, and the source object files contained load commands for version min, we can take the maximum of those min versions and emit in in the output object file. This test also tests r259739. llvm-svn: 259742
* Add generation of LC_VERSION_MIN load commands.Pete Cooper2016-02-031-2/+46
| | | | | | | | | | | | | If the command line contains something like -macosx_version_min and we don't explicitly disable generation with -no_version_load_command then we generate the LC_VERSION_MIN command in the output file. There's a couple of FIXME's in here. These will be handled soon with more tests but I didn't want to grow this patch any more than it already was. rdar://problem/24472630 llvm-svn: 259718
* Use an ilist instead of std::list. NFC.Pete Cooper2016-01-251-78/+115
| | | | | | | | | | | | The TrieNode/TrieEdge data structures here are allocated in a bumpptrallocator. Unfortunately, TrieNode contained a std::list<TrieEdge> and as the allocator doesn't call the TrieNode destructor, we ended up leaking the memory allocated by the std::list itself. Instead we can use an intrusive list as then we save the extra allocations anyway. llvm-svn: 258725
* Update for LLVM function name change.Rui Ueyama2016-01-141-7/+5
| | | | llvm-svn: 257801
* [lld][MachO] Recognize __thread_bss sections as zero-fill and set all theLang Hames2015-12-111-6/+6
| | | | | | | | | appropriate bits. This fixes the remaining clang regression test failures when linking clang with lld on Darwin. llvm-svn: 255390
* [lld][MachO] Always reserve space for the empty string in the mach-o symbolLang Hames2015-12-101-1/+1
| | | | | | | | | | | | | table. The first entry in the MachO symbol table is always the empty string: make sure we reserve space for it, or we will overflow the symbol table by one byte. No test case - this manifests as an occasional memory error. In the near future I hope to set up a bot building and runnnig LLD with sanitizers - that should catch future instances of this issue. llvm-svn: 255178
* Fix Clang-tidy modernize-use-auto warnings, other minor fixes.Eugene Zelenko2015-11-101-14/+8
| | | | | | Differential revision: http://reviews.llvm.org/D14553 llvm-svn: 252661
* [lld][MachO] Make sure LC_RPATH command size is a multiple of the pointer size.Lang Hames2015-10-291-2/+2
| | | | llvm-svn: 251637
* [lld][MachO] Initial implementation of -flat_namespace and -undefined.Lang Hames2015-09-281-2/+12
| | | | | | | | | This is a basic initial implementation of the -flat_namespace and -undefined options for LLD-darwin. It ignores several subtlties, but the result is close enough that we can now link LLVM (but not clang) on Darwin and pass all regression tests. llvm-svn: 248732
* Update for llvm api change.Rafael Espindola2015-08-131-6/+5
| | | | llvm-svn: 244849
* Wdeprecated: Remove unnecessary user-defined dtor that was getting in the ↵David Blaikie2015-08-121-1/+0
| | | | | | way of the default ops (copy construction, assignment, etc) llvm-svn: 244836
* [LLD] Add support for the -stack_size option to Darwin ld.Lang Hames2015-05-201-1/+1
| | | | llvm-svn: 237841
* Use alignment values everywhere instead of log2.Rui Ueyama2015-03-261-3/+3
| | | | | | | | This patch defines implicit conversion between integers and PowerOf2 instances, so uses of the classes is now implicit and look like regular integers. Now we are ready to remove the scaffolding. llvm-svn: 233245
* Remove implicit constructor and operator int from PowerOf2.Rui Ueyama2015-03-261-4/+3
| | | | | | | | | | This patch is to make instantiation and conversion to an integer explicit, so that we can mechanically replace all occurrences of the class with integer in the next step. Now get() returns an alignment value rather than its log2 value. llvm-svn: 233242
* [macho] Minor install_name fixesJean-Daniel Dupas2014-12-201-1/+3
| | | | | | | | | | | | | | | | | | | Summary: Fix the binary file reader to properly read dyld version info. Update the install_name test case to properly test the binary reader. We can't use '-print_atoms' as the output format is 'native' yaml and it does not contains the dyld current and compatibility versions. Also change the timestamp value of LD_ID_DYLD to match the one generated by ld64. The dynamic linker (dyld) used to expects different values for timestamp in LD_ID_DYLD and LD_LOAD_DYLD for prebound images. While prebinding is deprecated, we should probably keep it safe and match ld64. Reviewers: kledzik Subscribers: llvm-commits Projects: #lld Differential Revision: http://reviews.llvm.org/D6736 llvm-svn: 224681
* [macho] -rpath supportJean-Daniel Dupas2014-12-181-0/+21
| | | | | | | | | | | | | | | | | | | | | Summary: Work on adding -rpath support to the mach-o linker. This patch is based on the ld64 behavior for the command line option validation. It includes a basic test to check that the LC_RPATH load commands are properly generated when that option is used. It also add LC_RPATH support to the binary reader, but I don't know how to test it though. Reviewers: kledzik Subscribers: llvm-commits Projects: #lld Differential Revision: http://reviews.llvm.org/D6724 llvm-svn: 224544
* [mach-o] Fix TrieEdge leakNick Kledzik2014-12-021-5/+6
| | | | | | | | In PR21682 Jean-Daliel Dupas found a leak in the trie builder and suggested a fix was to use a list instead of SmallVector so that the list elements could be allocated in the BumpPtrAllocator. llvm-svn: 223104
* [mach-o] propagate dylib version numbersNick Kledzik2014-11-191-6/+6
| | | | | | | | | | | | | | Mach-o does not use a simple SO_NEEDED to track dependent dylibs. Instead, the linker copies four things from each dylib to each client: the runtime path (aka "install name"), the build time, current version (dylib build number), and compatibility version The build time is no longer used (it cause every rebuild of a dylib to be different). The compatibility version is usually just 1.0 and never changes, or the dylib becomes incompatible. This patch copies that information into the NormalizedMachO format and propagates it to clients. llvm-svn: 222300
* [mach-o] zero-fill sections have no file offsetNick Kledzik2014-11-181-9/+17
| | | | | | | In mach-o, sections of type S_ZEROFILL are special cased and to always have their section.offset field be zero. llvm-svn: 222202
* [mach-o] Fix lazy binding offsetsNick Kledzik2014-11-111-2/+11
| | | | | | | | | | 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] generate LC_DATA_IN_CODE in final linked imagesNick Kledzik2014-10-281-0/+18
| | | | | | | | | lld was regenerating LC_DATA_IN_CODE in .o output files, but not into final linked images. Update test case to verify data-in-code info makes it into final linked images. llvm-svn: 220827
* [mach-o] Support data-only dylibsNick Kledzik2014-10-241-0/+3
| | | | | | | | In final linked shared images, the __TEXT segment contains both code and the mach-o header/load-commands. In the case of a data-only dylib, there is no code, so we need to force the addition of the __TEXT segment. llvm-svn: 220597
* Sort include files according to convention.Shankar Easwaran2014-10-181-1/+1
| | | | llvm-svn: 220131
* [mach-o] Add support for upward linkingNick Kledzik2014-10-161-1/+1
| | | | | | | | To deal with cycles in shared library dependencies, the darwin linker supports marking specific link dependencies as "upward". An upward link is when a lower level library links against a higher level library. llvm-svn: 219949
* [mach-o] Add support for arm64 (AAarch64)Nick Kledzik2014-09-091-11/+19
| | | | | | | | | | 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 using export triesNick Kledzik2014-09-031-4/+236
| | | | | | | | | | | On Darwin at runtime, dyld will prefer to use the export trie of a dylib instead of the traditional symbol table (which is large and requires a binary search). This change enables the linker to generate an export trie and to prefer it if found in a dylib being linked against. This also simples the yaml for dylibs because the yaml form of the trie can be reduced to just a sequence of names. llvm-svn: 217066
* [mach-o] Add support for -sectalign optionNick Kledzik2014-07-301-1/+7
| | | | | | | | | | | | The -sectalign option is used to increase the alignment required for a section. It required some reworking of how the __TEXT segment is laid out because that segment also contains the mach_header and load commands. And the size of load commands depend on the number of segments, sections, and dependent dylibs used. Using this option will simplify some future test cases because the final address of code can be pinned down, making tests of its content easier. llvm-svn: 214268
* [mach-o] Add support for LC_DATA_IN_CODENick Kledzik2014-07-241-5/+46
| | | | | | | | | | | | | | 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 representation for LC_ID_DYLIB to MachONormalizedFileTim Northover2014-07-011-1/+24
| | | | | | | It still needs to be tied into BinaryReader, but this allows reasonably sensible creation of SharedLibrary atoms on MachO. llvm-svn: 212093
* MachO: calculate segment offsets in final MachO files properly.Tim Northover2014-06-301-6/+16
| | | | | | | | | Because of how we were calculating fileOffset and fileSize for segments, most ended up at a single offset in a finalised MachO file. This meant the data often didn't even get written in the final object, let alone where it would be useful. llvm-svn: 212030
* Left two files out of the previous commitArtyom Skrobov2014-06-141-2/+2
| | | | llvm-svn: 210975
* Update for llvm api change.Rafael Espindola2014-06-131-3/+4
| | | | llvm-svn: 210919
* include system_error directly.Rafael Espindola2014-06-121-1/+1
| | | | llvm-svn: 210801
* Run llvm/utils/sort_includes.py in a few files.Rafael Espindola2014-06-121-3/+0
| | | | | | This will reduce the noise in a followup patch. llvm-svn: 210800
* Don't import error_code into the lld namespace.Rafael Espindola2014-06-121-22/+15
| | | | llvm-svn: 210785
* Don't use make_error_code from the llvm namespace.Rafael Espindola2014-06-121-3/+3
| | | | llvm-svn: 210741
* Use std::error_code instead of llvm::error_code.Rafael Espindola2014-06-111-3/+3
| | | | | | This is an update for a llvm api change. llvm-svn: 210689
OpenPOWER on IntegriCloud