summaryrefslogtreecommitdiffstats
path: root/lld/COFF/Driver.h
Commit message (Collapse)AuthorAgeFilesLines
* lld-link: Add a flag /lldignoreenv that makes lld-link ignore env vars.Nico Weber2019-09-131-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | This is useful for enforcing that builds are independent of the environment; it can be used when all system library paths are added via /libpath: already. It's similar ot cl.exe's /X flag. Since it should also affect %LINK% (the other caller of `Process::GetEnv` in lld/COFF), the early-option-parsing needs to move around a bit. The options are: - Add a manual loop over the argv ArrayRef and look for "/lldignoreenv". This repeats the name of the flag in both Options.td and in DriverUtils.cpp. - Add yet another table.ParseArgs() call just for /lldignoreenv before adding %LINK%. - Use the existing early ParseArgs() that's there for --rsp-quoting and use it for /lldignoreenv for %LINK% as well. This means --rsp-quoting and /lldignoreenv can't be passed via %LINK%. I went with the third approach. Differential Revision: https://reviews.llvm.org/D67456 llvm-svn: 371852
* reland "[lld-link] implement -start-lib and -end-lib"Bob Haarman2019-09-031-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This is a re-land of r370487 with a fix for the use-after-free bug that rev contained. This implements -start-lib and -end-lib flags for lld-link, analogous to the similarly named options in ld.lld. Object files after -start-lib are included in the link only when needed to resolve undefined symbols. The -end-lib flag goes back to the normal behavior of always including object files in the link. This mimics the semantics of static libraries, but without needing to actually create the archive file. Reviewers: ruiu, smeenai, MaskRay Reviewed By: ruiu, MaskRay Subscribers: akhuang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66848 llvm-svn: 370816
* Revert "[lld-link] implement -start-lib and -end-lib"Vlad Tsyrklevich2019-08-301-3/+2
| | | | | | | This reverts commit r370487 as it is causing ASan/MSan failures on sanitizer-x86_64-linux-fast llvm-svn: 370550
* [lld-link] implement -start-lib and -end-libBob Haarman2019-08-301-2/+3
| | | | | | | | | | | | | | | | | | | | | | | Summary: This implements -start-lib and -end-lib flags for lld-link, analogous to the similarly named options in ld.lld. Object files after -start-lib are included in the link only when needed to resolve undefined symbols. The -end-lib flag goes back to the normal behavior of always including object files in the link. This mimics the semantics of static libraries, but without needing to actually create the archive file. Reviewers: ruiu, smeenai, MaskRay Reviewed By: ruiu, MaskRay Subscribers: akhuang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66848 llvm-svn: 370487
* [LLD] [COFF] Support merging resource object filesMartin Storsjo2019-08-301-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | Extend WindowsResourceParser to support using a ResourceSectionRef for loading resources from an object file. Only allow merging resource object files in mingw mode; keep the existing error on multiple resource objects in link mode. If there only is one resource object file and no .res resources, don't parse and recreate the .rsrc section, but just link it in without inspecting it. This allows users to produce any .rsrc section (outside of what the parser supports), just like before. (I don't have a specific need for this, but it reduces the risk of this new feature.) Separate out the .rsrc section chunks in InputFiles.cpp, and only include them in the list of section chunks to link if we've determined that there only was one single resource object. (We need to keep other chunks from those object files, as they can legitimately contain other sections as well, in addition to .rsrc section chunks.) Differential Revision: https://reviews.llvm.org/D66824 llvm-svn: 370436
* lld-link: Demangle symbols from archives in diagnosticsNico Weber2019-07-191-1/+1
| | | | | | | | | Also add test coverage for thin archives (which are the only way I could come up with to test at least some of the diagnostic changes). Differential Revision: https://reviews.llvm.org/D64927 llvm-svn: 366573
* [Coding style change][lld] Rename variables for non-ELF portsRui Ueyama2019-07-111-48/+48
| | | | | | | | | | | This patch does the same thing as r365595 to other subdirectories, which completes the naming style change for the entire lld directory. With this, the naming style conversion is complete for lld. Differential Revision: https://reviews.llvm.org/D64473 llvm-svn: 365730
* llvm-lib: Implement /machine: argumentNico Weber2019-06-111-4/+0
| | | | | | | | | | And share some code with lld-link. While here, also add a FIXME about PR42180 and merge r360150 to llvm-lib. Differential Revision: https://reviews.llvm.org/D63021 llvm-svn: 363016
* [COFF] Fix /export:foo=bar when bar is a weak aliasReid Kleckner2019-06-071-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: When handling exports from the command line or from .def files, the linker does a "fuzzy" string lookup to allow finding mangled symbols. However, when the symbol is re-exported under a new name, the linker has to transfer the decorations from the exported symbol over to the new name. This is implemented by taking the mangled symbol that was found in the object and replacing the original symbol name with the export name. Before this patch, LLD implemented the fuzzy search by adding an undefined symbol with the unmangled name, and then during symbol resolution, checking if similar mangled symbols had been added after the last round of symbol resolution. If so, LLD makes the original symbol a weak alias of the mangled symbol. Later, to get the original symbol name, LLD would look through the weak alias and forward it on to the import library writer, which copies the symbol decorations. This approach doesn't work when bar is itself a weak alias, as is the case in asan. It's especially bad when the aliasee of bar contains the string "bar", consider "bar_default". In this case, we would end up exporting the symbol "foo_default" when we should've exported just "foo". To fix this, don't look through weak aliases to find the mangled name. Save the mangled name earlier during fuzzy symbol lookup. Fixes PR42074 Reviewers: mstorsjo, ruiu Subscribers: thakis, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62984 llvm-svn: 362849
* Re-land [LLD][COFF] Early load PDB type server filesAlexandre Ganea2019-06-031-2/+2
| | | | | | | | | | We need to have all input files ready before doing debuginfo type merging. This patch is moving the late PDB type server discovery much earlier in the process, when the explicit inputs (OBJs, LIBs) are loaded. The short term goal is to parallelize type merging. Differential Revision: https://reviews.llvm.org/D60095 llvm-svn: 362393
* Revert r361842 as it breaks LLDB :: tools/lldb-mi/exec/exec-finish.testAlexandre Ganea2019-05-281-2/+2
| | | | llvm-svn: 361876
* [LLD][COFF] Early load PDB type server filesAlexandre Ganea2019-05-281-2/+2
| | | | | | | | | | We need to have all input files ready before doing debuginfo type merging. This patch is moving the late PDB type server discovery much earlier in the process, when the explicit inputs (OBJs, LIBs) are loaded. The short term goal is to parallelize type merging. Differential Revision: https://reviews.llvm.org/D60095 llvm-svn: 361842
* lld-link: Implement /swaprun: flagNico Weber2019-04-251-0/+3
| | | | | | | | | | | | | | | | r191276 added this to old LLD, but it never made it to new LLD -- except that the flag was in Options.td, so it was silently ignored. I figured it should be easy to implement, so I did that instead of removing the flags from Options.td. I then discovered that link.exe also supports comma-separated lists of 'cd' and 'net', which made the parsing code a bit annoying. The Alias technique in Options.td is to get nice help output. Differential Revision: https://reviews.llvm.org/D61067 llvm-svn: 359192
* [LLD][COFF] use offset in archive to disambiguate archive membersBob Haarman2019-04-151-1/+1
| | | | | | | | | | | | | | | | | | | | | Summary: Archives can contain multiple members with the same name. This would cause ThinLTO links to fail ("Expected at most one ThinLTO module per bitcode file"). This change implements the same strategy we use in the ELF linker: make the offset in the archive part of the module name so that names are unique. Reviewers: pcc, mehdi_amini, ruiu Reviewed By: ruiu Subscribers: eraman, steven_wu, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60549 llvm-svn: 358440
* [LLD][COFF] Improve checkFailIfMismatch()Alexandre Ganea2019-03-291-1/+1
| | | | | | | | As suggested by ruiu here (https://reviews.llvm.org/D58910#1425484), defer a call to toString(File) until it's really needed (if there's an error) Differential Revision: https://reviews.llvm.org/D59411 llvm-svn: 357305
* [LLD][COFF] More detailed information for /failifmismatchAlexandre Ganea2019-03-061-2/+2
| | | | | | | | | | | | | | When mismatched #pragma detect_mismatch declarations occur, now print the conflicting OBJs. lld-link: error: /failifmismatch: mismatch detected for 'TEST': >>> test.obj has value 1 >>> test2.obj has value 2 Fixes PR38579 Differential Revision: https://reviews.llvm.org/D58910 llvm-svn: 355543
* [LLD][COFF] Add support for /FUNCTIONPADMIN command-line optionAlexandre Ganea2019-02-231-0/+3
| | | | | | | | | | Initial patch by Stefan Reinalter. Fixes PR36775 Differential Revision: https://reviews.llvm.org/D49366 llvm-svn: 354716
* Move MinGW-specific code out of LinkerDriver::link. NFC.Rui Ueyama2019-02-191-0/+2
| | | | | | | | LinkerDriver::link is getting too long, it's time to simplify it. Differential Revision: https://reviews.llvm.org/D58395 llvm-svn: 354391
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [COFF] Look for libfoo.a if foo.lib is specified, for MinGWMartin Storsjo2018-10-101-0/+1
| | | | | | | | | | | | This allows using #pragma comment(lib, "foo") in MinGW built code, if built with -fms-extensions. (This works for system libraries and static libraries only, as it doesn't try to look for .dll.a. As ld.bfd doesn't support embedded defaultlib directives, this isn't in widespread use among mingw users.) Differential Revision: https://reviews.llvm.org/D53017 llvm-svn: 344124
* lld-link: Fix subsystem inference for non-console apps on 32-bit, and fix ↵Nico Weber2018-08-031-1/+0
| | | | | | | | | | | | | | | | | | | | | | | entry point inference on 32-bit with /nodefaultlib LinkerDriver::inferSubsystem() used to do Symtab->findUnderscore("WinMain"), but WinMain is stdcall in 32-bit and is hence is called _WinMain@16. Instead, Symtab->findMangle(mangle("WinMain")) needs to be called. But since LinkerDriver::inferSubsystem() and LinkerDriver::findDefaultEntry() both need to call this, introduce a common helper function for this and call it from both places. (Also call it for "main" for consistency, even though findUnderscore() is enough for main since that's __cdecl on 32-bit). This also exposed a bug for /nodefaultlib entrypoint inference: The code here called findMangle(Sym) instead of findMangle(mangle(Sym)), again doing the wrong thing on 32-bit. Fix that too. While here, make Driver::mangle() a static free function. https://reviews.llvm.org/D50184 llvm-svn: 338877
* lld-link: Remove /msvclto optionNico Weber2018-08-011-2/+0
| | | | | | | | | | | This was useful for LTO bringup in lld-link while lld couldn't write PDBs. Now that it can, this should no longer be needed. Hopefully the flag is obscure enough and recent enough, that nobody uses it – but if somebody should use it, they should be able to just stop passing it and things should continue to work. https://reviews.llvm.org/D50139 llvm-svn: 338615
* Fix /WholeArchive bug.Rui Ueyama2018-06-121-1/+6
| | | | | | | | | | `lld-link foo.lib /wholearchive:foo.lib` should work the same way as `lld-link /wholearchive:foo.lib foo.lib`. Previously, /wholearchive in the former case was ignored. Differential Revision: https://reviews.llvm.org/D47565 llvm-svn: 334552
* Consistent use of header file for ICF and MarkLiveSam Clegg2018-02-201-6/+0
| | | | | | | | | | Previously wasm used a separate header to declare markLive and ELF used to declare ICF. This change makes each backend consistently declare these in their own headers. Differential Revision: https://reviews.llvm.org/D43529 llvm-svn: 325631
* [COFF] Add minimal support for /guard:cfReid Kleckner2018-02-061-0/+2
| | | | | | | | | | | | | | | | | | | 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] Process /EXPORT option in fastpathRui Ueyama2018-01-091-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Patch by Takuto Ikuta. This patch reduces lld link time of chromium's blink_core.dll in component build. Total size of input argument in .directives become nearly 300MB in the build and almost all its content are /EXPORT. To reduce time of parsing too many /EXPORT option in the build, I introduce fastpath for /EXPORT in ArgParser::parseDirectives. On my desktop machine, 4 times stats of the link time are like below. Improved around 20%. This patch TotalSeconds : 8.6217627 TotalSeconds : 8.5402175 TotalSeconds : 8.6855853 TotalSeconds : 8.3624441 Ave : 8.5525024 master TotalSeconds : 10.9975031 TotalSeconds : 11.3409428 TotalSeconds : 10.6332897 TotalSeconds : 10.7650687 Ave : 10.934201075 llvm-svn: 322117
* Do not parse the same /export string more than once.Rui Ueyama2017-12-281-0/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D41607 llvm-svn: 321513
* [COFF] Do not parse args twice if no rsp files existsRui Ueyama2017-12-271-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Patch by Takuto Ikuta. This patch reduces link time of chromium's blink_core.dll in component build. Total size of input argument in .directives become nearly 300MB in the build and no rsp file is used. Speedup link by skipping duplicate parsing. On my desktop machine, 4 times stats are like below. Improved around 15%. This patch TotalSeconds : 18.408538 TotalSeconds : 17.2996744 TotalSeconds : 17.1053862 TotalSeconds : 17.809777 avg: 17.6558439 master TotalSeconds : 20.9290504 TotalSeconds : 19.9158213 TotalSeconds : 21.0643515 TotalSeconds : 20.8775831 avg: 20.696701575 Differential Revision: https://reviews.llvm.org/D41581 llvm-svn: 321470
* Prefer `ArrayRef` over `const std::vector&`Sam Clegg2017-12-081-3/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D40993 llvm-svn: 320125
* Rename SymbolBody -> SymbolRui Ueyama2017-11-031-1/+1
| | | | | | | | | | | | | 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: Add type server pdb files to linkrepro tar file.Peter Collingbourne2017-10-201-1/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D38977 llvm-svn: 316233
* COFF: Add resource files to linkrepro instead of the cvtres object file.Peter Collingbourne2017-10-161-4/+2
| | | | | | | | | Now that we have our own implementation of cvtres, we can add resource files directly to the linkrepro. Differential Revision: https://reviews.llvm.org/D38974 llvm-svn: 315954
* Move new lld's code to Common subdirectory.Rui Ueyama2017-10-021-2/+2
| | | | | | | | | | New lld's files are spread under lib subdirectory, and it isn't easy to find which files are actually maintained. This patch moves maintained files to Common subdirectory. Differential Revision: https://reviews.llvm.org/D37645 llvm-svn: 314719
* [COFF] Add support for the -wholearchive optionMartin Storsjo2017-09-131-2/+2
| | | | | | | | This fixes PR31824. Differential Revision: https://reviews.llvm.org/D37709 llvm-svn: 313123
* lld-link: Add --rsp-quoting= flag.Nico Weber2017-09-051-5/+4
| | | | | | | | | | This ports https://reviews.llvm.org/D19425 from clang / https://reviews.llvm.org/D22015 from the ELF port to COFF lld. This can be useful when linking COFF files on a posix host. https://reviews.llvm.org/D37452 llvm-svn: 312594
* Remove Symtab aliases.Rui Ueyama2017-08-281-3/+0
| | | | | | | | | Various classes have `Symtab` member variables even though we have lld::coff::Symtab variable because previous attempts to make COFF lld's internal structure resemble to ELF's was incomplete. This patch finishes that job by removing member variables. llvm-svn: 311938
* Keep an instance of COFFOptTable alive as long as InputArgList is alive.Rui Ueyama2017-08-281-2/+7
| | | | | | | | | | | | | | | | | | | | | | Summary: ArgParser created an instance of COFFOptTable on stack to use it to parser command line arguments. Parsed arguments were then returned from the function as InputArgList. This was safe because InputArgList referred only statically-allocated InfoTable. That is not a safe assumption after https://reviews.llvm.org/D36782, which changes the type of its internal table from ArrayRef to std::vector. To make lld work with that patch, we need to keep an instance of COFFOptTable at least as long as an InputArgList is alive. This patch does that. Reviewers: yamaguchi Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D37217 llvm-svn: 311930
* [COFF] Add support for aligncomm directivesMartin Storsjo2017-08-141-0/+1
| | | | | | | | | | | | | | 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
* Remove unused declarationsSam Clegg2017-06-301-1/+0
| | | | | | Differential Revision: https://reviews.llvm.org/D34852 llvm-svn: 306772
* [GSoC] Flag value completion for clangYuka Takahashi2017-06-201-1/+1
| | | | | | | | | | | | This is patch for GSoC project, bash-completion for clang. To use this on bash, please run `source clang/utils/bash-autocomplete.sh`. bash-autocomplete.sh is code for bash-completion. In this patch, Options.td was mainly changed in order to add value class in Options.inc. llvm-svn: 305805
* Re-land "COFF: migrate def parser from LLD to LLVM"Reid Kleckner2017-06-021-3/+0
| | | | | | | | | | | | | | | | | | | | | | This reverts commit r304561 and re-lands r303490 & co. The fix was to use "SymbolName" when translating LLD's internal export list to lib/Object's short export struct. The SymbolName reflects the actual symbol name, which may include fastcall and stdcall mangling bits not included in the /EXPORT or .def file EXPORTS name: @@ -434,8 +434,7 @@ std::vector<COFFShortExport> createCOFFShortExportFromConfig() { std::vector<COFFShortExport> Exports; for (Export &E1 : Config->Exports) { COFFShortExport E2; - E2.Name = E1.Name; + // Use SymbolName, which will have any stdcall or fastcall qualifiers. + E2.Name = E1.SymbolName; E2.ExtName = E1.ExtName; E2.Ordinal = E1.Ordinal; E2.Noname = E1.Noname; llvm-svn: 304573
* Revert "COFF: migrate def parser from LLD to LLVM"Reid Kleckner2017-06-021-0/+3
| | | | | | | | | | This reverts commits r303490, r303491, r303493, and r303494. This caused http://crbug.com/728726. Essentially, exporting stdcall functions doesn't appear to work after this change. Reduced test case soon. llvm-svn: 304561
* COFF: migrate def parser from LLD to LLVM [2/2]Martell Malone2017-05-201-3/+0
| | | | | | | | | | | | This is split up into two commits. This commit removes the DEF parser from LLD See the previous commit for the creation in LLVM. Reviewers: ruiu Differential Revision: https://reviews.llvm.org/D32689 llvm-svn: 303491
* Use make<> everywhere in COFF to make it consistent with ELF.Rui Ueyama2017-05-181-4/+0
| | | | | | | | | 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
* Handle _LINK_ env string as command line parameters.Rui Ueyama2017-04-241-1/+1
| | | | | | | | | "_LINK_" environment varaible should be appended to the command line. https://msdn.microsoft.com/en-us/library/6y6t9esh.aspx Fixes https://bugs.llvm.org/show_bug.cgi?id=32756 llvm-svn: 301264
* Fix /msvclto.Rui Ueyama2017-02-231-1/+3
| | | | | | | Previously, bitcode files in library paths were passed to the MSVC linker. This patch strips them. llvm-svn: 295913
* Add an option to use the MSVC linker to link LTO-generated object files.Rui Ueyama2017-02-061-0/+2
| | | | | | | | | | | This patch defines a new command line option, /MSVCLTO, to LLD. If that option is given, LLD invokes link.exe to link LTO-generated object files. This is hacky but useful because link.exe can create PDB files. Differential Revision: https://reviews.llvm.org/D29526 llvm-svn: 294234
* Use TarWriter to create tar archives instead of cpio.Rui Ueyama2017-01-061-1/+2
| | | | | | | | | | This is how we use TarWriter in LLD. Now LLD does not append a file extension, so you need to pass `--reproduce foo.tar` instead of `--reproduce foo`. Differential Revision: https://reviews.llvm.org/D28103 llvm-svn: 291210
* COFF: Cache the result of library searches.Peter Collingbourne2016-12-161-0/+1
| | | | | | | | | | | | | | | File system operations were still dominating the profile on Windows. In this case we were spending a significant amount of our time repeatedly searching for libraries as a result of processing linker directives. Address this by caching whether we have already found a library with a given name. For chrome_child.dll: Before: 10.53s After: 6.88s Differential Revision: https://reviews.llvm.org/D27840 llvm-svn: 289915
* COFF: Open and map input files asynchronously on Windows.Peter Collingbourne2016-12-151-1/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Profiling revealed that the majority of lld's execution time on Windows was spent opening and mapping input files. We can reduce this cost significantly by performing these operations asynchronously. This change introduces a queue for all operations on input file data. When we discover that we need to load a file (for example, when we find a lazy archive for an undefined symbol, or when we read a linker directive to load a file from disk), the file operation is launched using a future and the symbol resolution operation is enqueued. This implies another change to symbol resolution semantics, but it seems to be harmless ("ninja All" in Chromium still succeeds). To measure the perf impact of this change I linked Chromium's chrome_child.dll with both thin and fat archives. Thin archives: Before (median of 5 runs): 19.50s After: 10.93s Fat archives: Before: 12.00s After: 9.90s On Linux I found that doing this asynchronously had a negative effect on performance, probably because the cost of mapping a file is small enough that it becomes outweighed by the cost of managing the futures. So on non-Windows platforms I use the deferred execution strategy. Differential Revision: https://reviews.llvm.org/D27768 llvm-svn: 289760
OpenPOWER on IntegriCloud