Commit Graph

43 Commits

Author SHA1 Message Date
Rui Ueyama e6e206d4b4 Do not use errs() or outs() directly. Instead use message(), log() or error()
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
2017-02-21 23:22:56 +00:00
Rui Ueyama c8d3a83fff Remove error(error_code, const Twine &).
Now we have the consistent interface for all log/warn/error/fatal functions.

llvm-svn: 291847
2017-01-12 22:18:04 +00:00
Rui Ueyama cec59f6f3c Remove dead code.
llvm-svn: 291840
2017-01-12 22:03:25 +00:00
Rui Ueyama 52be82590c Improve an error message and remove fatal(Error &, const Twine &)
llvm-svn: 291834
2017-01-12 21:43:58 +00:00
Eric Liu b45c0d4ff0 [ELF] avoid 'invalid-noreturn' error.
Summary: elf::fatal is declared "noreturn".

Reviewers: grimar

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D28607

llvm-svn: 291766
2017-01-12 13:13:32 +00:00
George Rimar 0d8af3697a [ELF] - Reuse Decompressor class.
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
2017-01-12 10:53:31 +00:00
Rui Ueyama 72b1ee2533 Make getColorDiagnostics return a boolean value instead of an enum.
Config->ColorDiagnostics was of type enum before. Now it is just a
boolean flag. Thanks Rafael for suggestion.

llvm-svn: 287978
2016-11-26 15:10:01 +00:00
Rui Ueyama c01321c6b8 Do not print out ARGV0 in white because it's unreadable on white background.
llvm-svn: 287950
2016-11-25 20:37:16 +00:00
Rui Ueyama 8c8818a58c Support -color-diagnostics={auto,always,never}.
-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
2016-11-25 20:27:32 +00:00
Rui Ueyama d4c94d1899 Include a hint how to see all errors if error is truncated.
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
2016-11-24 20:31:43 +00:00
Rui Ueyama f373dd76ce Remove HasError and use ErrorCount instead.
HasError was always true if ErrorCount > 0, so we can use ErrorCount instead.

llvm-svn: 287849
2016-11-24 01:43:21 +00:00
Rui Ueyama 0ede7f281e Make log(), error() and fatal() thread-safe.
llvm-svn: 287794
2016-11-23 18:34:28 +00:00
Rui Ueyama ac95f6bfcc Limit default maximum number of errors to 20.
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
2016-11-23 18:15:37 +00:00
Rui Ueyama 169e7c4edc Call flush() after llvm_shutdown().
llvm_shutdown could write something to outs or errs,
so we need to flush them after calling llvm_shutdown.

llvm-svn: 286548
2016-11-11 02:16:15 +00:00
Davide Italiano 604d313816 [LTO] Call llvm_shutdown on early exit.
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
2016-11-10 19:39:05 +00:00
Rafael Espindola a8631e3887 Use fewer allocators.
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
2016-10-27 13:32:32 +00:00
Rui Ueyama 22646a80f4 Include ARGV[0] in error messages.
This is what other linkers and clang driver do.

Differential Revision: https://reviews.llvm.org/D25780

llvm-svn: 284634
2016-10-19 20:05:43 +00:00
Eugene Leviant 74c1b6c548 [ELF] Add "error" and "warning" prefixes to linker messages
Differential revision: https://reviews.llvm.org/D25729

llvm-svn: 284575
2016-10-19 09:35:19 +00:00
George Rimar b7aec33125 [ELF] - Do not crash when unable to parse ELF object file.
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
2016-10-07 08:51:57 +00:00
Rui Ueyama f65f56e002 Remove useless function.
llvm-svn: 283488
2016-10-06 20:04:54 +00:00
Rui Ueyama d31e13f287 Rename warning -> warn.
It's better because it's a verb.

llvm-svn: 282763
2016-09-29 21:00:23 +00:00
Rafael Espindola 01c078966d Delete dead code.
And make it easier to spot code going dead by using elf::.

llvm-svn: 275858
2016-07-18 18:24:41 +00:00
Rui Ueyama 112351dc38 Avoid writing to errs().
We should write to ErrorOS instead. Normaly, *ErrorOS == errs(),
but they can be different if LLD is embedded.

llvm-svn: 275525
2016-07-15 02:51:05 +00:00
Rui Ueyama aa2db88984 ELF: Make error() to always set HasError.
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
2016-07-15 01:38:54 +00:00
Lang Hames 622ef17f5d [lld] Update LLD for Archive::child_iterator change in LLVM r275361.
llvm-svn: 275362
2016-07-14 02:35:18 +00:00
Rafael Espindola d10f0b1eae Use "using namespace llvm" like the rest of ELF lld.
llvm-svn: 274755
2016-07-07 14:06:38 +00:00
George Rimar 857644cef8 [ELF] - Implemented --fatal-warnings option.
--fatal-warnings: Treat warnings as errors

DIfferential revision: http://reviews.llvm.org/D21969

llvm-svn: 274504
2016-07-04 13:43:12 +00:00
Rafael Espindola 2c51e619d5 Print the cpio trailer after every member.
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
2016-05-04 12:47:56 +00:00
Rafael Espindola 1dd2b3d1d0 Produce cpio files for --reproduce.
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
2016-05-03 17:30:44 +00:00
Rui Ueyama 860b13fc02 Remove dead code.
llvm-svn: 263363
2016-03-13 04:25:43 +00:00
Rui Ueyama 6eafa7fb23 Do not return a bool value from error().
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
2016-03-13 04:25:41 +00:00
Rafael Espindola 75714f618c Rename 'fatal' to 'check' when it doesn't always fail.
llvm-svn: 262666
2016-03-03 22:24:39 +00:00
Rafael Espindola ec9957bd0b Delete dead code.
llvm-svn: 262653
2016-03-03 20:45:26 +00:00
Rafael Espindola 1130935c4a Simplify error handling.
This makes fatal return T when there is no error. This avoids the need
for quite a few temporaries.

llvm-svn: 262626
2016-03-03 16:21:44 +00:00
Rafael Espindola e0df00b91f Rename elf2 to elf.
llvm-svn: 262159
2016-02-28 00:25:54 +00:00
Rui Ueyama 10bd283041 ELF: Define log() to print out message if --verbose is given.
llvm-svn: 261919
2016-02-25 18:56:01 +00:00
Rui Ueyama b6940115a8 ELF: Make link() to take an output stream to which error messages are written.
http://reviews.llvm.org/D16668

llvm-svn: 259597
2016-02-02 22:49:32 +00:00
Rui Ueyama 21eecb4f14 Re-submit ELF: Report multiple errors from the driver.
This reverts r259395 which reverted r259143.

llvm-svn: 259572
2016-02-02 21:13:09 +00:00
Nico Weber f07bd3b72d Revert r259143, it broke check-lld on Windows (see PR26388).
llvm-svn: 259395
2016-02-01 20:03:53 +00:00
Rui Ueyama 1940424632 ELF: Report multiple errors from the driver.
This patch let the driver keep going until it parses all
command line options.

http://reviews.llvm.org/D16645

llvm-svn: 259143
2016-01-29 01:54:52 +00:00
Rui Ueyama 64cfffd333 ELF: Rename error -> fatal and redefine error as a non-noreturn function.
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
2016-01-28 18:40:06 +00:00
Rui Ueyama d5b5ab7638 [ELF2] Output of all unknown arguments instead of only one.
Patch from George Rimar!

llvm-svn: 248524
2015-09-24 18:55:33 +00:00
Rafael Espindola 192e1fa59d Move the error handling functions to Error.h. NFC.
llvm-svn: 244216
2015-08-06 15:08:23 +00:00