Index: ELF/Driver.h =================================================================== --- ELF/Driver.h +++ ELF/Driver.h @@ -14,6 +14,7 @@ #include "lld/Core/LLVM.h" #include "llvm/ADT/StringRef.h" #include "llvm/Option/ArgList.h" +#include "llvm/Support/raw_ostream.h" namespace lld { namespace elf2 { @@ -21,7 +22,7 @@ extern class LinkerDriver *Driver; // Entry point of the ELF linker. -bool link(ArrayRef Args); +bool link(ArrayRef Args, llvm::raw_ostream &Error = llvm::errs()); class LinkerDriver { public: Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -29,8 +29,9 @@ Configuration *elf2::Config; LinkerDriver *elf2::Driver; -bool elf2::link(ArrayRef Args) { +bool elf2::link(ArrayRef Args, raw_ostream &Error) { HasError = false; + ErrorOS = &Error; Configuration C; LinkerDriver D; Config = &C; Index: ELF/Error.h =================================================================== --- ELF/Error.h +++ ELF/Error.h @@ -12,10 +12,15 @@ #include "lld/Core/LLVM.h" +namespace llvm { +class raw_ostream; +} + namespace lld { namespace elf2 { extern thread_local bool HasError; +extern thread_local llvm::raw_ostream *ErrorOS; void warning(const Twine &Msg); @@ -31,16 +36,6 @@ return error(V.getError()); } -LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg); -void fatal(std::error_code EC, const Twine &Prefix); -void fatal(std::error_code EC); - -template void fatal(const ErrorOr &V, const Twine &Prefix) { - fatal(V.getError(), Prefix); -} - -template void fatal(const ErrorOr &V) { fatal(V.getError()); } - } // namespace elf2 } // namespace lld Index: ELF/Error.cpp =================================================================== --- ELF/Error.cpp +++ ELF/Error.cpp @@ -16,11 +16,12 @@ namespace elf2 { thread_local bool HasError; +thread_local llvm::raw_ostream *ErrorOS; void warning(const Twine &Msg) { llvm::errs() << Msg << "\n"; } void error(const Twine &Msg) { - llvm::errs() << Msg << "\n"; + *ErrorOS << Msg << "\n"; HasError = true; } @@ -38,20 +39,5 @@ return true; } -void fatal(const Twine &Msg) { - llvm::errs() << Msg << "\n"; - exit(1); -} - -void fatal(std::error_code EC, const Twine &Prefix) { - if (EC) - fatal(Prefix + ": " + EC.message()); -} - -void fatal(std::error_code EC) { - if (EC) - fatal(EC.message()); -} - } // namespace elf2 } // namespace lld Index: include/lld/Driver/Driver.h =================================================================== --- include/lld/Driver/Driver.h +++ include/lld/Driver/Driver.h @@ -125,7 +125,7 @@ } namespace elf2 { -bool link(llvm::ArrayRef args); +bool link(llvm::ArrayRef args, raw_ostream &diag = llvm::errs()); } /// Driver for lld unit tests Index: lib/Driver/UniversalDriver.cpp =================================================================== --- lib/Driver/UniversalDriver.cpp +++ lib/Driver/UniversalDriver.cpp @@ -205,7 +205,7 @@ case Flavor::old_gnu_ld: return GnuLdDriver::linkELF(args, diagnostics); case Flavor::gnu_ld: - return elf2::link(args); + return elf2::link(args, diagnostics); case Flavor::darwin_ld: return DarwinLdDriver::linkMachO(args, diagnostics); case Flavor::win_link: