summaryrefslogtreecommitdiffstats
path: root/lld/COFF/InputFiles.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [COFF] Store import symbol pointers as pointers to the base classMartin Storsjo2018-07-101-1/+2
| | | | | | | | | | | | | | | Future symbol insertions can potentially change the type of these symbols - keep pointers to the base class to reflect this, and use dynamic casts to inspect them before using as the subclass type. This fixes crashes that were possible before, by touching these symbols that now are populated as e.g. a DefinedRegular, via the old pointers with DefinedImportThunk type. Differential Revision: https://reviews.llvm.org/D48953 llvm-svn: 336652
* COFF: Add a flag for disabling string tail merging.Peter Collingbourne2018-05-111-2/+2
| | | | | | | | | | | We discovered (crbug.com/838449#c24) that string tail merging can negatively affect compressed binary size, so provide a flag to turn it off for users who care more about compressed size than uncompressed size. Differential Revision: https://reviews.llvm.org/D46780 llvm-svn: 332149
* [COFF] more informative "broken object file" diagnosticsBob Haarman2018-04-251-5/+4
| | | | | | | | | | | | | | | | | | Summary: When a symbol refers to a special section or a section that doesn't exist, lld would fatal with "broken object file". This change gives a different message for each scenario, and includes the name of the file, name of the symbol, and the section being referred to. Reviewers: pcc, ruiu Reviewed By: ruiu Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D46090 llvm-svn: 330883
* COFF: Friendlier undefined symbol errors.Peter Collingbourne2018-04-171-2/+2
| | | | | | | | | | | | | | | Summary: This change does three things: - Try to find the file and line number of an undefined symbol reference by reading codeview debug info. - Try to find the name of the function or global variable with the undefined symbol reference by searching the object file's symbol table. - Prints the information in the same style as the ELF linker. Differential Revision: https://reviews.llvm.org/D45467 llvm-svn: 330235
* Remove references to old SymbolBody classSam Clegg2018-04-111-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D45400 llvm-svn: 329846
* COFF: Implement string tail merging.Peter Collingbourne2018-03-151-4/+11
| | | | | | | | | | | | | | | | | | In COFF, duplicate string literals are merged by placing them in a comdat whose leader symbol name contains a specific prefix followed by the hash and partial contents of the string literal. This gives us an easy way to identify sections containing string literals in the linker: check for leader symbol names with the given prefix. Any sections that are identified in this way as containing string literals may be tail merged. We do so using the StringTableBuilder class, which is also used to tail merge string literals in the ELF linker. Tail merging is enabled only if ICF is enabled, as this provides a signal as to whether the user cares about binary size. Differential Revision: https://reviews.llvm.org/D44504 llvm-svn: 327668
* [LLD] Implement /guard:[no]longjmpReid Kleckner2018-02-131-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This protects calls to longjmp from transferring control to arbitrary program points. Instead, longjmp calls are limited to the set of registered setjmp return addresses. This also implements /guard:nolongjmp to allow users to link in object files that call setjmp that weren't compiled with /guard:cf. In this case, the linker will approximate the set of address taken functions, but it will leave longjmp unprotected. I used the following program to test, compiling it with different -guard flags: $ cl -c t.c -guard:cf $ lld-link t.obj -guard:cf #include <setjmp.h> #include <stdio.h> jmp_buf buf; void g() { printf("before longjmp\n"); fflush(stdout); longjmp(buf, 1); } void f() { if (setjmp(buf)) { printf("setjmp returned non-zero\n"); return; } g(); } int main() { f(); printf("hello world\n"); } In particular, the program aborts when the code is compiled *without* -guard:cf and linked with -guard:cf. That indicates that longjmps are protected. Reviewers: ruiu, inglorion, amccarth Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D43217 llvm-svn: 325047
* [COFF] Add minimal support for /guard:cfReid Kleckner2018-02-061-12/+6
| | | | | | | | | | | | | | | | | | | 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
* Remove checkToString functions and use toString instead.Rui Ueyama2017-12-071-2/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D40928 llvm-svn: 320005
* [COFF] Stop lowercasing paths in messagesShoaib Meenai2017-12-071-5/+4
| | | | | | | | | | | | It's pretty annoying to have LLD lowercase paths in error messages when cross-compiling from a case-sensitive filesystem, since e.g. if I want to examine the problematic object file, I have to perform some manual case correction instead of just being able to copy the path from the error message. Differential Revision: https://reviews.llvm.org/D40931 llvm-svn: 319996
* Always evaluate the second argument for CHECK() lazily.Rui Ueyama2017-12-061-5/+5
| | | | | | | | | This patch is to rename check CHECK and make it a C macro, so that we can evaluate the second argument lazily. Differential Revision: https://reviews.llvm.org/D40915 llvm-svn: 319974
* toString function take a const refs where possibleSam Clegg2017-12-051-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D40824 llvm-svn: 319787
* COFF: Simplify construction of safe SEH table. NFCI.Peter Collingbourne2017-11-281-16/+6
| | | | | | | | | Instead of building intermediate sets of exception handlers for each object file, just create one for the final output file. Differential Revision: https://reviews.llvm.org/D40581 llvm-svn: 319244
* COFF: Do not add symbols in discarded sections to SEH handler list.Peter Collingbourne2017-11-281-1/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D40576 llvm-svn: 319229
* Move Memory.{h,cpp} to Common.Rui Ueyama2017-11-281-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D40571 llvm-svn: 319221
* Reland r319090, "COFF: Do not create SectionChunks for discarded comdat ↵Peter Collingbourne2017-11-281-85/+178
| | | | | | | | | | | | | | 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
* Consistent use of <internal> when displaying internal symbol namesSam Clegg2017-11-271-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D40510 llvm-svn: 319108
* Revert r319090, "COFF: Do not create SectionChunks for discarded comdat ↵Peter Collingbourne2017-11-271-177/+85
| | | | | | | | | 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-85/+177
| | | | | | | | | | | | | | | | | | | | 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: Remove the SymbolBodies vector, and rename SparseSymbolBodies to Symbols.Peter Collingbourne2017-11-201-8/+4
| | | | | | Differential Revision: https://reviews.llvm.org/D40237 llvm-svn: 318683
* COFF: Change SparseChunks to be of type std::vector<SectionChunk *>. NFC.Peter Collingbourne2017-11-201-3/+2
| | | | llvm-svn: 318636
* [COFF] Avoid "Body" as a local variable name.Rui Ueyama2017-11-031-15/+15
| | | | | | | 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-11/+11
| | | | | | | | | | | | | 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
* [COFF] Merge Symbol and SymbolBody.Rui Ueyama2017-10-311-10/+10
| | | | llvm-svn: 317007
* [lld] unified COFF and ELF error handling on new Common/ErrorHandlerBob Haarman2017-10-251-4/+3
| | | | | | | | | | | | | | | | | | | 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
* Update for llvm change.Rafael Espindola2017-10-111-5/+2
| | | | llvm-svn: 315478
* COFF: simplify thunk handling (NFC)Saleem Abdulrasool2017-09-011-6/+3
| | | | | | | | | Apply the simplification suggestions that Peter Collingbourne made during the review at D37368. The returned thunk is cast to the appropriate type in the SymbolTable, and the constant symbol's body is not needed directly, so avoid the assignment. NFC llvm-svn: 312391
* COFF: handle multiply defined symbols with different storageSaleem Abdulrasool2017-09-011-8/+8
| | | | | | | | | | | | | | If a symbol is locally defined and is DLL imported in another translation unit, and the object with the locally defined version is loaded prior to the imported version, then the linker will fail to resolve the definition of the thunk and return the locally defined symbol. This will then be attempted to be cast to an import thunk, which will clearly fail. Only return the thunk if the symbol is inserted or a thunk is created. Otherwise, report a duplication error. llvm-svn: 312386
* Revert r312171: Support nested static libraries.Rui Ueyama2017-08-301-6/+0
| | | | | | | | This reverts commit r312171 because it is pointed out that that's not a correct fix (see https://bugs.llvm.org/show_bug.cgi?id=32674#c14) and also because it broke buildbots. llvm-svn: 312174
* Support nested static libraries.Rui Ueyama2017-08-301-0/+6
| | | | | | | | | | MSVC link.exe supports nested static libraries. That is, an .a file can contain other .a file as its member. It is reported that MySQL actually depends on this feature. Fixes https://bugs.llvm.org/show_bug.cgi?id=32674 llvm-svn: 312171
* Move a function from Driver.cpp to InputFile.cpp.Rui Ueyama2017-08-301-0/+19
| | | | | | | This patch doesn't improve code per se, but it should make the following patch's diff easier to read. llvm-svn: 312170
* Add {Obj,Import,Bitcode}File::Instances to COFF input files.Rui Ueyama2017-07-271-0/+4
| | | | | | | We did the same thing for ELF in r309152, and I want to maintain COFF and ELF as close as possible. llvm-svn: 309239
* Rename ObjectFile ObjFile for COFF as well.Rui Ueyama2017-07-261-8/+8
| | | | llvm-svn: 309228
* [COFF] Add initial support for linking ARM64 binariesMartin Storsjo2017-07-011-0/+2
| | | | | | | | | A plain empty entry point function that returns 0 seems to produce a binary that loads and runs fine in wine. Differential Revision: https://reviews.llvm.org/D34833 llvm-svn: 306963
* [PDB] Don't emit debug info associated with dead chunksReid Kleckner2017-06-201-8/+8
| | | | | | | | | | | | | | Summary: Previously we didn't add debug info chunks to the SparseChunks array, so they didn't participate in section GC. Now we do. Reviewers: ruiu Subscribers: aprantl, llvm-commits Differential Revision: https://reviews.llvm.org/D34356 llvm-svn: 305811
* [COFF] Drop unused comdat sections when GC is turned offReid Kleckner2017-06-161-1/+5
| | | | | | | | | | | | | | | | | 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
* Make key-value types explicit. NFC.Rui Ueyama2017-05-241-3/+8
| | | | llvm-svn: 303776
* Change the control flow so that the function is a bit more readable. NFC.Rui Ueyama2017-05-241-6/+4
| | | | llvm-svn: 303775
* Revert r303304: Re-submit r303225: Garbage collect dllimported symbols.Rui Ueyama2017-05-221-10/+1
| | | | | | | | This reverts commit r303304 because it looks like the change introduced a crash bug. At least after that change, LLD with thinlto crashes when linking Chromium. llvm-svn: 303527
* Use make<> everywhere in COFF to make it consistent with ELF.Rui Ueyama2017-05-181-8/+8
| | | | | | | | | We've been using make<> to allocate new objects in ELF. We have the same function in COFF, but we didn't use it widely due to negligence. This patch uses the function in COFF to close the gap between ELF and COFF. llvm-svn: 303357
* Re-submit r303225: Garbage collect dllimported symbols.Rui Ueyama2017-05-171-1/+10
| | | | | | | | | | This reverts re-submits r303225 which was reverted in r303270 because it broke the sanitizer-windows bot. The reason of the failure is that we were writing dead symbols to the symbol table. I fixed the issue. llvm-svn: 303304
* Revert r303225 "Garbage collect dllimported symbols."Hans Wennborg2017-05-171-10/+1
| | | | | | | | | | | | | | | | | | | | | | | | | and follow-up r303226 "Fix Windows buildbots." This broke the sanitizer-windows buildbot. > Previously, the garbage collector (enabled by default or by explicitly > passing /opt:ref) did not kill dllimported symbols. As a result, > dllimported symbols could be added to resulting executables' dllimport > list even if no one was actually using them. > > This patch implements dllexported symbol garbage collection. Just like > COMDAT sections, dllimported symbols now have Live bits to manage their > liveness, and MarkLive marks reachable dllimported symbols. > > Fixes https://bugs.llvm.org/show_bug.cgi?id=32950 > > Reviewers: pcc > > Subscribers: llvm-commits > > Differential Revision: https://reviews.llvm.org/D33264 llvm-svn: 303270
* Garbage collect dllimported symbols.Rui Ueyama2017-05-171-1/+10
| | | | | | | | | | | | | | | | | | | | | | Summary: Previously, the garbage collector (enabled by default or by explicitly passing /opt:ref) did not kill dllimported symbols. As a result, dllimported symbols could be added to resulting executables' dllimport list even if no one was actually using them. This patch implements dllexported symbol garbage collection. Just like COMDAT sections, dllimported symbols now have Live bits to manage their liveness, and MarkLive marks reachable dllimported symbols. Fixes https://bugs.llvm.org/show_bug.cgi?id=32950 Reviewers: pcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D33264 llvm-svn: 303225
* COFF: actually synthesize CONST imports properlySaleem Abdulrasool2017-04-281-0/+3
| | | | | | | | | | CONSTANT imports expect both the `_imp_` prefixed and non-prefixed symbols should be added to the symbol table. This allows for linking symbols like _NSConcreteGlobalBlock in WinObjC. The previous change would generate the import library properly by handling the option but would not consume the generated entry properly. llvm-svn: 301657
* Object, LTO: Add target triple to irsymtab and LTO API.Peter Collingbourne2017-04-141-5/+1
| | | | | | | | | | Start using it in LLD to avoid needing to read bitcode again just to get the target triple, and in llvm-lto2 to avoid printing symbol table information that is inappropriate for the target. Differential Revision: https://reviews.llvm.org/D32038 llvm-svn: 300300
* Re-apply r299168 and r299169 now that the libdeps are fixed.Peter Collingbourne2017-03-311-3/+2
| | | | llvm-svn: 299184
* Revert r299168 and r299169 due to library dependency issues.Peter Collingbourne2017-03-311-2/+3
| | | | | | http://bb.pgr.jp/builders/i686-mingw32-RA-on-linux/builds/25073/steps/build_llvmclang/logs/stdio llvm-svn: 299171
* LTO: Reduce memory consumption by creating an in-memory symbol table for ↵Peter Collingbourne2017-03-311-3/+2
| | | | | | | | | | | | | | | | | | | | | | | InputFiles. NFCI. Introduce symbol table data structures that can be potentially written to disk, have the LTO library build those data structures using temporarily constructed modules and redirect the LTO library implementation to go through those data structures. This allows us to remove the LLVMContext and Modules owned by InputFile. With this change I measured a peak memory consumption decrease from 5.4GB to 2.8GB in a no-op incremental ThinLTO link of Chromium on Linux. The impact on memory consumption is larger in COFF linkers where we are currently forced to materialize all metadata in order to read linker options. Peak memory consumption linking a large piece of Chromium for Windows with full LTO and debug info decreases from >64GB (OOM) to 15GB. Part of PR27551. Differential Revision: https://reviews.llvm.org/D31364 llvm-svn: 299168
* LTO: Replace InputFile::Symbol::getFlags() with predicate accessors. NFC.Peter Collingbourne2017-03-281-5/+3
| | | | | | | This makes the predicates independent of the flag representation and makes the code a little easier to read. llvm-svn: 298951
OpenPOWER on IntegriCloud