This is an archive of the discontinued LLVM Phabricator instance.

COFF: add error() and warn() to Error.{cpp,h}
ClosedPublic

Authored by inglorion on Jan 13 2017, 12:47 PM.

Details

Summary

This copies over some functionality we have in ELF/Error.{cpp,h} and makes it available in COFF/Error.{cpp,h}

Event Timeline

inglorion updated this revision to Diff 84355.Jan 13 2017, 12:47 PM
inglorion retitled this revision from to add error, log, and warn to COFF/Error.{cpp,h}.
inglorion updated this object.
inglorion added reviewers: pcc, rafael, ruiu.

I'm refactoring the COFF linker's LTO support to use the new LTO API. To keep the code as similar as possible to what we do in the ELF linker, I'll be re-using some code that uses the functions being added here.

ruiu added inline comments.Jan 13 2017, 12:52 PM
COFF/Config.h
83

You don't seem to set a value to ColorDiagnostics. Does this mean it error messages are always printed in black/white? Doesn't Process::StandardErrHasColors work for Windows?

COFF/Error.h
26

This was removed from ELF, so you don't want to add it to COFF. You can always do error("somthing failed: " + EC.message()) instead of error(EC, "something failed").

Thanks for taking a look, @ruiu. I'll remove the functions that no longer exist in ELF. As for colors, I didn't need that for what I was doing, so I didn't make it do anything. Want me to include that in this patch or in a follow-up?

ruiu edited edge metadata.Jan 13 2017, 1:07 PM

If you are not going to set a value to Config->ColorDiagnostics, if (Config->ColorDiagnostics) part is dead code, but I don't think we want to check in dead code. How about adding this one line to the driver?

Config->Diagnostics = (ErrorOS == llvm::errs() && Process::StandardErrHasColors());
inglorion updated this revision to Diff 84366.Jan 13 2017, 1:51 PM
inglorion retitled this revision from add error, log, and warn to COFF/Error.{cpp,h} to COFF: add error() and warn() to Error.{cpp,h}.
inglorion edited edge metadata.

Changes requested by @ruiu:

  • Only add error(const Twine &Msg), not the variant that has since been removed.
  • Initialize Config->ColorDiagnostics based on color support in error stream.
  • Also updated existing code to use Config->ColorDiagnostics, instead of using its own detection.
  • Updated the title of the change to reflect that we're only adding error() and warn().
ruiu added inline comments.Jan 13 2017, 1:55 PM
COFF/Config.h
83

nit: remove = false as the default value will always be overwrote.

87

Since this is always true, please remove the variable.

COFF/Error.cpp
15

Are you actually using this header?

68–69

It is OK to call exitLld unconditionally in COFF.

95–98

I think you want to remove this code and Config::FatalWarnings. (This is using an uninitialized value.)

inglorion added inline comments.Jan 13 2017, 2:13 PM
COFF/Error.cpp
15

llvm_shutdown() (used in exitLld) comes from that header.

inglorion updated this revision to Diff 84382.Jan 13 2017, 2:17 PM

Changes requested by @ruiu:

  • Removed Config->ExitEarly and Config->FatalWarnings and the code that checks their values.
inglorion updated this revision to Diff 84385.Jan 13 2017, 2:21 PM

Removed no-longer-needed initialization of Config->ColorDiagnostics in Config.h.

ruiu accepted this revision.Jan 13 2017, 2:24 PM
ruiu edited edge metadata.

LGTM with this fix.

COFF/Error.cpp
95–96

Debug code or something?

This revision is now accepted and ready to land.Jan 13 2017, 2:24 PM
inglorion added inline comments.Jan 13 2017, 2:30 PM
COFF/Error.cpp
95–96

Nope...that's a bug I just introduced. Fixing...

inglorion updated this revision to Diff 84389.Jan 13 2017, 2:37 PM
inglorion edited edge metadata.

Use exitLld instead of _exit in fatal(), make warn() not fatal, and mark exitLld() noreturn.

inglorion marked 4 inline comments as done.Jan 17 2017, 10:55 AM
This revision was automatically updated to reflect the committed changes.
pcc added inline comments.Jan 26 2017, 11:57 AM
lld/trunk/COFF/Error.cpp
67 ↗(On Diff #84708)

It looks like this isn't actually configurable in the COFF linker.