summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter
Commit message (Collapse)AuthorAgeFilesLines
...
* Set max segment protection level.Pete Cooper2016-02-064-18/+49
| | | | | | | | | | | 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-062-24/+30
| | | | | | | | | | | | 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
* Use unsigned long long instead of uint64_t to appease botsPete Cooper2016-02-041-1/+1
| | | | llvm-svn: 259748
* Add support for the source_version cmdline option.Pete Cooper2016-02-043-0/+45
| | | | | | | | | 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
* Set S_ATTR_SOME_INSTRUCTIONS on __text section.Pete Cooper2016-02-041-1/+1
| | | | | | | | | ld64 sets both S_ATTR_PURE_INSTRUCTIONS and S_ATTR_SOME_INSTRUCTIONS on __TEXT, __text. We only had the S_ATTR_PURE_INSTRUCTIONS attribute. rdar://problem/24495801 llvm-svn: 259744
* Generate version min load commands when the platform is unknown.Pete Cooper2016-02-047-32/+127
| | | | | | | | | | | 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
* Default to an unknown OS instead of MacOSX.Pete Cooper2016-02-041-18/+24
| | | | | | | | | | | | Defaulting to unknown matches ld64, but it also makes sure that all of our code can handle not knowing the platform. For example, a later commit will add support for version min load commands with an unknown platform, which is a feature supported by ld64. No test case here. The next commit will have one with the version min code that needed this patch. llvm-svn: 259739
* Add support for -sdk_version cmdline option.Pete Cooper2016-02-031-1/+1
| | | | | | | | | | | | This option is emitted in the min_version load commands. Note, there's currently a difference in behaviour compared to ld64 in that we emit a warning if we generate a min_version load command and didn't give an sdk_version. We need to decide what the correct behaviour is here as its possible we want to emit an error and force clients to provide the option. llvm-svn: 259729
* Add generation of LC_VERSION_MIN load commands.Pete Cooper2016-02-033-2/+56
| | | | | | | | | | | | | 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
* __mh_execute_header atoms should be global and never dead strippped.Pete Cooper2016-02-022-2/+8
| | | | | | | | | | | | | | In r259574 I fixed some of the issues with the mach header symbols and DSO handles. This is the next issue whereby the __mh_execute_header has to not be dead stripped, and (to match ld64) should be dynamically referenced. The test here should also have been added in r259574 to make sure that we emit this symbol. But checking that it is not only emitted but also has the correct reference type is fine. llvm-svn: 259589
* Fix handling of mach header and DSO handle symbols.Pete Cooper2016-02-023-37/+55
| | | | | | | | | | | | | | | | | The magic file which contained these symbols inherited from archive which meant that the resolver didn't add the required atoms as archive members only get added when referenced. Instead we now inherit from SimpleFile which always links in the atoms needed. The second issue was in the handling of these symbols when we emit the MachO. The mach header symbol needs to be in the atom list as it gets an offset (0), and being in the atom list makes sure it is emitted to the symbol table. DSO handles are not emitted to the symbol table. rdar://problem/24450654 llvm-svn: 259574
* Set ordinals of all File's created in MachO passes.Pete Cooper2016-02-025-5/+15
| | | | | | | | | | | When we do debug printing of atoms, they expect their parent file to have an ordinal. Right now we trigger a bunch of asserts. This doesn't actually manifest in differences in any real tests, but even if the only thing it does is improve debuggability then its still useful. llvm-svn: 259450
* Fixed comment characters. NFCPete Cooper2016-02-021-3/+3
| | | | llvm-svn: 259442
* Add pointerKind() method to the MachO ArchHandler's. NFC.Pete Cooper2016-02-025-0/+20
| | | | | | | | 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
* Add ObjC method list atom type. NFC.Pete Cooper2016-02-011-0/+2
| | | | | | | | | | An upcoming patch will use this to create lists of ObjC methods. Adding it now to reduce the amount of code in that patch. Test cases will follow in the other patch too. llvm-svn: 259440
* Move SimpleDefinedAtom::addReference to DefinedAtom.Pete Cooper2016-02-015-26/+32
| | | | | | | | | | | | Most of the other methods to access Reference's were on DefinedAtom so this just keeps them all together. This will be used in a future patch in ObjCPass which needs to add new references. The method is virtual because we may add references to different data structures depending on whether we parsed a macho file or yaml. llvm-svn: 259436
* MachoFile should default to using subsections_via_symbols.Pete Cooper2016-02-011-1/+1
| | | | | | | | | | | | When we parse a MachoFile, we set a number of members from the parsed file, for example, subsectionsViaSymbols. However, a number of passes, such as ObjCPass, create local copies of MachoFile and don't get the benefit of setting flags and other fields in the parser. Instead we can just give a more sensible default as the parser will definitely get the correct value from the file anyway. llvm-svn: 259426
* Use dyn_cast instead of static_cast.Pete Cooper2016-02-011-3/+3
| | | | | | | | | | | | | | Now that MachoFile has classof(), we can use dyn_cast instead which is actually the only safe way to handle this. Turns out this actually manifests as a bug as we were incorrectly casting instances which weren't MachoFile in to a MachoFile. Unfortunately, there's no reliable way of checking for this as it requires that the file we are looking for has a 0 at exactly the byte we need for the load of subsectionsViaSymbols. llvm-svn: 259413
* Atomize the ObjC category list section.Pete Cooper2016-02-011-0/+3
| | | | | | | | | __DATA, __objc_catlist contains a list of pointers to categories. We want to atomize it so that the ObjC pass can later optimize and remove categories. That will be a later patch. llvm-svn: 259386
* 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
* Initialize member variable.Pete Cooper2016-01-251-1/+1
| | | | | | Found by Rafael using valgrind in https://llvm.org/bugs/show_bug.cgi?id=21466. llvm-svn: 258718
* Add support for export_dynamic cmdline option and behaviour.Pete Cooper2016-01-221-2/+4
| | | | | | | | | | | This option matches the behaviour of ld64, that is it prevents globals from being dead stripped in executables and dylibs. Reviewed by Lang Hames Differential Revision: http://reviews.llvm.org/D16026 llvm-svn: 258554
* Add an ObjCPass to the MachO linker.Pete Cooper2016-01-196-31/+167
| | | | | | | | | This pass currently emits an objc image info section if one is required. This section contains the aggregated version and flags for all of the input files. llvm-svn: 258197
* Set the objc constraint on the context based on the parsed files.Pete Cooper2016-01-191-0/+35
| | | | | | | | | | | | Like arch, os, etc, when we know we are going to use a file, we check that the file has compatible objc constraints to the context, throw appropriate errors where that is not the case, and hopefully set the objc constraints on the context for use later. Added 2 tests to ensure that we don't have incompatibilities between host and simulator code as both will get x86 based architectures. llvm-svn: 258173
* Cache the objc image info constraints in file.Pete Cooper2016-01-193-11/+20
| | | | | | | | | | Image info flags describe the objc constraint which is GC/retain/release/etc. These need to be parsed and stored in the file so that we can do error checking. That will come in a later commit. llvm-svn: 258160
* Only emit files with subsections_via_symbols if all inputs had that set.Pete Cooper2016-01-163-9/+32
| | | | | | | | | | | | When generating a relocatable file, its only valid to set this flag if all of the inputs also had the flag. Otherwise we may atomize incorrectly when we link the relocatable file again. Reviewed by Lang Hames. Differential Revision: http://reviews.llvm.org/D16018 llvm-svn: 257976
* Give error on binaries containing GC objc image infos.Pete Cooper2016-01-161-4/+12
| | | | | | | | The image info struct contains flags for what kind of GC/retain/release is required. Give an error if we parse GC flags as these are unsupported. llvm-svn: 257974
* Add checking of differing swift versions in input files.Pete Cooper2016-01-163-0/+18
| | | | | | | Swift versions are part of the objc image info section, and must match for all files linked which actually have an image info section llvm-svn: 257964
* Check that the objc image info version is exactly 0Pete Cooper2016-01-151-0/+8
| | | | llvm-svn: 257953
* Error check the size of the __objc_imageinfo sectionPete Cooper2016-01-141-0/+44
| | | | llvm-svn: 257841
* Check for mismatched arch and OS when linking MachO files.Pete Cooper2016-01-143-0/+36
| | | | | | | | | | | | This patch makes use of the handleLoadedFile hook added in r257814. That method is used to check the arch and the OS of the files we are linking against the arch and OS on the context. The first test to use this ensures that we do not try to combine i386 Mac OS code with i386 simulator code. llvm-svn: 257837
* Add File::kind's for all subclasses of File.Pete Cooper2016-01-1416-23/+37
| | | | | | | | | | | | This is to enable isa<> support for any files which need it. It will be used in an upcoming patch to differentiate MachOFile from other implicitly generated files. Reviewed by Lang Hames. Differential Revision: http://reviews.llvm.org/D16103 llvm-svn: 257830
* Add handleLoadedFile hook to the context.Pete Cooper2016-01-141-0/+4
| | | | | | | | | | | | | | This is called from the resolver on each file we decide we actually want to use. Future commits will make use of this to extract useful information from the files and do error checking against the context. For example, ensure that files are the same arch as each other. Reviewed by Lang Hames. Differential Revision: http://reviews.llvm.org/D16093 llvm-svn: 257814
* Update for LLVM function name change.Rui Ueyama2016-01-147-33/+28
| | | | llvm-svn: 257801
* [old ELF] Remove AMDGPU targetTom Stellard2016-01-1113-427/+0
| | | | | | | | | | | | Summary: This is no longer needed now that the new ELF implementation supports AMDGPU. Reviewers: ruiu, rafael Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D15954 llvm-svn: 257390
* Always generate the fixup content for unwindFDEToFunction as we noPete Cooper2016-01-071-3/+11
| | | | | | longer emit it. llvm-svn: 257100
* Don't emit relocs for the __eh_frame section as they can be implicit.Pete Cooper2016-01-073-8/+34
| | | | | | | | | | | | | | The __eh_frame section contains relocations which can always be implicitly generated. This patch tracks whether sections have only implicitly relocations and skips emitting them to the object file if that is the case. The test case here ensures that this is the case for __eh_frame sections. Reviewed by Lang Hames. http://reviews.llvm.org/D15594 llvm-svn: 257099
* Set CMake ADDITIONAL_HEADER_DIRS on libraries with headers in /include. NFC.Pete Cooper2016-01-071-0/+4
| | | | | | | | | | | In a UI such as XCode, it can group the headers for a library with that library. This is done in the CMakeLists.txt for the library itself by setting the path(s) as ADDITIONAL_HEADER_DIRS. LLVM already does this for all of its libraries, so just adding this to lld to make things easier. Should be NFC. llvm-svn: 257002
* Set the folder for libraries to 'lld libraries'. NFC.Pete Cooper2016-01-0712-12/+12
| | | | | | | | | | | | In a UI such as XCode, LLVM source files are in 'libraries' while clang files are in 'clang libraries'. This change moves the lld source to 'lld libraries' to make code browsing easier. It should be NFC as the build itself is still the same, just the structure in a UI differs. llvm-svn: 257001
* 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-052-9/+54
| | | | llvm-svn: 256805
* Sort sections in relocatable files.Pete Cooper2016-01-041-102/+62
| | | | | | | | | | | | | | | | | The final section order in relocatable files was just a side effect of the atom sorter. This meant that sections like __data were before __text because __data has RW permissions and __text RX and RW was less than RX in our enum. Final linked images had an actual section/segment sorter. There was no reason for the difference, so simplify a bunch of code and just use the same sorted for everything. Reviewed by Lang Hames. http://reviews.llvm.org/D15868 llvm-svn: 256786
* Fix x86_64 delta*Anon relocs.Pete Cooper2016-01-041-2/+22
| | | | | | | | | | | | | | | | | | The encoded value should be an offset from the fixup location, which means that it should take in to account the fixup offset in its section. We weren't subtracting the base address of the atom, which meant that when we parsed the file again for a round trip, we had 2x the atom address in our target address. I've also improved comments for these to try and describe what is going on. There's no test case right now, as the bug is only exhibited when __data is at a non-zero address in a -r link. A commit will soon sort the sections differently and move __data to after __text. Then these relocations in test/mach-o/parse-data-relocs-x86_64.yaml will test for this bug. llvm-svn: 256779
* 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
* Add more debugging output to MachO lld. NFC.Pete Cooper2015-12-162-0/+25
| | | | | | | In debug builds there's now a dump method on Section and improved printing of atoms. llvm-svn: 255826
* Added some DEBUG() prints to make it clearer what the mach-o passes are ↵Pete Cooper2015-12-161-0/+2
| | | | | | | | | | | | doing. NFC. We had some DEBUG prints these passes, but add more so that its clear where we are dumping things, and what state we are in when we do so. I'll be adding more and more DEBUG printing to try make it easier to observe whats going on without having to attach a debugger. llvm-svn: 255805
* [lld][MachO] Recognize __thread_bss sections as zero-fill and set all theLang Hames2015-12-117-14/+39
| | | | | | | | | appropriate bits. This fixes the remaining clang regression test failures when linking clang with lld on Darwin. llvm-svn: 255390
* Verify that macho-o delta64 relocs have the same offset.Pete Cooper2015-12-102-21/+50
| | | | | | | | | | 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
* [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
OpenPOWER on IntegriCloud