Index: COFF/LTO.cpp =================================================================== --- COFF/LTO.cpp +++ COFF/LTO.cpp @@ -12,6 +12,7 @@ #include "InputFiles.h" #include "Symbols.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Strings.h" #include "lld/Common/TargetOptionsCommandFlags.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" @@ -40,27 +41,6 @@ using namespace lld; using namespace lld::coff; -static void diagnosticHandler(const DiagnosticInfo &DI) { - SmallString<128> ErrStorage; - raw_svector_ostream OS(ErrStorage); - DiagnosticPrinterRawOStream DP(OS); - DI.print(DP); - warn(ErrStorage); -} - -static void checkError(Error E) { - handleAllErrors(std::move(E), - [&](ErrorInfoBase &EIB) { error(EIB.message()); }); -} - -static void saveBuffer(StringRef Buffer, const Twine &Path) { - std::error_code EC; - raw_fd_ostream OS(Path.str(), EC, sys::fs::OpenFlags::F_None); - if (EC) - error("cannot create " + Path + ": " + EC.message()); - OS << Buffer; -} - static std::unique_ptr createLTO() { lto::Config Conf; Conf.Options = InitTargetOptionsFromCodeGenFlags(); Index: COFF/SymbolTable.cpp =================================================================== --- COFF/SymbolTable.cpp +++ COFF/SymbolTable.cpp @@ -38,8 +38,9 @@ if (Config->Machine == IMAGE_FILE_MACHINE_UNKNOWN) { Config->Machine = MT; } else if (MT != IMAGE_FILE_MACHINE_UNKNOWN && Config->Machine != MT) { - fatal(toString(File) + ": machine type " + machineToStr(MT) + + error(toString(File) + ": machine type " + machineToStr(MT) + " conflicts with " + machineToStr(Config->Machine)); + return; } if (auto *F = dyn_cast(File)) { Index: Common/ErrorHandler.cpp =================================================================== --- Common/ErrorHandler.cpp +++ Common/ErrorHandler.cpp @@ -12,7 +12,8 @@ #include "lld/Common/Threads.h" #include "llvm/ADT/Twine.h" -#include "llvm/Support/Error.h" +#include "llvm/IR/DiagnosticInfo.h" +#include "llvm/IR/DiagnosticPrinter.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/raw_ostream.h" #include @@ -59,6 +60,19 @@ _exit(Val); } +void lld::diagnosticHandler(const DiagnosticInfo &DI) { + SmallString<128> ErrStorage; + raw_svector_ostream OS(ErrStorage); + DiagnosticPrinterRawOStream DP(OS); + DI.print(DP); + warn(ErrStorage); +} + +void lld::checkError(Error E) { + handleAllErrors(std::move(E), + [&](ErrorInfoBase &EIB) { error(EIB.message()); }); +} + void ErrorHandler::print(StringRef S, raw_ostream::Colors C) { *ErrorOS << LogName << ": "; if (ColorDiagnostics) { Index: Common/Strings.cpp =================================================================== --- Common/Strings.cpp +++ Common/Strings.cpp @@ -98,3 +98,12 @@ std::all_of(S.begin() + 1, S.end(), [](char C) { return C == '_' || isAlnum(C); }); } + +// Write the contents of the a buffer to a file +void lld::saveBuffer(StringRef Buffer, const Twine &Path) { + std::error_code EC; + raw_fd_ostream OS(Path.str(), EC, sys::fs::OpenFlags::F_None); + if (EC) + error("cannot create " + Path + ": " + EC.message()); + OS << Buffer; +} Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -1017,8 +1017,9 @@ case Triple::x86_64: return EM_X86_64; default: - fatal(Path + ": could not infer e_machine from bitcode target triple " + + error(Path + ": could not infer e_machine from bitcode target triple " + T.str()); + return EM_NONE; } } @@ -1065,7 +1066,7 @@ static Symbol *createBitcodeSymbol(const std::vector &KeptComdats, const lto::InputFile::Symbol &ObjSym, BitcodeFile &F) { - StringRef NameRef = Saver.save(ObjSym.getName()); + StringRef Name = Saver.save(ObjSym.getName()); uint32_t Binding = ObjSym.isWeak() ? STB_WEAK : STB_GLOBAL; uint8_t Type = ObjSym.isTLS() ? STT_TLS : STT_NOTYPE; @@ -1074,20 +1075,20 @@ int C = ObjSym.getComdatIndex(); if (C != -1 && !KeptComdats[C]) - return Symtab->addUndefined(NameRef, Binding, Visibility, Type, + return Symtab->addUndefined(Name, Binding, Visibility, Type, CanOmitFromDynSym, &F); if (ObjSym.isUndefined()) - return Symtab->addUndefined(NameRef, Binding, Visibility, Type, + return Symtab->addUndefined(Name, Binding, Visibility, Type, CanOmitFromDynSym, &F); if (ObjSym.isCommon()) - return Symtab->addCommon(NameRef, ObjSym.getCommonSize(), + return Symtab->addCommon(Name, ObjSym.getCommonSize(), ObjSym.getCommonAlignment(), Binding, Visibility, STT_OBJECT, F); - return Symtab->addBitcode(NameRef, Binding, Visibility, Type, - CanOmitFromDynSym, F); + return Symtab->addBitcode(Name, Binding, Visibility, Type, CanOmitFromDynSym, + F); } template Index: ELF/LTO.cpp =================================================================== --- ELF/LTO.cpp +++ ELF/LTO.cpp @@ -45,28 +45,6 @@ using namespace lld; using namespace lld::elf; -// This is for use when debugging LTO. -static void saveBuffer(StringRef Buffer, const Twine &Path) { - std::error_code EC; - raw_fd_ostream OS(Path.str(), EC, sys::fs::OpenFlags::F_None); - if (EC) - error("cannot create " + Path + ": " + EC.message()); - OS << Buffer; -} - -static void diagnosticHandler(const DiagnosticInfo &DI) { - SmallString<128> S; - raw_svector_ostream OS(S); - DiagnosticPrinterRawOStream DP(OS); - DI.print(DP); - warn(S); -} - -static void checkError(Error E) { - handleAllErrors(std::move(E), - [&](ErrorInfoBase &EIB) { error(EIB.message()); }); -} - // Creates an empty file to store a list of object files for final // linking of distributed ThinLTO. static std::unique_ptr openFile(StringRef File) { Index: include/lld/Common/ErrorHandler.h =================================================================== --- include/lld/Common/ErrorHandler.h +++ include/lld/Common/ErrorHandler.h @@ -34,6 +34,10 @@ #include "llvm/Support/Error.h" #include "llvm/Support/FileOutputBuffer.h" +namespace llvm { +class DiagnosticInfo; +} + namespace lld { class ErrorHandler { @@ -74,6 +78,9 @@ LLVM_ATTRIBUTE_NORETURN void exitLld(int Val); +void diagnosticHandler(const llvm::DiagnosticInfo &DI); +void checkError(Error E); + // check functions are convenient functions to strip errors // from error-or-value objects. template T check(ErrorOr E) { Index: include/lld/Common/Strings.h =================================================================== --- include/lld/Common/Strings.h +++ include/lld/Common/Strings.h @@ -26,6 +26,9 @@ std::vector parseHex(llvm::StringRef S); bool isValidCIdentifier(llvm::StringRef S); +// Write the contents of the a buffer to a file +void saveBuffer(llvm::StringRef Buffer, const llvm::Twine &Path); + // This class represents multiple glob patterns. class StringMatcher { public: @@ -41,6 +44,6 @@ inline llvm::ArrayRef toArrayRef(llvm::StringRef S) { return {reinterpret_cast(S.data()), S.size()}; } -} +} // namespace lld #endif