summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Use alignment values everywhere instead of log2.Rui Ueyama2015-03-261-5/+5
| | | | | | | | 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
* Define an implicit constructor which takes actual alignment value to PowerOf2.Rui Ueyama2015-03-261-2/+2
| | | | | | | The new constructor's type is the same, but this one takes not a log2 value but an alignment value itself, so the meaning is totally differnet. llvm-svn: 233244
* Make PowerOf2's constructor private.Rui Ueyama2015-03-261-2/+2
| | | | | | | Ban conversion from integers to PowerOf2 even if explicit to make all places we create PowerOf2 instances visible. llvm-svn: 233243
* Remove implicit constructor and operator int from PowerOf2.Rui Ueyama2015-03-261-4/+4
| | | | | | | | | | 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
* Add a scaffolding to merge alignment representations.Rui Ueyama2015-03-261-5/+4
| | | | | | | | | | | | | | | | | We are using log2 values and values themselves to represent alignments. For example, alignment 8 is sometimes represented as 3 (8 == 2^3). We want to stop using log2 values. Because both types are regular arithmetic types, we cannot get help from a compiler to find places we mix two representations. That makes this merging work surprisingly hard because if I make a mistake, I'll just get wrong results at runtime (Yay types!). In this patch, I introduced a class to represents power-of-two values, which is basically an alias for an integer type. Once the migration is done, the class will be removed. llvm-svn: 233232
* [Core,MachO,Test] Remove trailing whitespace.Shankar Easwaran2015-02-221-1/+1
| | | | llvm-svn: 230192
* Using 'isa' instead of 'dyn_cast'Jean-Daniel Dupas2015-02-131-1/+1
| | | | llvm-svn: 229107
* [macho] -rpath supportJean-Daniel Dupas2014-12-181-0/+1
| | | | | | | | | | | | | | | | | | | | | 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
* Fix Darwin linker. Patch from Jean-Daniel Dupas.Rui Ueyama2014-12-101-1/+1
| | | | llvm-svn: 223865
* [mach-o] fix leak in atoms -> normalizedNick Kledzik2014-12-051-0/+17
| | | | llvm-svn: 223530
* [mach-o] propagate dylib version numbersNick Kledzik2014-11-191-0/+4
| | | | | | | | | | | | | | 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-2/+5
| | | | | | | 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] Support linker synthesized mach_header symbols.Nick Kledzik2014-11-121-1/+13
| | | | | | | | | | | | | | | | | | | | | | | On darwin in final linked images, the __TEXT segment covers that start of the file. That means in memory a process can see the mach_header (and load commands) for every loaded image in a process. There are APIs that take and return the mach_header addresses as a way to specify a particular loaded image. For completeness, any code can get the address of the mach_header of the image it is in by using &__dso_handle. In addition there are mach-o type specific symbols like __mh_execute_header. The linker needs to supply a definition for any of these symbols if used. But the address the symbol it resolves to is not in any section. Instead it is the address of the start of the __TEXT segment. I needed to make a small change to SimpleFileNode to not override resetNextIndex() because the Driver creates a SimpleFileNode to hold the internal/implicit files that the context/writer can create. For some reason SimpleFileNode overrode resetNextIndex() to do nothing instead of reseting the index (which mach-o needs if the internal file is an archive). llvm-svn: 221822
* [mach-o] Fix lazy binding offsetsNick Kledzik2014-11-111-0/+1
| | | | | | | | | | 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] remove extra leading underscore on __bss and __gotNick Kledzik2014-11-061-2/+2
| | | | llvm-svn: 221425
* [mach-o] Add support for interposing tuples sectionNick Kledzik2014-11-061-0/+1
| | | | | | | | | | Darwin uses two-level-namespace lookup for symbols which means the static linker records where each symbol must be found at runtime. Thus defining a symbol in a dylib loaded earlier will not effect where symbols needed by later dylibs will be found. Instead overriding is done through a section of type S_INTERPOSING which contains tuples of <interposer, interposee>. llvm-svn: 221421
* [mach-o] remove __compact_unwind atoms once __unwind_info has been generatedTim Northover2014-11-041-6/+0
| | | | | | | | | | The job of the CompactUnwind pass is to turn __compact_unwind data (and __eh_frame) into the compressed final form in __unwind_info. After it's done, the original atoms are no longer relevant and should be deleted (they cause problems during actual execution, quite apart from the fact that they're not needed). llvm-svn: 221301
* [mach-o] Support data-only dylibsNick Kledzik2014-10-241-2/+12
| | | | | | | | 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-2/+0
| | | | llvm-svn: 220131
* [mach-o] Add support for upward linkingNick Kledzik2014-10-161-0/+2
| | | | | | | | 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] make __unwind_info defer to __eh_frame when necessary.Tim Northover2014-10-151-0/+9
| | | | | | | | | | | | 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
* [mach-o] create __unwind_info section on x86_64Tim Northover2014-09-301-1/+3
| | | | | | | | | | | 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
* Modified per David Blakie suggestion.Yaron Keren2014-09-211-3/+1
| | | | llvm-svn: 218198
* Silence these C4715 warnings from Visual C++ (NFC)Yaron Keren2014-09-211-0/+3
| | | | | | | | | | | | | | | llvm\tools\lld\lib\readerwriter\macho\macholinkingcontext.cpp(647): warning C4715: 'lld::MachOLinkingContext::exportSymbolNamed' : not all control paths return a value llvm\tools\lld\lib\readerwriter\macho\machonormalizedfilefromatoms.cpp(723): warning C4715: '`anonymous namespace'::Util::getSymbolTableRegion' : not all control paths return a value While all enum values do appear in the switch, an uninitialized or corrupted enum variable would not be caught without the default: case in the switch. llvm-svn: 218197
* [mach-o] Fix two-level namespace ordinalsNick Kledzik2014-09-161-11/+14
| | | | | | | | | On darwin, the linker tools records which dylib (DSO) each undefined was found in, and then at runtime, the loader (dyld) only looks in that one specific dylib for each undefined symbol. Now that llvm-objdump can display that info I can write test cases. llvm-svn: 217898
* [mach-o]: implement -image_base option on Darwin.Tim Northover2014-09-101-5/+8
| | | | | | | As suggested by Nick, this will make __unwind_info implementation more natural, and it'd have to be done at some point anyway. llvm-svn: 217486
* [mach-o] Add support for arm64 (AAarch64)Nick Kledzik2014-09-091-0/+1
| | | | | | | | | | 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 -pie and -no_pieNick Kledzik2014-09-091-1/+4
| | | | | | | | | There is a bit (MH_PIE) in the flags field of the mach_header which tells the kernel is a program was built position independent (for ASLR). The linker automatically attempts to build programs PIE if they are built for a recent OS version. But the -pie and -no_pie options override that default behavior. llvm-svn: 217408
* [mach-o] Add support for using export triesNick Kledzik2014-09-031-0/+31
| | | | | | | | | | | 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] support N_NO_DEAD_STRIP nlist.desc bitNick Kledzik2014-08-211-0/+5
| | | | | | | Mach-O symbols can have an attribute on them means their content should never be dead code stripped. This translates to deadStrip() == deadStripNever. llvm-svn: 216234
* [mach-o] Add support for -exported_symbols_list and -keep_private_externsNick Kledzik2014-08-211-32/+69
| | | | | | | | | | | | | | Both options control the final scope of atoms. When -exported_symbols_list <file> is used, the file is parsed into one symbol per line in the file. Only those symbols will be exported (global) in the final linked image. The -keep_private_externs option is only used with -r mode. Normally, -r mode reduces private extern (scopeLinkageUnit) symbols to non-external. But add the -keep_private_externs option keeps them private external. llvm-svn: 216146
* [mach-o] set ordinal in n_desc for undefined symbolsNick Kledzik2014-08-131-1/+6
| | | | | | | | | | | Mach-o uses "two-level namespace" where each undefined symbols is associated with a specific dylib. This means at runtime the loader (dyld) does need to search all loaded dylibs for that symbol but rather just the one specified. Now that llvm-nm -m prints out that info, properly set that info, and test it in the hello world test cases. llvm-svn: 215598
* [mach-o] Add support for -sectalign optionNick Kledzik2014-07-301-44/+90
| | | | | | | | | | | | 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] Implement interworking between thumb and arm codeNick Kledzik2014-07-281-1/+4
| | | | | | | | | | | All iOS arm processor support switching between arm and thumb mode at call sites by using the BLX instruction (instead of BL). But the compiler does not know the implementation mode for extern functions, so the linker must update BL/BLX instructions to match what is linked is actually linked together. In addition, pointers to functions (such as vtables) must have the low bit set if the target of the pointer is a thumb mode function. llvm-svn: 214140
* [mach-o] Add support for LC_DATA_IN_CODENick Kledzik2014-07-241-0/+42
| | | | | | | | | | | | | | 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 initial support for modes in arm code.Nick Kledzik2014-07-231-1/+3
| | | | | | | | | This patch just supports marking ranges that are thumb code (vs arm code). Future patches will mark data and jump table ranges. The ranges are encoded as References with offsetInAtom being the start of the range and the target being the same atom. llvm-svn: 213712
* [mach-o] Add test case for armv6 (arm not thumb) hello worldNick Kledzik2014-07-221-1/+6
| | | | llvm-svn: 213592
* [mach-o] implement more x86 and x86_64 relocation supportNick Kledzik2014-07-171-31/+70
| | | | | | | | | 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-5/+7
| | | | | | | | | | | 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
* [mach-o] add x86 test case to build hello world. Fix bugs it uncovered.Nick Kledzik2014-07-031-2/+4
| | | | llvm-svn: 212247
* [mach-o] add representation for LC_ID_DYLIB to MachONormalizedFileTim Northover2014-07-011-0/+1
| | | | | | | It still needs to be tied into BinaryReader, but this allows reasonably sensible creation of SharedLibrary atoms on MachO. llvm-svn: 212093
* MachO: stop iterating past the end of an arrayTim Northover2014-06-301-8/+7
| | | | | | | | When trying to map atom types to sections, we were iterating through an array until we hit a sentinel value. There's no need for such dances when range-based for loops are available. llvm-svn: 212035
* MachO: re-enable writing of compact-unwind sections.Tim Northover2014-06-301-1/+7
| | | | | | | | | | | | This isn't really the right place to put them in final object files (that would be __TEXT,__unwind_info), but the format is different between relocatable and final objects, which means we really need a pass to handle the translation. For now, re-emitting in __LD,__compact_unwind is harmless (dyld ignores it and moves straight on to inspecting __TEXT,__eh_frame), and sidesteps an assertion failure when processing files containing compact-unwind info. llvm-svn: 212032
* MachO: align segment virtual addresses to page size.Tim Northover2014-06-301-2/+5
| | | | | | | | | Segments must occupy a multiple of the page size in memory (4096 currently). We check for this when emitting files, but the placement algorithm broke down for the second non-__TEXT segment encountered: the offset wasn't aligned up to 4096 before starting its layout. llvm-svn: 212031
* [mach-o] refactor x86_64 relocation handling.Nick Kledzik2014-06-271-1/+7
| | | | | | | | | | | | | | This is first step in reworking how mach-o relocations are processed. The existing KindHandler is going to become a delgate/helper object for processing architecture specific references. The KindHandler knows how to convert mach-o relocations into References and back, as well, as fixing up the content the relocation is on. One of the messy things about mach-o relocations is that they sometime come in pairs, but the pairs still convert to one lld::Reference. So, the conversion has to detect pairs (arch specific) and change the stride. llvm-svn: 211921
* MachO: rename _outputFileType to avoid shadowing parent field.Tim Northover2014-06-201-9/+9
| | | | llvm-svn: 211367
* 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
* [mach-o] fix use of resolver functions to not cause duplicate sections.Nick Kledzik2014-06-111-14/+23
| | | | | | | | | The previous commit uncovered a bug in the mach-o writer whereby two __text sections were created. But the test case did not catch that. So I updated the test case to run the linker a second time, reading the output of the first pass. llvm-svn: 210624
* [mach-o] add support for parsing resolver functionsNick Kledzik2014-06-111-1/+24
| | | | llvm-svn: 210612
OpenPOWER on IntegriCloud