Files
clang-p2996/lld/ELF/Error.cpp
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

55 lines
1.1 KiB
C++

//===- Error.cpp ----------------------------------------------------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "Error.h"
#include "Config.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
namespace lld {
bool elf::HasError;
raw_ostream *elf::ErrorOS;
void elf::log(const Twine &Msg) {
if (Config->Verbose)
outs() << Msg << "\n";
}
void elf::warn(const Twine &Msg) {
if (Config->FatalWarnings)
error(Msg);
else
*ErrorOS << Msg << "\n";
}
void elf::error(const Twine &Msg) {
*ErrorOS << Msg << "\n";
HasError = true;
}
void elf::error(std::error_code EC, const Twine &Prefix) {
error(Prefix + ": " + EC.message());
}
void elf::fatal(const Twine &Msg) {
*ErrorOS << Msg << "\n";
exit(1);
}
void elf::fatal(std::error_code EC, const Twine &Prefix) {
fatal(Prefix + ": " + EC.message());
}
} // namespace lld