summaryrefslogtreecommitdiffstats
path: root/lld/COFF/Chunks.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Factor out common code from applySecRel functions.Rui Ueyama2018-02-171-24/+29
| | | | | | Differential Revision: https://reviews.llvm.org/D43412 llvm-svn: 325444
* [COFF] Add support for ARM64 secrel relocations for add/load instructionsMartin Storsjo2018-02-161-0/+31
| | | | | | Differential Revision: https://reviews.llvm.org/D43287 llvm-svn: 325396
* [COFF] Add minimal support for /guard:cfReid Kleckner2018-02-061-3/+5
| | | | | | | | | | | | | | | | | | | Summary: This patch adds some initial support for Windows control flow guard. At the end of the day, the linker needs to synthesize a table of RVAs very similar to the structured exception handler table (/safeseh). Both /safeseh and /guard:cf take sections of symbol table indices (.sxdata and .gfids$y) and turn them into RVA tables referenced by the load config struct in the CRT through special symbols. Reviewers: ruiu, amccarth Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D42592 llvm-svn: 324306
* [COFF] Error out if 20 bit thumb branches are out of rangeMartin Storsjo2017-12-141-0/+2
| | | | | | | | | This is similar to what was added in SVN r277838 for 24 bit branch instructions. Differential Revision: https://reviews.llvm.org/D41163 llvm-svn: 320677
* Reland r319090, "COFF: Do not create SectionChunks for discarded comdat ↵Peter Collingbourne2017-11-281-9/+2
| | | | | | | | | | | | | | sections." with a fix for debug sections. If /debug was not specified, readSection will return a null pointer for debug sections. If the debug section is associative with another section, we need to make sure that the section returned from readSection is not a null pointer before adding it as an associative section. Differential Revision: https://reviews.llvm.org/D40533 llvm-svn: 319133
* Revert r319090, "COFF: Do not create SectionChunks for discarded comdat ↵Peter Collingbourne2017-11-271-2/+9
| | | | | | | | | sections." Caused test failures in check-cfi on Windows. http://lab.llvm.org:8011/builders/sanitizer-windows/builds/20284 llvm-svn: 319100
* COFF: Do not create SectionChunks for discarded comdat sections.Peter Collingbourne2017-11-271-9/+2
| | | | | | | | | | | | | | | | | | | | With this change, instead of creating a SectionChunk for each section in the object file, we only create them when we encounter a prevailing comdat section. Also change how symbol resolution occurs between comdat symbols. Now only the comdat leader participates in comdat resolution, and not any other external associated symbols. This is more in line with how COFF semantics are defined, and should allow for a more straightforward implementation of non-ANY comdat types. On my machine, this change reduces our runtime linking a release build of chrome_child.dll with /nopdb from 5.65s to 4.54s (median of 50 runs). Differential Revision: https://reviews.llvm.org/D40238 llvm-svn: 319090
* COFF: Correctly handle relocations against early discarded sections.Peter Collingbourne2017-11-201-2/+15
| | | | | | | | | | | Don't crash if we encounter a reference to an early discarded section (such as .drectve). Instead, handle them the same way as sections discarded by comdat merging, i.e. either print an error message or (for debug sections) silently ignore the relocation. Differential Revision: https://reviews.llvm.org/D40235 llvm-svn: 318689
* [COFF] Add support for IMAGE_REL_ARM64_SECRELMartin Storsjo2017-11-081-0/+1
| | | | | | | | | | | I never ran into this until lld-link started enabling debug output by default for the mingw mode. I haven't been able to verify that this actually behaves correctly, but this relocation is handled identically on all other architectures so far. Differential Revision: https://reviews.llvm.org/D39754 llvm-svn: 317669
* [COFF] Handle ARM64 in getDefaultTypeMartin Storsjo2017-11-061-0/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D39634 llvm-svn: 317455
* [COFF] Avoid "Body" as a local variable name.Rui Ueyama2017-11-031-4/+2
| | | | | | | Since SymbolBody is gone, "Body" is not a good variable name. This patch renames or eliminates them. llvm-svn: 317384
* Rename SymbolBody -> SymbolRui Ueyama2017-11-031-2/+2
| | | | | | | | | | | | | Now that we have only SymbolBody as the symbol class. So, "SymbolBody" is a bit strange name now. This is a mechanical change generated by perl -i -pe s/SymbolBody/Symbol/g $(git grep -l SymbolBody lld/ELF lld/COFF) nd clang-format-diff. Differential Revision: https://reviews.llvm.org/D39459 llvm-svn: 317370
* [lld] unified COFF and ELF error handling on new Common/ErrorHandlerBob Haarman2017-10-251-1/+1
| | | | | | | | | | | | | | | | | | | Summary: The COFF linker and the ELF linker have long had similar but separate Error.h and Error.cpp files to implement error handling. This change introduces new error handling code in Common/ErrorHandler.h, changes the COFF and ELF linkers to use it, and removes the old, separate implementations. Reviewers: ruiu Reviewed By: ruiu Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits Differential Revision: https://reviews.llvm.org/D39259 llvm-svn: 316624
* [COFF] Implement support for IMAGE_REL_ARM64_ADDR32NBMartin Storsjo2017-10-121-0/+1
| | | | | | | | | This is implemented in the same way as the other ADDR32NB relocations for ARM and X64. Differential Revision: https://reviews.llvm.org/D38815 llvm-svn: 315561
* [COFF] Adjust secrel limit checkShoaib Meenai2017-09-201-1/+4
| | | | | | | | | | | | | | | According to Microsoft's PE/COFF documentation, a SECREL relocation is "The 32-bit offset of the target from the beginning of its section". By my reading, the "from the beginning of its section" implies that the offset is unsigned. Change from an assertion to an error, since it's possible to trigger this condition normally for input files with very large sections, and we should fail gracefully for those instead of asserting. Differential Revision: https://reviews.llvm.org/D38020 llvm-svn: 313703
* Remove {get,set}Align accessor functions and use Alignment member variable ↵Rui Ueyama2017-09-131-7/+3
| | | | | | instead. llvm-svn: 313204
* [COFF] Add support for aligncomm directivesMartin Storsjo2017-08-141-0/+4
| | | | | | | | | | | | | | These are emitted for comm symbols in object files, when targeting a GNU environment. Alternatively, just ignore them since we already align CommonChunk to the natural size of the content (up to 32 bytes). That would only trade away the possibility to overalign small symbols, which doesn't sound like something that might not need to be handled? Differential Revision: https://reviews.llvm.org/D36304 llvm-svn: 310871
* Rename ObjectFile ObjFile for COFF as well.Rui Ueyama2017-07-261-1/+1
| | | | llvm-svn: 309228
* [COFF, ARM64] Handle ADRP immediate offsets in relocationsMartin Storsjo2017-07-261-9/+25
| | | | | | | | | | | | Also handle overflow correctly in LDR/STR relocations. Even if the offset range of a 8 byte LDR instruction is 15 bit (even if the immediate itself is 12 bit) due to a 3 bit shift, only include up to 12 bits of offset after doing the relocation, by limiting the range of the immediate by the number of shifted bits. Differential Revision: https://reviews.llvm.org/D35792 llvm-svn: 309175
* [COFF] Add support for delay loading DLLs on ARMMartin Storsjo2017-07-251-2/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D35768 llvm-svn: 309017
* [COFF] Support 128 bit SIMD/FP ldr/str in IMAGE_REL_ARM64_PAGEOFFSET_12LMartin Storsjo2017-07-201-1/+6
| | | | | | | | | | Also extend the tests for IMAGE_REL_ARM64_PAGEOFFSET_12L to test all 8/16/32/64 bit GPR and 8/16/32/64/128 SIMD/FP bit ldr/str variants, and a ldr with an existing offset. Differential revision: https://reviews.llvm.org/D35647 llvm-svn: 308631
* [COFF] Minor tweaks to ARM64 relocation code. NFC.Martin Storsjo2017-07-201-3/+2
| | | | | | | | | | | Fix issues found in existing code, while reviewing other changes. Change the data type of a variable to uint32_t, to avoid potential issues with signedness in shifts. Differential revision: https://reviews.llvm.org/D35646 llvm-svn: 308586
* [COFF] Align import address chunks to the pointer sizeMartin Storsjo2017-07-201-0/+2
| | | | | | | | | | | | | | This fixes cases on ARM64 when importing from more than one DLL, in case the imports from the first DLL ended up unaligned. When fixing up a IMAGE_REL_ARM64_PAGEOFFSET_12L, which shifts the offset by the load/store size, check that the shift doesn't discard any bits. (This would also detect if the import address chunks were unaligned.) Differential revision: https://reviews.llvm.org/D35640 llvm-svn: 308585
* [COFF] Accept discarded relocations in DWARF debug sectionsShoaib Meenai2017-07-181-1/+1
| | | | | | | | | DWARF debug sections can also contain relocations against symbols in discared segments. LLD should accept such relocations. Differential Revision: https://reviews.llvm.org/D35526 llvm-svn: 308315
* [COFF] Bounds check relocationsReid Kleckner2017-07-131-0/+8
| | | | | | | | | | | | | | | | | | Summary: This would have caught the invalid object file I used in my test case in r307726. The OOB was only caught by ASan later, which is slow and doesn't work on some platforms. LLD should do some basic input validation itself. This check isn't perfect, so relocations can reach OOB by up to seven bytes, but it's better than what we had and probably cheap. Reviewers: ruiu Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D35371 llvm-svn: 307948
* [COFF] Add initial support for some ARM64 relocations and import thunksMartin Storsjo2017-07-111-0/+51
| | | | | | | | | | This is enough to link a working hello world executable, with a call to an imported function, a string constant passed to the imported function, and loads from a global variable. Differential Revision: https://reviews.llvm.org/D34964 llvm-svn: 307629
* [COFF] Allow debug info to relocate against discarded symbolsReid Kleckner2017-06-281-32/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: In order to do this without switching on the symbol kind multiple times, I created Defined::getChunkAndOffset and use that instead of SymbolBody::getRVA in the inner relocation loop. Now we get the symbol's chunk before switching over relocation types, so we can test if it has been discarded outside the inner relocation type switch. This also simplifies application of section relative relocations. Previously we would switch on symbol kind to compute the RVA, then the relocation type, and then the symbol kind again to get the output section so we could subtract that from the symbol RVA. Now we *always* have an OutputSection, so applying SECREL and SECTION relocations isn't as much of a special case. I'm still not quite happy with the cleanliness of this code. I'm not sure what offsets and bases we should be using during the relocation processing loop: VA, RVA, or OutputSectionOffset. Reviewers: ruiu, pcc Reviewed By: ruiu Subscribers: majnemer, inglorion, llvm-commits, aprantl Differential Revision: https://reviews.llvm.org/D34650 llvm-svn: 306566
* [COFF] Fix SECTION and SECREL relocation handling for absolute symbolsReid Kleckner2017-06-221-3/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: For SECTION relocations against absolute symbols, MSVC emits the largest output section index plus one. I've implemented that by threading a global variable through DefinedAbsolute that is filled in by the Writer. A more library-oriented approach would be to thread the Writer through Chunk::writeTo and SectionChunk::applyRel*, but Rui seems to prefer doing it this way. MSVC rejects SECREL relocations against absolute symbols, but only when the relocation is in a real output section. When the relocation is in a CodeView debug info section destined for the PDB, it seems that this relocation error is suppressed, and absolute symbols become zeros in the object file. This is easily implemented by checking the input section from which we're applying relocations. This should fix errors about __safe_se_handler_table and __guard_fids_table when linking the CRT and generating a PDB. Reviewers: ruiu Subscribers: aprantl, llvm-commits Differential Revision: https://reviews.llvm.org/D34541 llvm-svn: 306071
* [COFF] Drop unused comdat sections when GC is turned offReid Kleckner2017-06-161-4/+14
| | | | | | | | | | | | | | | | | Summary: Adds a "Discarded" bool to SectionChunk to indicate if the section was discarded by COMDAT deduplication. The Writer still just checks `isLive()`. Fixes PR33446 Reviewers: ruiu Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D34288 llvm-svn: 305582
* Move Object format code to lib/BinaryFormat.Zachary Turner2017-06-071-1/+1
| | | | | | | | | | | | This creates a new library called BinaryFormat that has all of the headers from llvm/Support containing structure and layout definitions for various types of binary formats like dwarf, coff, elf, etc as well as the code for identifying a file from its magic. Differential Revision: https://reviews.llvm.org/D33843 llvm-svn: 304864
* Fix comments again.Rui Ueyama2017-04-261-24/+21
| | | | | | | | I thought I fixed the page size, but there were still errors. This patch also contains fixes for grammatical errors. Thanks pcc for proofreading! llvm-svn: 301454
* Fix comment.Rui Ueyama2017-04-261-2/+2
| | | | llvm-svn: 301450
* Add comments about Widnows .reloc section.Rui Ueyama2017-04-251-2/+42
| | | | llvm-svn: 301287
* Do not use errs() or outs() directly. Instead use message(), log() or error()Rui Ueyama2017-02-211-1/+1
| | | | | | | | | LLD is a multi-threaded program. errs() or outs() are not guaranteed to be thread-safe (they are actually not). LLD's message(), log() or error() are thread-safe. We should use them. llvm-svn: 295787
* COFF: include relocation type in unsupported relocation messageBob Haarman2017-01-131-3/+4
| | | | | | | | | | Summary: When we encouter a relocation type we don't know how to handle, this change causes us to print out the hexadecimal value of the relocation type. This makes troubleshooting a little easier. Reviewers: ruiu, zturner Differential Revision: https://reviews.llvm.org/D28576 llvm-svn: 291962
* COFF: New symbol table design.Peter Collingbourne2016-12-091-2/+2
| | | | | | | | | This ports the ELF linker's symbol table design, introduced in r268178, to the COFF linker. Differential Revision: http://reviews.llvm.org/D21166 llvm-svn: 289280
* Remove unnecessary `llvm::`.Rui Ueyama2016-12-081-1/+1
| | | | llvm-svn: 289102
* Emit Section Contributions.Rui Ueyama2016-11-121-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D26211 llvm-svn: 286684
* [lld/COFF] Don't round alignment if it's already a power-of-two.Davide Italiano2016-11-111-1/+1
| | | | | | | | This matches link.exe behaviour. Differential Revision: https://reviews.llvm.org/D26372 llvm-svn: 286553
* [COFF] Add support for IMAGE_REL_ARM_SECRELMartin Storsjo2016-09-271-0/+1
| | | | | | | | | Handle this in the exact same way as IMAGE_REL_AMD64_SECREL and IMAGE_REL_I386_SECREL. Differential revision: https://reviews.llvm.org/D24608 llvm-svn: 282531
* COFF ARM: Apply an existing offset in MOV32T relocationsSaleem Abdulrasool2016-08-051-2/+14
| | | | | | | | | | | Don't blindly OR in the new value, but clear the existing one, since it can be nonzero. Read out the existing value before, and add into the desired offset. (The add is done outside of the applyMOV, to handle potential overflow between the two.) Patch by Martin Storsjö! llvm-svn: 277846
* COFF ARM: Error out if 24 bit thumb branches are out of rangeSaleem Abdulrasool2016-08-051-0/+2
| | | | | | | | | In the ELF linker, the same situation already errors out with "relocation R_ARM_THM_CALL out of range". Patch by Martin Storsjö! llvm-svn: 277838
* COFF ARM: Clear the J1 and J2 bits when applying relocations to 24 bit branchesSaleem Abdulrasool2016-08-051-1/+2
| | | | | | | | | | The opcode for the bl branches can initially be F000 F800, i.e. the J1 and J2 bits are already set. Therefore mask these bits out before or'ing in the new bits. Patch by Martin Storsjö! llvm-svn: 277836
* COFF: Update error messages so that they start with lowercase letters.Rui Ueyama2016-07-151-3/+3
| | | | llvm-svn: 275513
* COFF: Rename noreturn error -> fatal.Rui Ueyama2016-07-141-3/+3
| | | | | | This new name is also consistent with ELF. llvm-svn: 275500
* [COFF] Use coff_section::getAlignmentDavid Majnemer2016-03-171-4/+1
| | | | | | | Use LLVM's section alignment calculation instead of having LLD calculate it. llvm-svn: 263724
* Update for LLVM function name change.Rui Ueyama2016-01-141-1/+1
| | | | llvm-svn: 257801
* COFF: Rename RoundUpToAlignment -> align.Rui Ueyama2016-01-081-1/+1
| | | | llvm-svn: 257220
* COFF: Rename Ptr -> Repl.Rui Ueyama2015-09-251-3/+3
| | | | | | This pointer points to a replacement for this chunk. Ptr was not a good name. llvm-svn: 248579
* COFF: Rename A.replaceWith(B) -> B.replace(A). NFC.Rui Ueyama2015-09-211-3/+3
| | | | llvm-svn: 248197
OpenPOWER on IntegriCloud