summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Error.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [lld] unified COFF and ELF error handling on new Common/ErrorHandlerBob Haarman2017-10-251-120/+0
| | | | | | | | | | | | | | | | | | | 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
* [lld] Move Threads to CommonBob Haarman2017-10-131-1/+2
| | | | | | | | | | | | | | | | Summary: This will allow using the functionality from other linkers. It is also a prerequisite for sharing the error logging code. Reviewers: ruiu Reviewed By: ruiu Subscribers: emaste, mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D38822 llvm-svn: 315725
* Wait for all threads to terminate before exitting.Rui Ueyama2017-10-051-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | I think it is not defined what would happen to detached threads when the main thread tries to exit. That means it was not guaranteed that unlinkAsync correctly removes a temporary file. It was also reported that this unlinkAsync caused a crash on Windows. This patch adds a few new functions so that the main thread always waits for non-main threads before exitting. I don't actually like the new two functions, runBackground and waitForBackgroundThreads, because it looks like it is a bit overdesigned. After all, what we are doing with these functions is to just remove a file. An alternative would be to do fork(2) and make the child process remove a file asynchronously. However, it has its own problems. Correctly forking and reclaiming a resource using waitpid(2) is not doable unless we know our process-wide settings (such as signal mask), but we can't make any assumption on it when lld is embedded to other process. So I chose to stick with threads instead of multi-processes. Differential Revision: https://reviews.llvm.org/D38571 llvm-svn: 315033
* Use StringRef::contains().Rui Ueyama2017-07-191-1/+1
| | | | llvm-svn: 308526
* [lld/pdb] Add some basic linker module symbols.Zachary Turner2017-07-101-3/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D35152 llvm-svn: 307590
* Flush output in log()Hans Wennborg2017-04-281-0/+1
| | | | | | | | This change was motivated by output from lld-link.exe and link.exe getting intermixed. There's already a flush() call in message(), so there's precedence. llvm-svn: 301693
* Change the error message format for undefined symbols.Rui Ueyama2017-03-301-3/+16
| | | | | | | | | | | | | | | | | | | | Previously, undefined symbol errors are one line like this and wasn't easy to read. /ssd/clang/bin/ld.lld: error: /ssd/llvm-project/lld/ELF/Writer.cpp:207: undefined symbol 'lld::elf::EhFrameSection<llvm::object::ELFType<(llvm::support::endianness)0, true> >::addSection(lld::elf::InputSectionBase*)' This patch make it more structured like this. bin/ld.lld: error: undefined symbol: lld::elf::EhFrameSection<llvm::object::ELFType<(llvm::support::endianness)0, true> >>> Referenced by Writer.cpp:207 (/ssd/llvm-project/lld/ELF/Writer.cpp:207) >>> Writer.cpp.o in archive lib/liblldELF.a Discussion thread: http://lists.llvm.org/pipermail/llvm-dev/2017-March/111459.html Differential Revision: https://reviews.llvm.org/D31481 llvm-svn: 299097
* Use `using namespace lld` for consistency with other files.Rui Ueyama2017-03-241-4/+2
| | | | llvm-svn: 298668
* Do not use errs() or outs() directly. Instead use message(), log() or error()Rui Ueyama2017-02-211-2/+9
| | | | | | | | | 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
* Remove error(error_code, const Twine &).Rui Ueyama2017-01-121-4/+0
| | | | | | Now we have the consistent interface for all log/warn/error/fatal functions. llvm-svn: 291847
* Remove dead code.Rui Ueyama2017-01-121-4/+0
| | | | llvm-svn: 291840
* Improve an error message and remove fatal(Error &, const Twine &)Rui Ueyama2017-01-121-4/+0
| | | | llvm-svn: 291834
* [ELF] avoid 'invalid-noreturn' error.Eric Liu2017-01-121-3/+1
| | | | | | | | | | | | Summary: elf::fatal is declared "noreturn". Reviewers: grimar Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D28607 llvm-svn: 291766
* [ELF] - Reuse Decompressor class.George Rimar2017-01-121-0/+6
| | | | | | | | | | | Intention of change is to get rid of code duplication. Decompressor was introduced in D28105. Change allows to get rid of few methods relative to decompression. Differential revision: https://reviews.llvm.org/D28106 llvm-svn: 291758
* Make getColorDiagnostics return a boolean value instead of an enum.Rui Ueyama2016-11-261-10/+1
| | | | | | | Config->ColorDiagnostics was of type enum before. Now it is just a boolean flag. Thanks Rafael for suggestion. llvm-svn: 287978
* Do not print out ARGV0 in white because it's unreadable on white background.Rui Ueyama2016-11-251-3/+2
| | | | llvm-svn: 287950
* Support -color-diagnostics={auto,always,never}.Rui Ueyama2016-11-251-4/+30
| | | | | | | | | | | | | | | | -color-diagnostics=auto is default because that's the same as Clang's default. When color is enabled, error or warning messages are colored like this. error: <bold>ld.lld</bold> <red>error:</red> foo.o: no such file warning: <bold>ld.lld</bold> <magenta>warning:</magenta> foo.o: no such file Differential Revision: https://reviews.llvm.org/D27117 llvm-svn: 287949
* Include a hint how to see all errors if error is truncated.Rui Ueyama2016-11-241-1/+2
| | | | | | | | | | | | | | This patch changes the error message from too many errors emitted, stopping now to too many errors emitted, stopping now (use -error-limit=0 to see all errors) Thanks for Sean for the suggestion! llvm-svn: 287900
* Remove HasError and use ErrorCount instead.Rui Ueyama2016-11-241-2/+0
| | | | | | HasError was always true if ErrorCount > 0, so we can use ErrorCount instead. llvm-svn: 287849
* Make log(), error() and fatal() thread-safe.Rui Ueyama2016-11-231-3/+14
| | | | llvm-svn: 287794
* Limit default maximum number of errors to 20.Rui Ueyama2016-11-231-1/+10
| | | | | | | | | | | | | | | | | | This is in the context of https://llvm.org/bugs/show_bug.cgi?id=31109. When LLD prints out errors for relocations, it tends to print out extremely large number of errors (like millions) because it would print out one error per relocation. This patch makes LLD bail out if it prints out more than 20 errors. You can configure the limitation using -error-limit argument. -error-limit=0 means no limit. I chose the flag name because Clang has the same feature as -ferror-limit. "f" doesn't make sense to us, so I omitted it. Differential Revision: https://reviews.llvm.org/D26981 llvm-svn: 287789
* Call flush() after llvm_shutdown().Rui Ueyama2016-11-111-3/+2
| | | | | | | llvm_shutdown could write something to outs or errs, so we need to flush them after calling llvm_shutdown. llvm-svn: 286548
* [LTO] Call llvm_shutdown on early exit.Davide Italiano2016-11-101-0/+7
| | | | | | | | | | In a non-LTO build is a nop. In a LTO build, we deallocate/destroy managed static and this allows us to get the output of, e.g., -time-passes without performing a full shutdown. Differential Revision: https://reviews.llvm.org/D26517 llvm-svn: 286493
* Use fewer allocators.Rafael Espindola2016-10-271-1/+11
| | | | | | | | | | | | | | Instead of having 3 section allocators per file, have 3 for all files. This is a substantial performance improvement for some cases. Linking chromium without gc speeds up by 1.065x. This requires using _exit in fatal since we have to avoid destructing an InputSection if fatal is called from the constructor. Thanks to Rui for the suggestion. llvm-svn: 285290
* Include ARGV[0] in error messages.Rui Ueyama2016-10-191-4/+5
| | | | | | | | This is what other linkers and clang driver do. Differential Revision: https://reviews.llvm.org/D25780 llvm-svn: 284634
* [ELF] Add "error" and "warning" prefixes to linker messagesEugene Leviant2016-10-191-3/+3
| | | | | | Differential revision: https://reviews.llvm.org/D25729 llvm-svn: 284575
* [ELF] - Do not crash when unable to parse ELF object file.George Rimar2016-10-071-0/+4
| | | | | | | | | | | | | createELFObj() may call error(...), for example when file is too short. In that case header is not set and following line lead to crash: EMachine = ELFObj.getHeader()->e_machine; Patch fixes the issue. Differential revision: https://reviews.llvm.org/D25233 llvm-svn: 283532
* Remove useless function.Rui Ueyama2016-10-061-4/+0
| | | | llvm-svn: 283488
* Rename warning -> warn.Rui Ueyama2016-09-291-1/+1
| | | | | | It's better because it's a verb. llvm-svn: 282763
* Delete dead code.Rafael Espindola2016-07-181-19/+8
| | | | | | And make it easier to spot code going dead by using elf::. llvm-svn: 275858
* Avoid writing to errs().Rui Ueyama2016-07-151-2/+2
| | | | | | | We should write to ErrorOS instead. Normaly, *ErrorOS == errs(), but they can be different if LLD is embedded. llvm-svn: 275525
* ELF: Make error() to always set HasError.Rui Ueyama2016-07-151-2/+1
| | | | | | | | Previously, it checked for the EC parameter and set HasError only when there was an error. But in most places we called error only when error had occurred, so this behavior was confusing. llvm-svn: 275517
* [lld] Update LLD for Archive::child_iterator change in LLVM r275361.Lang Hames2016-07-141-0/+5
| | | | llvm-svn: 275362
* Use "using namespace llvm" like the rest of ELF lld.Rafael Espindola2016-07-071-4/+6
| | | | llvm-svn: 274755
* [ELF] - Implemented --fatal-warnings option.George Rimar2016-07-041-1/+6
| | | | | | | | --fatal-warnings: Treat warnings as errors DIfferential revision: http://reviews.llvm.org/D21969 llvm-svn: 274504
* Print the cpio trailer after every member.Rafael Espindola2016-05-041-2/+0
| | | | | | | | | This is both simpler and safer. If we crash at any point, there is a valid cpio file to reproduce the crash. Thanks to Rui for the suggestion. llvm-svn: 268495
* Produce cpio files for --reproduce.Rafael Espindola2016-05-031-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We want --reproduce to * not rewrite scripts and thin archives * work with absolute paths Given that, it pretty much has to create a full directory tree. On windows that is problematic because of the very short maximum path limit. On most cases users can still work around it with "--repro c:\r", but that is annoying and not viable for automated testing. We then need to produce some form of archive with the files. The first option that comes to mind is .a files since we already have code for writing them. There are a few problems with them The format has a dedicated string table, so we cannot start writing it until all members are known. Regular implementations don't support creating directories. We could make llvm-ar support that, but that is probably not a good idea. The next natural option would be tar. The problem is that to support long path names (which is how this started) it needs a "pax extended header" making this an annoying format to write. The next option I looked at seems a natural fit: cpio files. They are available on pretty much every unix, support directories and long path names and are really easy to write. The only slightly annoying part is a terminator, but at least gnu cpio only prints a warning if it is missing, which is handy for crashes. This patch still makes an effort to always create it. llvm-svn: 268404
* Remove dead code.Rui Ueyama2016-03-131-5/+0
| | | | llvm-svn: 263363
* Do not return a bool value from error().Rui Ueyama2016-03-131-10/+6
| | | | | | | | | | | | | | | | | | | | error returned true if there was an error. This allows us to replace the code like this if (EC) { error(EC, "something failed"); return; } with if (error(EC, "something failed")) return; I thought that that was a good idea, but it turned out that we only have two places to use this pattern. So this patch removes that feature. llvm-svn: 263362
* Rename 'fatal' to 'check' when it doesn't always fail.Rafael Espindola2016-03-031-1/+1
| | | | llvm-svn: 262666
* Delete dead code.Rafael Espindola2016-03-031-5/+0
| | | | llvm-svn: 262653
* Simplify error handling.Rafael Espindola2016-03-031-0/+4
| | | | | | | This makes fatal return T when there is no error. This avoids the need for quite a few temporaries. llvm-svn: 262626
* Rename elf2 to elf.Rafael Espindola2016-02-281-2/+2
| | | | llvm-svn: 262159
* ELF: Define log() to print out message if --verbose is given.Rui Ueyama2016-02-251-0/+6
| | | | llvm-svn: 261919
* ELF: Make link() to take an output stream to which error messages are written.Rui Ueyama2016-02-021-1/+2
| | | | | | http://reviews.llvm.org/D16668 llvm-svn: 259597
* Re-submit ELF: Report multiple errors from the driver.Rui Ueyama2016-02-021-6/+10
| | | | | | This reverts r259395 which reverted r259143. llvm-svn: 259572
* Revert r259143, it broke check-lld on Windows (see PR26388).Nico Weber2016-02-011-10/+6
| | | | llvm-svn: 259395
* ELF: Report multiple errors from the driver.Rui Ueyama2016-01-291-6/+10
| | | | | | | | | This patch let the driver keep going until it parses all command line options. http://reviews.llvm.org/D16645 llvm-svn: 259143
* ELF: Rename error -> fatal and redefine error as a non-noreturn function.Rui Ueyama2016-01-281-7/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In many situations, we don't want to exit at the first error even in the process model. For example, it is better to report all undefined symbols rather than reporting the first one that the linker picked up randomly. In order to handle such errors, we don't need to wrap everything with ErrorOr (thanks for David Blaikie for pointing this out!) Instead, we can set a flag to record the fact that we found an error and keep it going until it reaches a reasonable checkpoint. This idea should be applicable to other places. For example, we can ignore broken relocations and check for errors after visiting all relocs. In this patch, I rename error to fatal, and introduce another version of error which doesn't call exit. That function instead sets HasError to true. Once HasError becomes true, it stays true, so that we know that there was an error if it is true. I think introducing a non-noreturn error reporting function is by itself a good idea, and it looks to me that this also provides a gradual path towards lld-as-a-library (or at least embed-lld-to-your-program) without sacrificing code readability with lots of ErrorOr's. http://reviews.llvm.org/D16641 llvm-svn: 259069
* [ELF2] Output of all unknown arguments instead of only one.Rui Ueyama2015-09-241-0/+2
| | | | | | Patch from George Rimar! llvm-svn: 248524
OpenPOWER on IntegriCloud