summaryrefslogtreecommitdiffstats
path: root/lld/COFF/Driver.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* lld-link: Fix subsystem inference for non-console apps on 32-bit, and fix ↵Nico Weber2018-08-031-14/+17
| | | | | | | | | | | | | | | | | | | | | | | 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-132/+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
* [COFF] clean up global resources after completionRui Ueyama2018-07-261-0/+3
| | | | | | | | | | | | | Patch by Andrew Kelley. Previously, running lld::coff::link() twice in the same process would access stale pointers because of these global variables not being reset. After this patch, lld::coff::link() can be called any number of times, just like its ELF and MACH-O counterparts. Differential Revision: https://reviews.llvm.org/D49856 llvm-svn: 338042
* Omit path to lld binary from lld's error, warning, and log output.Nico Weber2018-07-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | lld currently prepends the absolute path to itself to every diagnostic it emits. This path can be longer than the diagnostic, and makes the actual error message hard to read. There isn't a good reason for printing this path: if you want to know which lld you're running, pass -v to clang – chances are that if you're unsure of this, you're not only unsure when it errors out. Some people want an indication that the diagnostic is from the linker though, so instead print just the basename of the linker's path. Before: ``` $ out/bin/clang -target x86_64-unknown-linux -x c++ /dev/null -fuse-ld=lld /Users/thakis/src/llvm-mono/out/bin/ld.lld: error: cannot open crt1.o: No such file or directory /Users/thakis/src/llvm-mono/out/bin/ld.lld: error: cannot open crti.o: No such file or directory /Users/thakis/src/llvm-mono/out/bin/ld.lld: error: cannot open crtbegin.o: No such file or directory /Users/thakis/src/llvm-mono/out/bin/ld.lld: error: unable to find library -lgcc /Users/thakis/src/llvm-mono/out/bin/ld.lld: error: unable to find library -lgcc_s /Users/thakis/src/llvm-mono/out/bin/ld.lld: error: unable to find library -lc /Users/thakis/src/llvm-mono/out/bin/ld.lld: error: unable to find library -lgcc /Users/thakis/src/llvm-mono/out/bin/ld.lld: error: unable to find library -lgcc_s /Users/thakis/src/llvm-mono/out/bin/ld.lld: error: cannot open crtend.o: No such file or directory /Users/thakis/src/llvm-mono/out/bin/ld.lld: error: cannot open crtn.o: No such file or directory clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` After: ``` $ out/bin/clang -target x86_64-unknown-linux -x c++ /dev/null -fuse-ld=lld ld.lld: error: cannot open crt1.o: No such file or directory ld.lld: error: cannot open crti.o: No such file or directory ld.lld: error: cannot open crtbegin.o: No such file or directory ld.lld: error: unable to find library -lgcc ld.lld: error: unable to find library -lgcc_s ld.lld: error: unable to find library -lc ld.lld: error: unable to find library -lgcc ld.lld: error: unable to find library -lgcc_s ld.lld: error: cannot open crtend.o: No such file or directory ld.lld: error: cannot open crtn.o: No such file or directory clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` https://reviews.llvm.org/D49189 llvm-svn: 337634
* [PDB] Write the command line after response file expansionReid Kleckner2018-07-201-2/+1
| | | | | | | | | | | | Summary: Fixes PR38085 Reviewers: ruiu, zturner Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D49566 llvm-svn: 337628
* [PDB] Add PDBSourcePath flag to support absolutize source file pathTakuto Ikuta2018-07-191-0/+3
| | | | | | | | | | | | | | | | | | | | | This patch changes relative path for source files in obj files to absolute path in PDB when linking with added flag. I will make obj file generated by clang-cl independent from build directory for chromium build. But I don't want to confuse visual studio debugger or require additional configuration. To attain this goal, I added flag to convert relative source file path in obj to absolute path when emitting PDB. By removing absolute path from obj files, we can share build cache between chromium developers even when they are doing debug build. That will make build time faster. More context: https://bugs.chromium.org/p/chromium/issues/detail?id=712796 https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/5HXSVX-7fPc llvm-svn: 337439
* Look for an entry point function if /nodefaultlib is given.Rui Ueyama2018-07-181-0/+17
| | | | | | | | | | | | Summary: Fixes https://bugs.llvm.org/show_bug.cgi?id=38018 Reviewers: thakis Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D48990 llvm-svn: 337407
* [coff] remove_dots from /PDBPATH but not /PDBALTPATH.Zachary Turner2018-07-121-0/+5
| | | | | | | This more closely matches the behavior of link.exe, and also simplifies the code slightly. llvm-svn: 336882
* [COFF] Add an LLD specific option -debug:symbtabMartin Storsjo2018-06-291-0/+1
| | | | | | | | | | | With this set, we retain the symbol table, but skip the actual debug information. This is meant to be used by the MinGW frontend. Differential Revision: https://reviews.llvm.org/D48745 llvm-svn: 335946
* [COFF] Fix /wholearchive: to do libpath search againReid Kleckner2018-06-141-3/+4
| | | | | | Fixes https://crbug.com/852882 llvm-svn: 334761
* Fix /WholeArchive bug.Rui Ueyama2018-06-121-19/+40
| | | | | | | | | | `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
* lld-link: Implement /INTEGRITYCHECK flagNico Weber2018-05-311-0/+2
| | | | | | | | /INTEGRITYCHECK has the effect of setting IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY. Fixes PR31066. https://reviews.llvm.org/D47472 llvm-svn: 333652
* Code cleanup in preparation for adding LTO for wasm. NFC.Sam Clegg2018-05-221-3/+3
| | | | | | | | | | | | | | - Move some common code into Common/rrorHandler.cpp and Common/Strings.h. - Don't use `fatal` when incompatible bitcode files are encountered. - Rename NameRef variable to just Name See D47162 Differential Revision: https://reviews.llvm.org/D47206 llvm-svn: 333021
* [COFF] Add /Brepro and /TIMESTAMP options.Zachary Turner2018-05-171-0/+17
| | | | | | | | | | | | | | | | | | | | Previously we would always write a hash of the binary into the PE file, for reproducible builds. This breaks AppCompat, which is a feature of Windows that relies on the timestamp in the PE header being set to a real value (or at the very least, a value that satisfies certain properties). To address this, we put the old behavior of writing the hash behind the /Brepro flag, which mimics MSVC linker behavior. We also match MSVC default behavior, which is to write an actual timestamp to the PE header. Finally, we add the /TIMESTAMP option (an lld extension) so that the user can specify the exact value to be used in case he/she manually constructs a value which is both reproducible and satisfies AppCompat. Differential Revision: https://reviews.llvm.org/D46966 llvm-svn: 332613
* COFF: Add a flag for disabling string tail merging.Peter Collingbourne2018-05-111-0/+6
| | | | | | | | | | | 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] Fix dangling StringRefs from SVN 331900Martin Storsjo2018-05-091-2/+2
| | | | llvm-svn: 331912
* [COFF] Allow specifying export forwarding in a def fileMartin Storsjo2018-05-091-0/+10
| | | | | | | | | Previously this was only supported when specified on the command line or in directives. Differential Revision: https://reviews.llvm.org/D46244 llvm-svn: 331900
* [COFF] Improve correctness of def parsing for GNU featuresMartin Storsjo2018-05-091-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | The operator == used for exporting a function with a different name in the DLL compared to the name in the import library (which is useful for adding linker level aliases for function in the import library) is a feature distinct and different from the operator = used for exporting a function with a different name (both in import library and DLL) than in the implementation producing the DLL. When creating an import library using dlltool, from a def file that contains forwards (Func = OtherDll.Func), this shouldn't affect the produced import library, which should still behave just as if it was a normal exported function. This clears a lot of confusion and subtle misunderstandings, and avoids a parameter that was used to avoid creating weak aliases when invoked from lld. (This parameter was added previously due to the existing conflation of the two features.) Differential Revision: https://reviews.llvm.org/D46245 llvm-svn: 331860
* [COFF] Don't set the tsaware bit on DLLsHans Wennborg2018-04-251-1/+2
| | | | | | | | It doesn't apply to DLLs, and link.exe doesn't set it. Differential Revision: https://reviews.llvm.org/D46077 llvm-svn: 330868
* [COFF] create MemoryBuffers without requiring NUL terminatorsBob Haarman2018-04-241-3/+7
| | | | | | | | | | | | | | | | | | | | Summary: In a number of places in the COFF linker, we were calling MemoryBuffer::getFile() with default parameters. This causes LLVM to NUL-terminate the buffers, which can prevent them from being memory mapped. Since we operate on binary and do not use NUL as an indicator of the end of the file content, this change causes us to not require the NUL terminator anymore. Reviewers: ruiu, pcc Reviewed By: ruiu Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D45909 llvm-svn: 330786
* COFF: Merge .xdata into .rdata by default.Peter Collingbourne2018-04-201-0/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D45804 llvm-svn: 330484
* COFF: Merge .bss into .data by default.Peter Collingbourne2018-04-201-0/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D45803 llvm-svn: 330483
* COFF: Rename Chunk::getPermissions to getOutputCharacteristics.Peter Collingbourne2018-04-191-1/+1
| | | | | | | | | | In an upcoming change I will need to make a distinction between section type (code, data, bss) and permissions. The term that I use for both of these things is "output characteristics". Differential Revision: https://reviews.llvm.org/D45799 llvm-svn: 330361
* Reland r330223, "COFF: Merge .idata, .didat and .edata into .rdata by ↵Peter Collingbourne2018-04-171-0/+6
| | | | | | | | | | | | | | | | | | | | | default.", which was reverted in r330228. In this reland I removed an unnecessary use of /debug in the test delayimports32.test and used the /pdbaltpath flag in the test pdb-publics-import.test, both of which avoid embedding absolute PDB paths in executables which could affect later RVAs. Original commit message: > COFF: Merge .idata, .didat and .edata into .rdata by default. > > This saves a little space and matches what link.exe does. > > Tested using the chromium Windows trybots: > https://chromium-review.googlesource.com/c/chromium/src/+/1014784 Differential Revision: https://reviews.llvm.org/D45737 llvm-svn: 330233
* COFF: Implement /pdbaltpath flag.Peter Collingbourne2018-04-171-4/+15
| | | | | | | | | | | I needed to revert r330223 because we were embedding an absolute PDB path in the .rdata section, which ended up being laid out before the .idata section and affecting its RVAs. This flag will let us control the embedded path. Differential Revision: https://reviews.llvm.org/D45747 llvm-svn: 330232
* Revert r330223, "COFF: Merge .idata, .didat and .edata into .rdata by default."Peter Collingbourne2018-04-171-6/+0
| | | | | | Seems to have uncovered some sort of non-determinism on the bots. llvm-svn: 330228
* COFF: Merge .idata, .didat and .edata into .rdata by default.Peter Collingbourne2018-04-171-0/+6
| | | | | | | | | | | This saves a little space and matches what link.exe does. Tested using the chromium Windows trybots: https://chromium-review.googlesource.com/c/chromium/src/+/1014784 Differential Revision: https://reviews.llvm.org/D45737 llvm-svn: 330223
* s/LLVM_ON_WIN32/_WIN32/, lldNico Weber2018-04-101-1/+1
| | | | | | | | | | | LLVM_ON_WIN32 is set exactly with MSVC and MinGW (but not Cygwin) in HandleLLVMOptions.cmake, which is where _WIN32 defined too. Just use the default macro instead of a reinvented one. See thread "Replacing LLVM_ON_WIN32 with just _WIN32" on llvm-dev and cfe-dev. No intended behavior change. llvm-svn: 329696
* [lld-link] Add comment explaining that /FIXED behavior is correct despite ↵Nico Weber2018-03-301-0/+3
| | | | | | | | | contradicting MSDN. Also add a test for /FIXED. https://reviews.llvm.org/D45087 llvm-svn: 328879
* [lld-link] Let /PROFILE imply /OPT:REF /OPT:NOICF /INCREMENTAL:NO /FIXED:NONico Weber2018-03-301-8/+15
| | | | | | | | | | /FIXED:NO is always the default, so that part needs no work. Also test the interaction of /ORDER: with /INCREMENTAL. https://reviews.llvm.org/D45091 llvm-svn: 328877
* [PDB] Resubmit "Support embedding natvis files in PDBs."Zachary Turner2018-03-231-1/+4
| | | | | | | | | | | | This was reverted several times due to what ultimately turned out to be incompatibilities in our serialized hash table format. Several changes went in prior to this to fix those issues since they were more fundamental and independent of supporting injected sources, so now that those are fixed this change should hopefully pass. llvm-svn: 328363
* Revert "Resubmit "Support embedding natvis files in PDBs.""Zachary Turner2018-03-201-4/+1
| | | | | | | | This is still failing on a different bot this time due to some issue related to hashing absolute paths. Reverting until I can figure it out. llvm-svn: 328014
* Resubmit "Support embedding natvis files in PDBs."Zachary Turner2018-03-201-1/+4
| | | | | | | | | | | The issue causing this to fail in certain configurations should be fixed. It was due to the fact that DIA apparently expects there to be a null string at ID 1 in the string table. I'm not sure why this is important but it seems to make a difference, so set it. llvm-svn: 328002
* Revert "Support embedding natvis files in PDBs."Zachary Turner2018-03-191-4/+1
| | | | | | | This is causing a test failure on a certain bot, so I'm removing this temporarily until we can figure out the source of the error. llvm-svn: 327903
* Support embedding natvis files in PDBs.Zachary Turner2018-03-191-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | Natvis is a debug language supported by Visual Studio for specifying custom visualizers. The /NATVIS option is an undocumented link.exe flag which will take a .natvis file and "inject" it into the PDB. This way, you can ship the debug visualizers for a program along with the PDB, which is very useful for postmortem debugging. This is implemented by adding a new "named stream" to the PDB with a special name of /src/files/<natvis file name> and simply copying the contents of the xml into this file. Additionally, we need to emit a single stream named /src/headerblock which contains a hash table of embedded files to records describing them. This patch adds this functionality, including the /NATVIS option to lld-link. Differential Revision: https://reviews.llvm.org/D44328 llvm-svn: 327895
* [COFF] Add support for the GNU ld flag --kill-atMartin Storsjo2018-03-141-0/+4
| | | | | | | | | | | | | | | | | | | GNU ld has got a number of different flags for adjusting how to behave around stdcall functions. The --kill-at flag strips the trailing sdcall suffix from exported functions (which otherwise is included by default in MinGW setups). This also strips it from the corresponding import library though. That makes it hard to link to such an import library from code that calls the functions - but this matches what GNU ld does with this flag. Therefore, this flag is probably not sensibly used together with import libraries, but probably mostly when creating some sort of plugin, or if creating the import library separately with dlltool. Differential Revision: https://reviews.llvm.org/D44292 llvm-svn: 327561
* Make lld-link shout at me less.Nico Weber2018-03-121-4/+4
| | | | | | | | | This makes the output of some flag names in warning messages consistent with the output of /? and the output of flags in most other diagnostics. https://reviews.llvm.org/D44307 llvm-svn: 327261
* [lld-link] For suppressible warnings, print the warning number.Nico Weber2018-03-121-1/+1
| | | | | | | The warning can be suppressed by passing the number to /ignore:. https://reviews.llvm.org/D44297 llvm-svn: 327257
* [lld-link] Add support for /ignore:4037.Nico Weber2018-03-091-3/+7
| | | | | | | Fixes PR36657. https://reviews.llvm.org/D44286 llvm-svn: 327124
* Report an error if you try to link against .dll instead of .lib.Rui Ueyama2018-03-011-11/+18
| | | | | | | | | | | | It is a usage error to feed a .dll file instead of a .dll to COFF linker. Previously, lld failed with a mysterious error message. Now we reject it at the driver. Fixes https://bugs.llvm.org/show_bug.cgi?id=36440 Differential Revision: https://reviews.llvm.org/D43964 llvm-svn: 326507
* Consistent use of header file for ICF and MarkLiveSam Clegg2018-02-201-1/+3
| | | | | | | | | | 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
* Consistent (non) use of empty lines in include blocksSam Clegg2018-02-201-1/+0
| | | | | | | | | The profailing style in lld seem to be to not include such empty lines. Clang-tidy/clang-format seem to handle this just fine. Differential Revision: https://reviews.llvm.org/D43528 llvm-svn: 325629
* [COFF] LTO does not require a disassembler.Benjamin Kramer2018-02-061-1/+0
| | | | llvm-svn: 324355
* [COFF] Add minimal support for /guard:cfReid Kleckner2018-02-061-4/+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
* [COFF] make /incremental control overwriting unchanged import librariesBob Haarman2018-01-311-0/+27
| | | | | | | | | | | | | | | | | | | | | | Summary: r323164 made lld-link not overwrite import libraries when their contents haven't changed. MSVC's link.exe does this only when performing incremental linking. This change makes lld-link's import library overwriting similarly dependent on whether or not incremental linking is being performed. This is controlled by the /incremental or /incremental:no options. In addition, /opt:icf, /opt:ref, and /order turn off /incremental and issue a warning if /incremental was specified on the command line. Reviewers: rnk, ruiu, zturner Reviewed By: ruiu Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D42716 llvm-svn: 323930
* [COFF] Remove the temporary file if not updating the import libraryMartin Storsjo2018-01-301-0/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D42621 llvm-svn: 323725
* Warn on nonexistent comdat sections in an /order file.Rui Ueyama2018-01-291-5/+18
| | | | | | | | | | | | | I didn't implement the feature in the original patch because I didn't come up with an idea to do that easily and efficiently. Turned out that that is actually easy to implement. In this patch, we collect comdat sections before gc is run and warn on nonexistent symbols in an order file. Differential Revision: https://reviews.llvm.org/D42658 llvm-svn: 323699
* Remove trailing space.Rui Ueyama2018-01-291-1/+1
| | | | llvm-svn: 323682
* Add the /order option.Rui Ueyama2018-01-271-0/+32
| | | | | | | | | | | | With the /order option, you can give an order file. An order file contains symbol names, one per line, and the linker places comdat sections in that given order. The option is used often to optimize an output binary for (in particular, startup) speed by improving locality. Differential Revision: https://reviews.llvm.org/D42598 llvm-svn: 323579
* [COFF] don't replace import library if contents are unchangedBob Haarman2018-01-231-6/+35
| | | | | | | | | | | | | | | | | | | | | Summary: This detects when an import library is about to be overwritten with a newly built one with the same contents, and keeps the old library instead. The use case for this is to avoid needlessly rebuilding targets that depend on the import library in build systems that rely on timestamps to determine whether a target requires rebuilding. This feature was requested in PR35917. Reviewers: rnk, ruiu, zturner, pcc Reviewed By: ruiu Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D42326 llvm-svn: 323164
OpenPOWER on IntegriCloud