Remove 'using std::error_code' from tools.

llvm-svn: 210876
This commit is contained in:
Rafael Espindola 2014-06-13 03:07:50 +00:00
parent 567b1546ac
commit 4453e42945
33 changed files with 167 additions and 194 deletions

View File

@ -22,7 +22,6 @@
#include <fstream> #include <fstream>
using namespace llvm; using namespace llvm;
using std::error_code;
namespace { namespace {
// OutputType - Allow the user to specify the way code should be run, to test // OutputType - Allow the user to specify the way code should be run, to test
@ -268,7 +267,7 @@ void BugDriver::compileProgram(Module *M, std::string *Error) const {
// Emit the program to a bitcode file... // Emit the program to a bitcode file...
SmallString<128> BitcodeFile; SmallString<128> BitcodeFile;
int BitcodeFD; int BitcodeFD;
error_code EC = sys::fs::createUniqueFile( std::error_code EC = sys::fs::createUniqueFile(
OutputPrefix + "-test-program-%%%%%%%.bc", BitcodeFD, BitcodeFile); OutputPrefix + "-test-program-%%%%%%%.bc", BitcodeFD, BitcodeFile);
if (EC) { if (EC) {
errs() << ToolName << ": Error making unique filename: " << EC.message() errs() << ToolName << ": Error making unique filename: " << EC.message()
@ -306,7 +305,7 @@ std::string BugDriver::executeProgram(const Module *Program,
// Emit the program to a bitcode file... // Emit the program to a bitcode file...
SmallString<128> UniqueFilename; SmallString<128> UniqueFilename;
int UniqueFD; int UniqueFD;
error_code EC = sys::fs::createUniqueFile( std::error_code EC = sys::fs::createUniqueFile(
OutputPrefix + "-test-program-%%%%%%%.bc", UniqueFD, UniqueFilename); OutputPrefix + "-test-program-%%%%%%%.bc", UniqueFD, UniqueFilename);
if (EC) { if (EC) {
errs() << ToolName << ": Error making unique filename: " errs() << ToolName << ": Error making unique filename: "
@ -332,7 +331,7 @@ std::string BugDriver::executeProgram(const Module *Program,
// Check to see if this is a valid output filename... // Check to see if this is a valid output filename...
SmallString<128> UniqueFile; SmallString<128> UniqueFile;
error_code EC = sys::fs::createUniqueFile(OutputFile, UniqueFile); std::error_code EC = sys::fs::createUniqueFile(OutputFile, UniqueFile);
if (EC) { if (EC) {
errs() << ToolName << ": Error making unique filename: " errs() << ToolName << ": Error making unique filename: "
<< EC.message() << "\n"; << EC.message() << "\n";

View File

@ -33,7 +33,6 @@
#include "llvm/Transforms/Utils/CodeExtractor.h" #include "llvm/Transforms/Utils/CodeExtractor.h"
#include <set> #include <set>
using namespace llvm; using namespace llvm;
using std::error_code;
#define DEBUG_TYPE "bugpoint" #define DEBUG_TYPE "bugpoint"
@ -367,7 +366,7 @@ Module *BugDriver::ExtractMappedBlocksFromModule(const
Module *M) { Module *M) {
SmallString<128> Filename; SmallString<128> Filename;
int FD; int FD;
error_code EC = sys::fs::createUniqueFile( std::error_code EC = sys::fs::createUniqueFile(
OutputPrefix + "-extractblocks%%%%%%%", FD, Filename); OutputPrefix + "-extractblocks%%%%%%%", FD, Filename);
if (EC) { if (EC) {
outs() << "*** Basic Block extraction failed!\n"; outs() << "*** Basic Block extraction failed!\n";

View File

@ -27,7 +27,6 @@
#include "llvm/Support/FileUtilities.h" #include "llvm/Support/FileUtilities.h"
#include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Transforms/Utils/Cloning.h"
using namespace llvm; using namespace llvm;
using std::error_code;
namespace llvm { namespace llvm {
extern cl::opt<std::string> OutputPrefix; extern cl::opt<std::string> OutputPrefix;
@ -965,8 +964,8 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe,
SmallString<128> TestModuleBC; SmallString<128> TestModuleBC;
int TestModuleFD; int TestModuleFD;
error_code EC = sys::fs::createTemporaryFile("bugpoint.test", "bc", std::error_code EC = sys::fs::createTemporaryFile("bugpoint.test", "bc",
TestModuleFD, TestModuleBC); TestModuleFD, TestModuleBC);
if (EC) { if (EC) {
errs() << BD.getToolName() << "Error making unique filename: " errs() << BD.getToolName() << "Error making unique filename: "
<< EC.message() << "\n"; << EC.message() << "\n";
@ -1059,8 +1058,8 @@ bool BugDriver::debugCodeGenerator(std::string *Error) {
SmallString<128> TestModuleBC; SmallString<128> TestModuleBC;
int TestModuleFD; int TestModuleFD;
error_code EC = sys::fs::createTemporaryFile("bugpoint.test", "bc", std::error_code EC = sys::fs::createTemporaryFile("bugpoint.test", "bc",
TestModuleFD, TestModuleBC); TestModuleFD, TestModuleBC);
if (EC) { if (EC) {
errs() << getToolName() << "Error making unique filename: " errs() << getToolName() << "Error making unique filename: "
<< EC.message() << "\n"; << EC.message() << "\n";

View File

@ -35,7 +35,6 @@
#include <fstream> #include <fstream>
using namespace llvm; using namespace llvm;
using std::error_code;
#define DEBUG_TYPE "bugpoint" #define DEBUG_TYPE "bugpoint"
@ -130,7 +129,7 @@ bool BugDriver::runPasses(Module *Program,
// setup the output file name // setup the output file name
outs().flush(); outs().flush();
SmallString<128> UniqueFilename; SmallString<128> UniqueFilename;
error_code EC = sys::fs::createUniqueFile( std::error_code EC = sys::fs::createUniqueFile(
OutputPrefix + "-output-%%%%%%%.bc", UniqueFilename); OutputPrefix + "-output-%%%%%%%.bc", UniqueFilename);
if (EC) { if (EC) {
errs() << getToolName() << ": Error making unique filename: " errs() << getToolName() << ": Error making unique filename: "

View File

@ -22,7 +22,6 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
using namespace llvm; using namespace llvm;
using std::error_code;
#define DEBUG_TYPE "toolrunner" #define DEBUG_TYPE "toolrunner"
@ -143,7 +142,7 @@ static std::string ProcessFailure(StringRef ProgPath, const char** Args,
// Rerun the compiler, capturing any error messages to print them. // Rerun the compiler, capturing any error messages to print them.
SmallString<128> ErrorFilename; SmallString<128> ErrorFilename;
int ErrorFD; int ErrorFD;
error_code EC = sys::fs::createTemporaryFile( std::error_code EC = sys::fs::createTemporaryFile(
"bugpoint.program_error_messages", "", ErrorFD, ErrorFilename); "bugpoint.program_error_messages", "", ErrorFD, ErrorFilename);
if (EC) { if (EC) {
errs() << "Error making unique filename: " << EC.message() << "\n"; errs() << "Error making unique filename: " << EC.message() << "\n";
@ -479,7 +478,7 @@ GCC::FileType LLC::OutputCode(const std::string &Bitcode,
const char *Suffix = (UseIntegratedAssembler ? ".llc.o" : ".llc.s"); const char *Suffix = (UseIntegratedAssembler ? ".llc.o" : ".llc.s");
SmallString<128> UniqueFile; SmallString<128> UniqueFile;
error_code EC = std::error_code EC =
sys::fs::createUniqueFile(Bitcode + "-%%%%%%%" + Suffix, UniqueFile); sys::fs::createUniqueFile(Bitcode + "-%%%%%%%" + Suffix, UniqueFile);
if (EC) { if (EC) {
errs() << "Error making unique filename: " << EC.message() << "\n"; errs() << "Error making unique filename: " << EC.message() << "\n";
@ -716,7 +715,7 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
GCCArgs.push_back("-o"); GCCArgs.push_back("-o");
SmallString<128> OutputBinary; SmallString<128> OutputBinary;
error_code EC = std::error_code EC =
sys::fs::createUniqueFile(ProgramFile + "-%%%%%%%.gcc.exe", OutputBinary); sys::fs::createUniqueFile(ProgramFile + "-%%%%%%%.gcc.exe", OutputBinary);
if (EC) { if (EC) {
errs() << "Error making unique filename: " << EC.message() << "\n"; errs() << "Error making unique filename: " << EC.message() << "\n";
@ -826,7 +825,7 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
const std::vector<std::string> &ArgsForGCC, const std::vector<std::string> &ArgsForGCC,
std::string &Error) { std::string &Error) {
SmallString<128> UniqueFilename; SmallString<128> UniqueFilename;
error_code EC = sys::fs::createUniqueFile( std::error_code EC = sys::fs::createUniqueFile(
InputFile + "-%%%%%%%" + LTDL_SHLIB_EXT, UniqueFilename); InputFile + "-%%%%%%%" + LTDL_SHLIB_EXT, UniqueFilename);
if (EC) { if (EC) {
errs() << "Error making unique filename: " << EC.message() << "\n"; errs() << "Error making unique filename: " << EC.message() << "\n";

View File

@ -44,7 +44,6 @@
#endif #endif
using namespace llvm; using namespace llvm;
using std::error_code;
namespace { namespace {
ld_plugin_status discard_message(int level, const char *format, ...) { ld_plugin_status discard_message(int level, const char *format, ...) {
@ -259,7 +258,7 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file,
if (file->offset) { if (file->offset) {
offset = file->offset; offset = file->offset;
} }
if (error_code ec = MemoryBuffer::getOpenFileSlice( if (std::error_code ec = MemoryBuffer::getOpenFileSlice(
file->fd, file->name, buffer, file->filesize, offset)) { file->fd, file->name, buffer, file->filesize, offset)) {
(*message)(LDPL_ERROR, ec.message().c_str()); (*message)(LDPL_ERROR, ec.message().c_str());
return LDPS_ERR; return LDPS_ERR;
@ -485,7 +484,7 @@ static ld_plugin_status all_symbols_read_hook(void) {
static ld_plugin_status cleanup_hook(void) { static ld_plugin_status cleanup_hook(void) {
for (int i = 0, e = Cleanup.size(); i != e; ++i) { for (int i = 0, e = Cleanup.size(); i != e; ++i) {
error_code EC = sys::fs::remove(Cleanup[i]); std::error_code EC = sys::fs::remove(Cleanup[i]);
if (EC) if (EC)
(*message)(LDPL_ERROR, "Failed to delete '%s': %s", Cleanup[i].c_str(), (*message)(LDPL_ERROR, "Failed to delete '%s': %s", Cleanup[i].c_str(),
EC.message().c_str()); EC.message().c_str());

View File

@ -19,7 +19,6 @@
#include "llvm/Support/Format.h" #include "llvm/Support/Format.h"
using namespace llvm; using namespace llvm;
using std::error_code;
#define DEBUG_TYPE "lli" #define DEBUG_TYPE "lli"
@ -62,7 +61,7 @@ allocateDataSection(uintptr_t Size, unsigned Alignment,
} }
sys::MemoryBlock RemoteMemoryManager::allocateSection(uintptr_t Size) { sys::MemoryBlock RemoteMemoryManager::allocateSection(uintptr_t Size) {
error_code ec; std::error_code ec;
sys::MemoryBlock MB = sys::Memory::allocateMappedMemory(Size, sys::MemoryBlock MB = sys::Memory::allocateMappedMemory(Size,
&Near, &Near,
sys::Memory::MF_READ | sys::Memory::MF_READ |

View File

@ -62,7 +62,6 @@
#endif #endif
using namespace llvm; using namespace llvm;
using std::error_code;
#define DEBUG_TYPE "lli" #define DEBUG_TYPE "lli"
@ -416,7 +415,7 @@ int main(int argc, char **argv, char * const *envp) {
// If not jitting lazily, load the whole bitcode file eagerly too. // If not jitting lazily, load the whole bitcode file eagerly too.
if (NoLazyCompilation) { if (NoLazyCompilation) {
if (error_code EC = Mod->materializeAllPermanently()) { if (std::error_code EC = Mod->materializeAllPermanently()) {
errs() << argv[0] << ": bitcode didn't read correctly.\n"; errs() << argv[0] << ": bitcode didn't read correctly.\n";
errs() << "Reason: " << EC.message() << "\n"; errs() << "Reason: " << EC.message() << "\n";
exit(1); exit(1);
@ -540,7 +539,7 @@ int main(int argc, char **argv, char * const *envp) {
for (unsigned i = 0, e = ExtraArchives.size(); i != e; ++i) { for (unsigned i = 0, e = ExtraArchives.size(); i != e; ++i) {
std::unique_ptr<MemoryBuffer> ArBuf; std::unique_ptr<MemoryBuffer> ArBuf;
error_code ec; std::error_code ec;
ec = MemoryBuffer::getFileOrSTDIN(ExtraArchives[i], ArBuf); ec = MemoryBuffer::getFileOrSTDIN(ExtraArchives[i], ArBuf);
if (ec) { if (ec) {
Err.print(argv[0], errs()); Err.print(argv[0], errs());

View File

@ -36,7 +36,6 @@
#endif #endif
using namespace llvm; using namespace llvm;
using std::error_code;
// The name this program was invoked as. // The name this program was invoked as.
static StringRef ToolName; static StringRef ToolName;
@ -54,7 +53,7 @@ LLVM_ATTRIBUTE_NORETURN static void fail(Twine Error) {
exit(1); exit(1);
} }
static void failIfError(error_code EC, Twine Context = "") { static void failIfError(std::error_code EC, Twine Context = "") {
if (!EC) if (!EC)
return; return;
@ -939,7 +938,7 @@ int ar_main(char **argv) {
static int performOperation(ArchiveOperation Operation) { static int performOperation(ArchiveOperation Operation) {
// Create or open the archive object. // Create or open the archive object.
std::unique_ptr<MemoryBuffer> Buf; std::unique_ptr<MemoryBuffer> Buf;
error_code EC = MemoryBuffer::getFile(ArchiveName, Buf, -1, false); std::error_code EC = MemoryBuffer::getFile(ArchiveName, Buf, -1, false);
if (EC && EC != std::errc::no_such_file_or_directory) { if (EC && EC != std::errc::no_such_file_or_directory) {
errs() << ToolName << ": error opening '" << ArchiveName errs() << ToolName << ": error opening '" << ArchiveName
<< "': " << EC.message() << "!\n"; << "': " << EC.message() << "!\n";

View File

@ -43,7 +43,6 @@
#include <map> #include <map>
#include <system_error> #include <system_error>
using namespace llvm; using namespace llvm;
using std::error_code;
static cl::opt<std::string> static cl::opt<std::string>
InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-")); InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-"));
@ -481,8 +480,7 @@ static int AnalyzeBitcode() {
// Read the input file. // Read the input file.
std::unique_ptr<MemoryBuffer> MemBuf; std::unique_ptr<MemoryBuffer> MemBuf;
if (error_code ec = if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename, MemBuf))
MemoryBuffer::getFileOrSTDIN(InputFilename, MemBuf))
return Error("Error reading '" + InputFilename + "': " + ec.message()); return Error("Error reading '" + InputFilename + "': " + ec.message());
if (MemBuf->getBufferSize() & 3) if (MemBuf->getBufferSize() & 3)

View File

@ -22,7 +22,6 @@
#include "llvm/Support/Signals.h" #include "llvm/Support/Signals.h"
#include <system_error> #include <system_error>
using namespace llvm; using namespace llvm;
using std::error_code;
static cl::opt<std::string> SourceFile(cl::Positional, cl::Required, static cl::opt<std::string> SourceFile(cl::Positional, cl::Required,
cl::desc("SOURCEFILE")); cl::desc("SOURCEFILE"));
@ -105,7 +104,7 @@ int main(int argc, char **argv) {
GCOVFile GF; GCOVFile GF;
std::unique_ptr<MemoryBuffer> GCNO_Buff; std::unique_ptr<MemoryBuffer> GCNO_Buff;
if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCNO, GCNO_Buff)) { if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCNO, GCNO_Buff)) {
errs() << InputGCNO << ": " << ec.message() << "\n"; errs() << InputGCNO << ": " << ec.message() << "\n";
return 1; return 1;
} }
@ -116,7 +115,7 @@ int main(int argc, char **argv) {
} }
std::unique_ptr<MemoryBuffer> GCDA_Buff; std::unique_ptr<MemoryBuffer> GCDA_Buff;
if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) { if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) {
if (ec != std::errc::no_such_file_or_directory) { if (ec != std::errc::no_such_file_or_directory) {
errs() << InputGCDA << ": " << ec.message() << "\n"; errs() << InputGCDA << ": " << ec.message() << "\n";
return 1; return 1;

View File

@ -34,7 +34,6 @@
#include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/ToolOutputFile.h"
#include <system_error> #include <system_error>
using namespace llvm; using namespace llvm;
using std::error_code;
static cl::opt<std::string> static cl::opt<std::string>
InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-")); InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-"));
@ -138,7 +137,7 @@ int main(int argc, char **argv) {
M.reset(getStreamedBitcodeModule(DisplayFilename, streamer, Context, M.reset(getStreamedBitcodeModule(DisplayFilename, streamer, Context,
&ErrorMessage)); &ErrorMessage));
if(M.get()) { if(M.get()) {
if (error_code EC = M->materializeAllPermanently()) { if (std::error_code EC = M->materializeAllPermanently()) {
ErrorMessage = EC.message(); ErrorMessage = EC.message();
M.reset(); M.reset();
} }

View File

@ -33,7 +33,6 @@
using namespace llvm; using namespace llvm;
using namespace object; using namespace object;
using std::error_code;
static cl::list<std::string> static cl::list<std::string>
InputFilenames(cl::Positional, cl::desc("<input object files>"), InputFilenames(cl::Positional, cl::desc("<input object files>"),
@ -69,13 +68,13 @@ DumpType("debug-dump", cl::init(DIDT_All),
static void DumpInput(const StringRef &Filename) { static void DumpInput(const StringRef &Filename) {
std::unique_ptr<MemoryBuffer> Buff; std::unique_ptr<MemoryBuffer> Buff;
if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) { if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) {
errs() << Filename << ": " << ec.message() << "\n"; errs() << Filename << ": " << ec.message() << "\n";
return; return;
} }
ErrorOr<ObjectFile*> ObjOrErr(ObjectFile::createObjectFile(Buff.release())); ErrorOr<ObjectFile*> ObjOrErr(ObjectFile::createObjectFile(Buff.release()));
if (error_code EC = ObjOrErr.getError()) { if (std::error_code EC = ObjOrErr.getError()) {
errs() << Filename << ": " << EC.message() << '\n'; errs() << Filename << ": " << EC.message() << '\n';
return; return;
} }

View File

@ -40,7 +40,6 @@
#include "llvm/Support/TargetSelect.h" #include "llvm/Support/TargetSelect.h"
#include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/ToolOutputFile.h"
using namespace llvm; using namespace llvm;
using std::error_code;
static cl::opt<std::string> static cl::opt<std::string>
InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-")); InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"));
@ -368,7 +367,8 @@ int main(int argc, char **argv) {
return 1; return 1;
std::unique_ptr<MemoryBuffer> BufferPtr; std::unique_ptr<MemoryBuffer> BufferPtr;
if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename, BufferPtr)) { if (std::error_code ec =
MemoryBuffer::getFileOrSTDIN(InputFilename, BufferPtr)) {
errs() << ProgName << ": " << ec.message() << '\n'; errs() << ProgName << ": " << ec.message() << '\n';
return 1; return 1;
} }

View File

@ -21,7 +21,6 @@
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include <system_error> #include <system_error>
using namespace llvm; using namespace llvm;
using std::error_code;
static cl::list<std::string> static cl::list<std::string>
InputFilenames(cl::Positional, cl::desc("<input files>"), InputFilenames(cl::Positional, cl::desc("<input files>"),
@ -137,7 +136,7 @@ MarkupTag MarkupParser::parseTag() {
static void parseMCMarkup(StringRef Filename) { static void parseMCMarkup(StringRef Filename) {
std::unique_ptr<MemoryBuffer> BufferPtr; std::unique_ptr<MemoryBuffer> BufferPtr;
if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, BufferPtr)) { if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, BufferPtr)) {
errs() << ToolName << ": " << ec.message() << '\n'; errs() << ToolName << ": " << ec.message() << '\n';
return; return;
} }

View File

@ -45,7 +45,6 @@
#include <vector> #include <vector>
using namespace llvm; using namespace llvm;
using namespace object; using namespace object;
using std::error_code;
namespace { namespace {
enum OutputFormatTy { bsd, sysv, posix, darwin }; enum OutputFormatTy { bsd, sysv, posix, darwin };
@ -133,7 +132,7 @@ static void error(Twine Message, Twine Path = Twine()) {
errs() << ToolName << ": " << Path << ": " << Message << ".\n"; errs() << ToolName << ": " << Path << ": " << Message << ".\n";
} }
static bool error(error_code EC, Twine Path = Twine()) { static bool error(std::error_code EC, Twine Path = Twine()) {
if (EC) { if (EC) {
error(EC.message(), Path); error(EC.message(), Path);
return true; return true;

View File

@ -29,7 +29,6 @@
using namespace llvm; using namespace llvm;
using namespace object; using namespace object;
using namespace llvm::Win64EH; using namespace llvm::Win64EH;
using std::error_code;
// Returns the name of the unwind code. // Returns the name of the unwind code.
static StringRef getUnwindCodeTypeName(uint8_t Code) { static StringRef getUnwindCodeTypeName(uint8_t Code) {
@ -158,14 +157,14 @@ static void printAllUnwindCodes(ArrayRef<UnwindCode> UCs) {
} }
// Given a symbol sym this functions returns the address and section of it. // Given a symbol sym this functions returns the address and section of it.
static error_code resolveSectionAndAddress(const COFFObjectFile *Obj, static std::error_code
const SymbolRef &Sym, resolveSectionAndAddress(const COFFObjectFile *Obj, const SymbolRef &Sym,
const coff_section *&ResolvedSection, const coff_section *&ResolvedSection,
uint64_t &ResolvedAddr) { uint64_t &ResolvedAddr) {
if (error_code EC = Sym.getAddress(ResolvedAddr)) if (std::error_code EC = Sym.getAddress(ResolvedAddr))
return EC; return EC;
section_iterator iter(Obj->section_begin()); section_iterator iter(Obj->section_begin());
if (error_code EC = Sym.getSection(iter)) if (std::error_code EC = Sym.getSection(iter))
return EC; return EC;
ResolvedSection = Obj->getCOFFSection(*iter); ResolvedSection = Obj->getCOFFSection(*iter);
return object_error::success; return object_error::success;
@ -173,13 +172,13 @@ static error_code resolveSectionAndAddress(const COFFObjectFile *Obj,
// Given a vector of relocations for a section and an offset into this section // Given a vector of relocations for a section and an offset into this section
// the function returns the symbol used for the relocation at the offset. // the function returns the symbol used for the relocation at the offset.
static error_code resolveSymbol(const std::vector<RelocationRef> &Rels, static std::error_code resolveSymbol(const std::vector<RelocationRef> &Rels,
uint64_t Offset, SymbolRef &Sym) { uint64_t Offset, SymbolRef &Sym) {
for (std::vector<RelocationRef>::const_iterator I = Rels.begin(), for (std::vector<RelocationRef>::const_iterator I = Rels.begin(),
E = Rels.end(); E = Rels.end();
I != E; ++I) { I != E; ++I) {
uint64_t Ofs; uint64_t Ofs;
if (error_code EC = I->getOffset(Ofs)) if (std::error_code EC = I->getOffset(Ofs))
return EC; return EC;
if (Ofs == Offset) { if (Ofs == Offset) {
Sym = *I->getSymbol(); Sym = *I->getSymbol();
@ -193,18 +192,17 @@ static error_code resolveSymbol(const std::vector<RelocationRef> &Rels,
// the function resolves the symbol used for the relocation at the offset and // the function resolves the symbol used for the relocation at the offset and
// returns the section content and the address inside the content pointed to // returns the section content and the address inside the content pointed to
// by the symbol. // by the symbol.
static error_code getSectionContents(const COFFObjectFile *Obj, static std::error_code
const std::vector<RelocationRef> &Rels, getSectionContents(const COFFObjectFile *Obj,
uint64_t Offset, const std::vector<RelocationRef> &Rels, uint64_t Offset,
ArrayRef<uint8_t> &Contents, ArrayRef<uint8_t> &Contents, uint64_t &Addr) {
uint64_t &Addr) {
SymbolRef Sym; SymbolRef Sym;
if (error_code EC = resolveSymbol(Rels, Offset, Sym)) if (std::error_code EC = resolveSymbol(Rels, Offset, Sym))
return EC; return EC;
const coff_section *Section; const coff_section *Section;
if (error_code EC = resolveSectionAndAddress(Obj, Sym, Section, Addr)) if (std::error_code EC = resolveSectionAndAddress(Obj, Sym, Section, Addr))
return EC; return EC;
if (error_code EC = Obj->getSectionContents(Section, Contents)) if (std::error_code EC = Obj->getSectionContents(Section, Contents))
return EC; return EC;
return object_error::success; return object_error::success;
} }
@ -212,12 +210,12 @@ static error_code getSectionContents(const COFFObjectFile *Obj,
// Given a vector of relocations for a section and an offset into this section // Given a vector of relocations for a section and an offset into this section
// the function returns the name of the symbol used for the relocation at the // the function returns the name of the symbol used for the relocation at the
// offset. // offset.
static error_code resolveSymbolName(const std::vector<RelocationRef> &Rels, static std::error_code resolveSymbolName(const std::vector<RelocationRef> &Rels,
uint64_t Offset, StringRef &Name) { uint64_t Offset, StringRef &Name) {
SymbolRef Sym; SymbolRef Sym;
if (error_code EC = resolveSymbol(Rels, Offset, Sym)) if (std::error_code EC = resolveSymbol(Rels, Offset, Sym))
return EC; return EC;
if (error_code EC = Sym.getName(Name)) if (std::error_code EC = Sym.getName(Name))
return EC; return EC;
return object_error::success; return object_error::success;
} }

View File

@ -42,7 +42,6 @@
#include <system_error> #include <system_error>
using namespace llvm; using namespace llvm;
using namespace object; using namespace object;
using std::error_code;
static cl::opt<bool> static cl::opt<bool>
UseDbg("g", cl::desc("Print line information from debug info if available")); UseDbg("g", cl::desc("Print line information from debug info if available"));
@ -198,7 +197,7 @@ static void DisassembleInputMachO2(StringRef Filename,
void llvm::DisassembleInputMachO(StringRef Filename) { void llvm::DisassembleInputMachO(StringRef Filename) {
std::unique_ptr<MemoryBuffer> Buff; std::unique_ptr<MemoryBuffer> Buff;
if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) { if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) {
errs() << "llvm-objdump: " << Filename << ": " << ec.message() << "\n"; errs() << "llvm-objdump: " << Filename << ": " << ec.message() << "\n";
return; return;
} }
@ -290,7 +289,7 @@ static void DisassembleInputMachO2(StringRef Filename,
// get the sections and supply it to the section name parsing machinery. // get the sections and supply it to the section name parsing machinery.
if (!DSYMFile.empty()) { if (!DSYMFile.empty()) {
std::unique_ptr<MemoryBuffer> Buf; std::unique_ptr<MemoryBuffer> Buf;
if (error_code ec = MemoryBuffer::getFileOrSTDIN(DSYMFile, Buf)) { if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(DSYMFile, Buf)) {
errs() << "llvm-objdump: " << Filename << ": " << ec.message() << '\n'; errs() << "llvm-objdump: " << Filename << ": " << ec.message() << '\n';
return; return;
} }

View File

@ -64,7 +64,6 @@
using namespace llvm; using namespace llvm;
using namespace object; using namespace object;
using std::error_code;
static cl::list<std::string> static cl::list<std::string>
InputFilenames(cl::Positional, cl::desc("<input object files>"),cl::ZeroOrMore); InputFilenames(cl::Positional, cl::desc("<input object files>"),cl::ZeroOrMore);
@ -149,7 +148,7 @@ YAMLCFG("yaml-cfg",
static StringRef ToolName; static StringRef ToolName;
bool llvm::error(error_code EC) { bool llvm::error(std::error_code EC) {
if (!EC) if (!EC)
return false; return false;
@ -396,7 +395,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
// Create a mapping, RelocSecs = SectionRelocMap[S], where sections // Create a mapping, RelocSecs = SectionRelocMap[S], where sections
// in RelocSecs contain the relocations for section S. // in RelocSecs contain the relocations for section S.
error_code EC; std::error_code EC;
std::map<SectionRef, SmallVector<SectionRef, 1>> SectionRelocMap; std::map<SectionRef, SmallVector<SectionRef, 1>> SectionRelocMap;
for (const SectionRef &Section : Obj->sections()) { for (const SectionRef &Section : Obj->sections()) {
section_iterator Sec2 = Section.getRelocatedSection(); section_iterator Sec2 = Section.getRelocatedSection();
@ -621,7 +620,7 @@ static void PrintSectionHeaders(const ObjectFile *Obj) {
} }
static void PrintSectionContents(const ObjectFile *Obj) { static void PrintSectionContents(const ObjectFile *Obj) {
error_code EC; std::error_code EC;
for (const SectionRef &Section : Obj->sections()) { for (const SectionRef &Section : Obj->sections()) {
StringRef Name; StringRef Name;
StringRef Contents; StringRef Contents;
@ -852,7 +851,7 @@ static void DumpArchive(const Archive *a) {
for (Archive::child_iterator i = a->child_begin(), e = a->child_end(); i != e; for (Archive::child_iterator i = a->child_begin(), e = a->child_end(); i != e;
++i) { ++i) {
std::unique_ptr<Binary> child; std::unique_ptr<Binary> child;
if (error_code EC = i->getAsBinary(child)) { if (std::error_code EC = i->getAsBinary(child)) {
// Ignore non-object files. // Ignore non-object files.
if (EC != object_error::invalid_file_type) if (EC != object_error::invalid_file_type)
errs() << ToolName << ": '" << a->getFileName() << "': " << EC.message() errs() << ToolName << ": '" << a->getFileName() << "': " << EC.message()
@ -882,7 +881,7 @@ static void DumpInput(StringRef file) {
// Attempt to open the binary. // Attempt to open the binary.
ErrorOr<Binary *> BinaryOrErr = createBinary(file); ErrorOr<Binary *> BinaryOrErr = createBinary(file);
if (error_code EC = BinaryOrErr.getError()) { if (std::error_code EC = BinaryOrErr.getError()) {
errs() << ToolName << ": '" << file << "': " << EC.message() << ".\n"; errs() << ToolName << ": '" << file << "': " << EC.message() << ".\n";
return; return;
} }

View File

@ -24,7 +24,6 @@
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
using namespace llvm; using namespace llvm;
using std::error_code;
static void exitWithError(const Twine &Message, StringRef Whence = "") { static void exitWithError(const Twine &Message, StringRef Whence = "") {
errs() << "error: "; errs() << "error: ";
@ -57,11 +56,12 @@ int merge_main(int argc, const char *argv[]) {
InstrProfWriter Writer; InstrProfWriter Writer;
for (const auto &Filename : Inputs) { for (const auto &Filename : Inputs) {
std::unique_ptr<InstrProfReader> Reader; std::unique_ptr<InstrProfReader> Reader;
if (error_code ec = InstrProfReader::create(Filename, Reader)) if (std::error_code ec = InstrProfReader::create(Filename, Reader))
exitWithError(ec.message(), Filename); exitWithError(ec.message(), Filename);
for (const auto &I : *Reader) for (const auto &I : *Reader)
if (error_code EC = Writer.addFunctionCounts(I.Name, I.Hash, I.Counts)) if (std::error_code EC =
Writer.addFunctionCounts(I.Name, I.Hash, I.Counts))
errs() << Filename << ": " << I.Name << ": " << EC.message() << "\n"; errs() << Filename << ": " << I.Name << ": " << EC.message() << "\n";
if (Reader->hasError()) if (Reader->hasError())
exitWithError(Reader->getError().message(), Filename); exitWithError(Reader->getError().message(), Filename);
@ -91,7 +91,7 @@ int show_main(int argc, const char *argv[]) {
cl::ParseCommandLineOptions(argc, argv, "LLVM profile data summary\n"); cl::ParseCommandLineOptions(argc, argv, "LLVM profile data summary\n");
std::unique_ptr<InstrProfReader> Reader; std::unique_ptr<InstrProfReader> Reader;
if (error_code EC = InstrProfReader::create(Filename, Reader)) if (std::error_code EC = InstrProfReader::create(Filename, Reader))
exitWithError(EC.message(), Filename); exitWithError(EC.message(), Filename);
if (OutputFilename.empty()) if (OutputFilename.empty())

View File

@ -38,7 +38,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::object; using namespace llvm::object;
using namespace llvm::Win64EH; using namespace llvm::Win64EH;
using std::error_code;
namespace { namespace {
@ -70,10 +69,10 @@ private:
void cacheRelocations(); void cacheRelocations();
error_code resolveSymbol(const coff_section *Section, uint64_t Offset, std::error_code resolveSymbol(const coff_section *Section, uint64_t Offset,
SymbolRef &Sym); SymbolRef &Sym);
error_code resolveSymbolName(const coff_section *Section, uint64_t Offset, std::error_code resolveSymbolName(const coff_section *Section,
StringRef &Name); uint64_t Offset, StringRef &Name);
typedef DenseMap<const coff_section*, std::vector<RelocationRef> > RelocMapTy; typedef DenseMap<const coff_section*, std::vector<RelocationRef> > RelocMapTy;
@ -86,8 +85,9 @@ private:
namespace llvm { namespace llvm {
error_code createCOFFDumper(const object::ObjectFile *Obj, StreamWriter &Writer, std::error_code createCOFFDumper(const object::ObjectFile *Obj,
std::unique_ptr<ObjDumper> &Result) { StreamWriter &Writer,
std::unique_ptr<ObjDumper> &Result) {
const COFFObjectFile *COFFObj = dyn_cast<COFFObjectFile>(Obj); const COFFObjectFile *COFFObj = dyn_cast<COFFObjectFile>(Obj);
if (!COFFObj) if (!COFFObj)
return readobj_error::unsupported_obj_file_format; return readobj_error::unsupported_obj_file_format;
@ -100,12 +100,12 @@ error_code createCOFFDumper(const object::ObjectFile *Obj, StreamWriter &Writer,
// Given a a section and an offset into this section the function returns the // Given a a section and an offset into this section the function returns the
// symbol used for the relocation at the offset. // symbol used for the relocation at the offset.
error_code COFFDumper::resolveSymbol(const coff_section *Section, std::error_code COFFDumper::resolveSymbol(const coff_section *Section,
uint64_t Offset, SymbolRef &Sym) { uint64_t Offset, SymbolRef &Sym) {
const auto &Relocations = RelocMap[Section]; const auto &Relocations = RelocMap[Section];
for (const auto &Relocation : Relocations) { for (const auto &Relocation : Relocations) {
uint64_t RelocationOffset; uint64_t RelocationOffset;
if (error_code EC = Relocation.getOffset(RelocationOffset)) if (std::error_code EC = Relocation.getOffset(RelocationOffset))
return EC; return EC;
if (RelocationOffset == Offset) { if (RelocationOffset == Offset) {
@ -118,12 +118,13 @@ error_code COFFDumper::resolveSymbol(const coff_section *Section,
// Given a section and an offset into this section the function returns the name // Given a section and an offset into this section the function returns the name
// of the symbol used for the relocation at the offset. // of the symbol used for the relocation at the offset.
error_code COFFDumper::resolveSymbolName(const coff_section *Section, std::error_code COFFDumper::resolveSymbolName(const coff_section *Section,
uint64_t Offset, StringRef &Name) { uint64_t Offset,
StringRef &Name) {
SymbolRef Symbol; SymbolRef Symbol;
if (error_code EC = resolveSymbol(Section, Offset, Symbol)) if (std::error_code EC = resolveSymbol(Section, Offset, Symbol))
return EC; return EC;
if (error_code EC = Symbol.getName(Name)) if (std::error_code EC = Symbol.getName(Name))
return EC; return EC;
return object_error::success; return object_error::success;
} }
@ -308,9 +309,10 @@ WeakExternalCharacteristics[] = {
{ "Alias" , COFF::IMAGE_WEAK_EXTERN_SEARCH_ALIAS } { "Alias" , COFF::IMAGE_WEAK_EXTERN_SEARCH_ALIAS }
}; };
template<typename T> template <typename T>
static error_code getSymbolAuxData(const COFFObjectFile *Obj, static std::error_code getSymbolAuxData(const COFFObjectFile *Obj,
const coff_symbol *Symbol, const T* &Aux) { const coff_symbol *Symbol,
const T *&Aux) {
ArrayRef<uint8_t> AuxData = Obj->getSymbolAuxData(Symbol); ArrayRef<uint8_t> AuxData = Obj->getSymbolAuxData(Symbol);
Aux = reinterpret_cast<const T*>(AuxData.data()); Aux = reinterpret_cast<const T*>(AuxData.data());
return readobj_error::success; return readobj_error::success;
@ -720,7 +722,7 @@ void COFFDumper::printSymbol(const SymbolRef &Sym) {
const coff_symbol *Symbol = Obj->getCOFFSymbol(Sym); const coff_symbol *Symbol = Obj->getCOFFSymbol(Sym);
const coff_section *Section; const coff_section *Section;
if (error_code EC = Obj->getSection(Symbol->SectionNumber, Section)) { if (std::error_code EC = Obj->getSection(Symbol->SectionNumber, Section)) {
W.startLine() << "Invalid section number: " << EC.message() << "\n"; W.startLine() << "Invalid section number: " << EC.message() << "\n";
W.flush(); W.flush();
return; return;
@ -764,7 +766,7 @@ void COFFDumper::printSymbol(const SymbolRef &Sym) {
const coff_symbol *Linked; const coff_symbol *Linked;
StringRef LinkedName; StringRef LinkedName;
error_code EC; std::error_code EC;
if ((EC = Obj->getSymbol(Aux->TagIndex, Linked)) || if ((EC = Obj->getSymbol(Aux->TagIndex, Linked)) ||
(EC = Obj->getSymbolName(Linked, LinkedName))) { (EC = Obj->getSymbolName(Linked, LinkedName))) {
LinkedName = ""; LinkedName = "";
@ -806,7 +808,7 @@ void COFFDumper::printSymbol(const SymbolRef &Sym) {
&& Aux->Selection == COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE) { && Aux->Selection == COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE) {
const coff_section *Assoc; const coff_section *Assoc;
StringRef AssocName; StringRef AssocName;
error_code EC; std::error_code EC;
if ((EC = Obj->getSection(Aux->Number, Assoc)) || if ((EC = Obj->getSection(Aux->Number, Assoc)) ||
(EC = Obj->getSectionName(Assoc, AssocName))) { (EC = Obj->getSectionName(Assoc, AssocName))) {
AssocName = ""; AssocName = "";
@ -822,7 +824,7 @@ void COFFDumper::printSymbol(const SymbolRef &Sym) {
const coff_symbol *ReferredSym; const coff_symbol *ReferredSym;
StringRef ReferredName; StringRef ReferredName;
error_code EC; std::error_code EC;
if ((EC = Obj->getSymbol(Aux->SymbolTableIndex, ReferredSym)) || if ((EC = Obj->getSymbol(Aux->SymbolTableIndex, ReferredSym)) ||
(EC = Obj->getSymbolName(ReferredSym, ReferredName))) { (EC = Obj->getSymbolName(ReferredSym, ReferredName))) {
ReferredName = ""; ReferredName = "";
@ -850,12 +852,12 @@ void COFFDumper::printUnwindInfo() {
switch (Header->Machine) { switch (Header->Machine) {
case COFF::IMAGE_FILE_MACHINE_AMD64: { case COFF::IMAGE_FILE_MACHINE_AMD64: {
Win64EH::Dumper Dumper(W); Win64EH::Dumper Dumper(W);
Win64EH::Dumper::SymbolResolver Resolver = Win64EH::Dumper::SymbolResolver
[](const object::coff_section *Section, uint64_t Offset, Resolver = [](const object::coff_section *Section, uint64_t Offset,
SymbolRef &Symbol, void *user_data) -> error_code { SymbolRef &Symbol, void *user_data) -> std::error_code {
COFFDumper *Dumper = reinterpret_cast<COFFDumper*>(user_data); COFFDumper *Dumper = reinterpret_cast<COFFDumper *>(user_data);
return Dumper->resolveSymbol(Section, Offset, Symbol); return Dumper->resolveSymbol(Section, Offset, Symbol);
}; };
Win64EH::Dumper::Context Ctx(*Obj, Resolver, this); Win64EH::Dumper::Context Ctx(*Obj, Resolver, this);
Dumper.printData(Ctx); Dumper.printData(Ctx);
break; break;

View File

@ -30,7 +30,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::object; using namespace llvm::object;
using namespace ELF; using namespace ELF;
using std::error_code;
#define LLVM_READOBJ_ENUM_CASE(ns, enum) \ #define LLVM_READOBJ_ENUM_CASE(ns, enum) \
case ns::enum: return #enum; case ns::enum: return #enum;
@ -82,15 +81,16 @@ template <class T> T errorOrDefault(ErrorOr<T> Val, T Default = T()) {
namespace llvm { namespace llvm {
template <class ELFT> template <class ELFT>
static error_code createELFDumper(const ELFFile<ELFT> *Obj, static std::error_code createELFDumper(const ELFFile<ELFT> *Obj,
StreamWriter &Writer, StreamWriter &Writer,
std::unique_ptr<ObjDumper> &Result) { std::unique_ptr<ObjDumper> &Result) {
Result.reset(new ELFDumper<ELFT>(Obj, Writer)); Result.reset(new ELFDumper<ELFT>(Obj, Writer));
return readobj_error::success; return readobj_error::success;
} }
error_code createELFDumper(const object::ObjectFile *Obj, StreamWriter &Writer, std::error_code createELFDumper(const object::ObjectFile *Obj,
std::unique_ptr<ObjDumper> &Result) { StreamWriter &Writer,
std::unique_ptr<ObjDumper> &Result) {
// Little-endian 32-bit // Little-endian 32-bit
if (const ELF32LEObjectFile *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj)) if (const ELF32LEObjectFile *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj))
return createELFDumper(ELFObj->getELFFile(), Writer, Result); return createELFDumper(ELFObj->getELFFile(), Writer, Result);

View File

@ -21,7 +21,6 @@
using namespace llvm; using namespace llvm;
using namespace object; using namespace object;
using std::error_code;
namespace { namespace {
@ -55,9 +54,9 @@ private:
namespace llvm { namespace llvm {
error_code createMachODumper(const object::ObjectFile *Obj, std::error_code createMachODumper(const object::ObjectFile *Obj,
StreamWriter &Writer, StreamWriter &Writer,
std::unique_ptr<ObjDumper> &Result) { std::unique_ptr<ObjDumper> &Result) {
const MachOObjectFile *MachOObj = dyn_cast<MachOObjectFile>(Obj); const MachOObjectFile *MachOObj = dyn_cast<MachOObjectFile>(Obj);
if (!MachOObj) if (!MachOObj)
return readobj_error::unsupported_obj_file_format; return readobj_error::unsupported_obj_file_format;
@ -278,7 +277,7 @@ void MachODumper::printSections(const MachOObjectFile *Obj) {
void MachODumper::printRelocations() { void MachODumper::printRelocations() {
ListScope D(W, "Relocations"); ListScope D(W, "Relocations");
error_code EC; std::error_code EC;
for (const SectionRef &Section : Obj->sections()) { for (const SectionRef &Section : Obj->sections()) {
StringRef Name; StringRef Name;
if (error(Section.getName(Name))) if (error(Section.getName(Name)))

View File

@ -16,7 +16,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::object; using namespace llvm::object;
using namespace llvm::Win64EH; using namespace llvm::Win64EH;
using std::error_code;
static const EnumEntry<unsigned> UnwindFlags[] = { static const EnumEntry<unsigned> UnwindFlags[] = {
{ "ExceptionHandler", UNW_ExceptionHandler }, { "ExceptionHandler", UNW_ExceptionHandler },
@ -135,20 +134,21 @@ static std::string formatSymbol(const Dumper::Context &Ctx,
return OS.str(); return OS.str();
} }
static error_code resolveRelocation(const Dumper::Context &Ctx, static std::error_code resolveRelocation(const Dumper::Context &Ctx,
const coff_section *Section, const coff_section *Section,
uint64_t Offset, uint64_t Offset,
const coff_section *&ResolvedSection, const coff_section *&ResolvedSection,
uint64_t &ResolvedAddress) { uint64_t &ResolvedAddress) {
SymbolRef Symbol; SymbolRef Symbol;
if (error_code EC = Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData)) if (std::error_code EC =
Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData))
return EC; return EC;
if (error_code EC = Symbol.getAddress(ResolvedAddress)) if (std::error_code EC = Symbol.getAddress(ResolvedAddress))
return EC; return EC;
section_iterator SI = Ctx.COFF.section_begin(); section_iterator SI = Ctx.COFF.section_begin();
if (error_code EC = Symbol.getSection(SI)) if (std::error_code EC = Symbol.getSection(SI))
return EC; return EC;
ResolvedSection = Ctx.COFF.getCOFFSection(*SI); ResolvedSection = Ctx.COFF.getCOFFSection(*SI);

View File

@ -41,7 +41,6 @@
using namespace llvm; using namespace llvm;
using namespace llvm::object; using namespace llvm::object;
using std::error_code;
namespace opts { namespace opts {
cl::list<std::string> InputFilenames(cl::Positional, cl::list<std::string> InputFilenames(cl::Positional,
@ -142,7 +141,7 @@ static int ReturnValue = EXIT_SUCCESS;
namespace llvm { namespace llvm {
bool error(error_code EC) { bool error(std::error_code EC) {
if (!EC) if (!EC)
return false; return false;
@ -161,8 +160,7 @@ bool relocAddressLess(RelocationRef a, RelocationRef b) {
} // namespace llvm } // namespace llvm
static void reportError(StringRef Input, std::error_code EC) {
static void reportError(StringRef Input, error_code EC) {
if (Input == "-") if (Input == "-")
Input = "<stdin>"; Input = "<stdin>";
@ -180,8 +178,8 @@ static void reportError(StringRef Input, StringRef Message) {
} }
/// @brief Creates an format-specific object file dumper. /// @brief Creates an format-specific object file dumper.
static error_code createDumper(const ObjectFile *Obj, StreamWriter &Writer, static std::error_code createDumper(const ObjectFile *Obj, StreamWriter &Writer,
std::unique_ptr<ObjDumper> &Result) { std::unique_ptr<ObjDumper> &Result) {
if (!Obj) if (!Obj)
return readobj_error::unsupported_file_format; return readobj_error::unsupported_file_format;
@ -200,7 +198,7 @@ static error_code createDumper(const ObjectFile *Obj, StreamWriter &Writer,
static void dumpObject(const ObjectFile *Obj) { static void dumpObject(const ObjectFile *Obj) {
StreamWriter Writer(outs()); StreamWriter Writer(outs());
std::unique_ptr<ObjDumper> Dumper; std::unique_ptr<ObjDumper> Dumper;
if (error_code EC = createDumper(Obj, Writer, Dumper)) { if (std::error_code EC = createDumper(Obj, Writer, Dumper)) {
reportError(Obj->getFileName(), EC); reportError(Obj->getFileName(), EC);
return; return;
} }
@ -245,7 +243,7 @@ static void dumpArchive(const Archive *Arc) {
ArcE = Arc->child_end(); ArcE = Arc->child_end();
ArcI != ArcE; ++ArcI) { ArcI != ArcE; ++ArcI) {
std::unique_ptr<Binary> child; std::unique_ptr<Binary> child;
if (error_code EC = ArcI->getAsBinary(child)) { if (std::error_code EC = ArcI->getAsBinary(child)) {
// Ignore non-object files. // Ignore non-object files.
if (EC != object_error::invalid_file_type) if (EC != object_error::invalid_file_type)
reportError(Arc->getFileName(), EC.message()); reportError(Arc->getFileName(), EC.message());
@ -270,7 +268,7 @@ static void dumpInput(StringRef File) {
// Attempt to open the binary. // Attempt to open the binary.
ErrorOr<Binary *> BinaryOrErr = createBinary(File); ErrorOr<Binary *> BinaryOrErr = createBinary(File);
if (error_code EC = BinaryOrErr.getError()) { if (std::error_code EC = BinaryOrErr.getError()) {
reportError(File, EC); reportError(File, EC);
return; return;
} }

View File

@ -28,7 +28,6 @@
#include <system_error> #include <system_error>
using namespace llvm; using namespace llvm;
using namespace llvm::object; using namespace llvm::object;
using std::error_code;
static cl::list<std::string> static cl::list<std::string>
InputFileList(cl::Positional, cl::ZeroOrMore, InputFileList(cl::Positional, cl::ZeroOrMore,
@ -158,8 +157,8 @@ static int printLineInfoForInput() {
// Load the input memory buffer. // Load the input memory buffer.
std::unique_ptr<MemoryBuffer> InputBuffer; std::unique_ptr<MemoryBuffer> InputBuffer;
std::unique_ptr<ObjectImage> LoadedObject; std::unique_ptr<ObjectImage> LoadedObject;
if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFileList[i], if (std::error_code ec =
InputBuffer)) MemoryBuffer::getFileOrSTDIN(InputFileList[i], InputBuffer))
return Error("unable to read input: '" + ec.message() + "'"); return Error("unable to read input: '" + ec.message() + "'");
// Load the object file // Load the object file
@ -219,8 +218,8 @@ static int executeInput() {
// Load the input memory buffer. // Load the input memory buffer.
std::unique_ptr<MemoryBuffer> InputBuffer; std::unique_ptr<MemoryBuffer> InputBuffer;
std::unique_ptr<ObjectImage> LoadedObject; std::unique_ptr<ObjectImage> LoadedObject;
if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFileList[i], if (std::error_code ec =
InputBuffer)) MemoryBuffer::getFileOrSTDIN(InputFileList[i], InputBuffer))
return Error("unable to read input: '" + ec.message() + "'"); return Error("unable to read input: '" + ec.message() + "'");
// Load the object file // Load the object file

View File

@ -30,7 +30,6 @@
#include <system_error> #include <system_error>
using namespace llvm; using namespace llvm;
using namespace object; using namespace object;
using std::error_code;
enum OutputFormatTy {berkeley, sysv}; enum OutputFormatTy {berkeley, sysv};
static cl::opt<OutputFormatTy> static cl::opt<OutputFormatTy>
@ -69,7 +68,7 @@ static cl::list<std::string>
static std::string ToolName; static std::string ToolName;
/// @brief If ec is not success, print the error and return true. /// @brief If ec is not success, print the error and return true.
static bool error(error_code ec) { static bool error(std::error_code ec) {
if (!ec) return false; if (!ec) return false;
outs() << ToolName << ": error reading file: " << ec.message() << ".\n"; outs() << ToolName << ": error reading file: " << ec.message() << ".\n";
@ -236,7 +235,7 @@ static void PrintFileSectionSizes(StringRef file) {
// Attempt to open the binary. // Attempt to open the binary.
ErrorOr<Binary *> BinaryOrErr = createBinary(file); ErrorOr<Binary *> BinaryOrErr = createBinary(file);
if (error_code EC = BinaryOrErr.getError()) { if (std::error_code EC = BinaryOrErr.getError()) {
errs() << ToolName << ": " << file << ": " << EC.message() << ".\n"; errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
return; return;
} }
@ -247,7 +246,7 @@ static void PrintFileSectionSizes(StringRef file) {
for (object::Archive::child_iterator i = a->child_begin(), for (object::Archive::child_iterator i = a->child_begin(),
e = a->child_end(); i != e; ++i) { e = a->child_end(); i != e; ++i) {
std::unique_ptr<Binary> child; std::unique_ptr<Binary> child;
if (error_code ec = i->getAsBinary(child)) { if (std::error_code ec = i->getAsBinary(child)) {
errs() << ToolName << ": " << file << ": " << ec.message() << ".\n"; errs() << ToolName << ": " << file << ": " << ec.message() << ".\n";
continue; continue;
} }

View File

@ -26,10 +26,9 @@
#include <stdlib.h> #include <stdlib.h>
namespace llvm { namespace llvm {
using std::error_code;
namespace symbolize { namespace symbolize {
static bool error(error_code ec) { static bool error(std::error_code ec) {
if (!ec) if (!ec)
return false; return false;
errs() << "LLVMSymbolizer: error reading file: " << ec.message() << ".\n"; errs() << "LLVMSymbolizer: error reading file: " << ec.message() << ".\n";
@ -311,7 +310,7 @@ LLVMSymbolizer::getOrCreateBinary(const std::string &Path) {
const std::string &ResourcePath = const std::string &ResourcePath =
getDarwinDWARFResourceForPath(Path); getDarwinDWARFResourceForPath(Path);
BinaryOrErr = createBinary(ResourcePath); BinaryOrErr = createBinary(ResourcePath);
error_code EC = BinaryOrErr.getError(); std::error_code EC = BinaryOrErr.getError();
if (EC != std::errc::no_such_file_or_directory && !error(EC)) { if (EC != std::errc::no_such_file_or_directory && !error(EC)) {
DbgBin = BinaryOrErr.get(); DbgBin = BinaryOrErr.get();
ParsedBinariesAndObjects.push_back(std::unique_ptr<Binary>(DbgBin)); ParsedBinariesAndObjects.push_back(std::unique_ptr<Binary>(DbgBin));

View File

@ -29,7 +29,6 @@
using namespace llvm; using namespace llvm;
using namespace symbolize; using namespace symbolize;
using std::error_code;
static cl::opt<bool> static cl::opt<bool>
ClUseSymbolTable("use-symbol-table", cl::init(true), ClUseSymbolTable("use-symbol-table", cl::init(true),

View File

@ -23,7 +23,6 @@
#include <system_error> #include <system_error>
using namespace llvm; using namespace llvm;
using namespace llvm::object; using namespace llvm::object;
using std::error_code;
static cl::opt<std::string> static cl::opt<std::string>
InputFile(cl::Positional, cl::desc("<input file>"), cl::init("-")); InputFile(cl::Positional, cl::desc("<input file>"), cl::init("-"));
@ -392,7 +391,7 @@ int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv, "llvm Mach-O dumping tool\n"); cl::ParseCommandLineOptions(argc, argv, "llvm Mach-O dumping tool\n");
ErrorOr<Binary *> BinaryOrErr = createBinary(InputFile); ErrorOr<Binary *> BinaryOrErr = createBinary(InputFile);
if (error_code EC = BinaryOrErr.getError()) if (std::error_code EC = BinaryOrErr.getError())
return Error("unable to read input: '" + EC.message() + "'"); return Error("unable to read input: '" + EC.message() + "'");
std::unique_ptr<Binary> Binary(BinaryOrErr.get()); std::unique_ptr<Binary> Binary(BinaryOrErr.get());

View File

@ -14,7 +14,6 @@
#include "llvm/Support/YAMLTraits.h" #include "llvm/Support/YAMLTraits.h"
using namespace llvm; using namespace llvm;
using std::error_code;
namespace { namespace {
@ -32,7 +31,7 @@ public:
} }
static void check(error_code ec) { static void check(std::error_code ec) {
if (ec) if (ec)
report_fatal_error(ec.message()); report_fatal_error(ec.message());
} }
@ -211,7 +210,7 @@ COFFYAML::Object &COFFDumper::getYAMLObj() {
return YAMLObj; return YAMLObj;
} }
error_code coff2yaml(raw_ostream &Out, const object::COFFObjectFile &Obj) { std::error_code coff2yaml(raw_ostream &Out, const object::COFFObjectFile &Obj) {
COFFDumper Dumper(Obj); COFFDumper Dumper(Obj);
yaml::Output Yout(Out); yaml::Output Yout(Out);

View File

@ -16,7 +16,6 @@
#include "llvm/Support/YAMLTraits.h" #include "llvm/Support/YAMLTraits.h"
using namespace llvm; using namespace llvm;
using std::error_code;
namespace { namespace {
@ -27,13 +26,13 @@ class ELFDumper {
const object::ELFFile<ELFT> &Obj; const object::ELFFile<ELFT> &Obj;
error_code dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S); std::error_code dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S);
error_code dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S); std::error_code dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S);
error_code dumpCommonRelocationSection(const Elf_Shdr *Shdr, std::error_code dumpCommonRelocationSection(const Elf_Shdr *Shdr,
ELFYAML::RelocationSection &S); ELFYAML::RelocationSection &S);
template <class RelT> template <class RelT>
error_code dumpRelocation(const Elf_Shdr *Shdr, const RelT *Rel, std::error_code dumpRelocation(const Elf_Shdr *Shdr, const RelT *Rel,
ELFYAML::Relocation &R); ELFYAML::Relocation &R);
ErrorOr<ELFYAML::RelocationSection *> dumpRelSection(const Elf_Shdr *Shdr); ErrorOr<ELFYAML::RelocationSection *> dumpRelSection(const Elf_Shdr *Shdr);
ErrorOr<ELFYAML::RelocationSection *> dumpRelaSection(const Elf_Shdr *Shdr); ErrorOr<ELFYAML::RelocationSection *> dumpRelaSection(const Elf_Shdr *Shdr);
@ -75,14 +74,14 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
break; break;
case ELF::SHT_RELA: { case ELF::SHT_RELA: {
ErrorOr<ELFYAML::RelocationSection *> S = dumpRelaSection(&Sec); ErrorOr<ELFYAML::RelocationSection *> S = dumpRelaSection(&Sec);
if (error_code EC = S.getError()) if (std::error_code EC = S.getError())
return EC; return EC;
Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get())); Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get()));
break; break;
} }
case ELF::SHT_REL: { case ELF::SHT_REL: {
ErrorOr<ELFYAML::RelocationSection *> S = dumpRelSection(&Sec); ErrorOr<ELFYAML::RelocationSection *> S = dumpRelSection(&Sec);
if (error_code EC = S.getError()) if (std::error_code EC = S.getError())
return EC; return EC;
Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get())); Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get()));
break; break;
@ -90,7 +89,7 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
// FIXME: Support SHT_GROUP section format. // FIXME: Support SHT_GROUP section format.
default: { default: {
ErrorOr<ELFYAML::RawContentSection *> S = dumpContentSection(&Sec); ErrorOr<ELFYAML::RawContentSection *> S = dumpContentSection(&Sec);
if (error_code EC = S.getError()) if (std::error_code EC = S.getError())
return EC; return EC;
Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get())); Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get()));
} }
@ -106,7 +105,7 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
} }
ELFYAML::Symbol S; ELFYAML::Symbol S;
if (error_code EC = ELFDumper<ELFT>::dumpSymbol(SI, S)) if (std::error_code EC = ELFDumper<ELFT>::dumpSymbol(SI, S))
return EC; return EC;
switch (SI->getBinding()) switch (SI->getBinding())
@ -129,14 +128,15 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
} }
template <class ELFT> template <class ELFT>
error_code ELFDumper<ELFT>::dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S) { std::error_code ELFDumper<ELFT>::dumpSymbol(Elf_Sym_Iter Sym,
ELFYAML::Symbol &S) {
S.Type = Sym->getType(); S.Type = Sym->getType();
S.Value = Sym->st_value; S.Value = Sym->st_value;
S.Size = Sym->st_size; S.Size = Sym->st_size;
S.Visibility = Sym->st_other & 0x3; S.Visibility = Sym->st_other & 0x3;
ErrorOr<StringRef> NameOrErr = Obj.getSymbolName(Sym); ErrorOr<StringRef> NameOrErr = Obj.getSymbolName(Sym);
if (error_code EC = NameOrErr.getError()) if (std::error_code EC = NameOrErr.getError())
return EC; return EC;
S.Name = NameOrErr.get(); S.Name = NameOrErr.get();
@ -145,7 +145,7 @@ error_code ELFDumper<ELFT>::dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S) {
return obj2yaml_error::success; return obj2yaml_error::success;
NameOrErr = Obj.getSectionName(Shdr); NameOrErr = Obj.getSectionName(Shdr);
if (error_code EC = NameOrErr.getError()) if (std::error_code EC = NameOrErr.getError())
return EC; return EC;
S.Section = NameOrErr.get(); S.Section = NameOrErr.get();
@ -154,9 +154,9 @@ error_code ELFDumper<ELFT>::dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S) {
template <class ELFT> template <class ELFT>
template <class RelT> template <class RelT>
error_code ELFDumper<ELFT>::dumpRelocation(const Elf_Shdr *Shdr, std::error_code ELFDumper<ELFT>::dumpRelocation(const Elf_Shdr *Shdr,
const RelT *Rel, const RelT *Rel,
ELFYAML::Relocation &R) { ELFYAML::Relocation &R) {
R.Type = Rel->getType(Obj.isMips64EL()); R.Type = Rel->getType(Obj.isMips64EL());
R.Offset = Rel->r_offset; R.Offset = Rel->r_offset;
R.Addend = 0; R.Addend = 0;
@ -167,7 +167,7 @@ error_code ELFDumper<ELFT>::dumpRelocation(const Elf_Shdr *Shdr,
ErrorOr<StringRef> NameOrErr = ErrorOr<StringRef> NameOrErr =
Obj.getSymbolName(NamePair.first, NamePair.second); Obj.getSymbolName(NamePair.first, NamePair.second);
if (error_code EC = NameOrErr.getError()) if (std::error_code EC = NameOrErr.getError())
return EC; return EC;
R.Symbol = NameOrErr.get(); R.Symbol = NameOrErr.get();
@ -175,22 +175,22 @@ error_code ELFDumper<ELFT>::dumpRelocation(const Elf_Shdr *Shdr,
} }
template <class ELFT> template <class ELFT>
error_code ELFDumper<ELFT>::dumpCommonSection(const Elf_Shdr *Shdr, std::error_code ELFDumper<ELFT>::dumpCommonSection(const Elf_Shdr *Shdr,
ELFYAML::Section &S) { ELFYAML::Section &S) {
S.Type = Shdr->sh_type; S.Type = Shdr->sh_type;
S.Flags = Shdr->sh_flags; S.Flags = Shdr->sh_flags;
S.Address = Shdr->sh_addr; S.Address = Shdr->sh_addr;
S.AddressAlign = Shdr->sh_addralign; S.AddressAlign = Shdr->sh_addralign;
ErrorOr<StringRef> NameOrErr = Obj.getSectionName(Shdr); ErrorOr<StringRef> NameOrErr = Obj.getSectionName(Shdr);
if (error_code EC = NameOrErr.getError()) if (std::error_code EC = NameOrErr.getError())
return EC; return EC;
S.Name = NameOrErr.get(); S.Name = NameOrErr.get();
if (Shdr->sh_link != ELF::SHN_UNDEF) { if (Shdr->sh_link != ELF::SHN_UNDEF) {
if (const Elf_Shdr *LinkSection = Obj.getSection(Shdr->sh_link)) { if (const Elf_Shdr *LinkSection = Obj.getSection(Shdr->sh_link)) {
NameOrErr = Obj.getSectionName(LinkSection); NameOrErr = Obj.getSectionName(LinkSection);
if (error_code EC = NameOrErr.getError()) if (std::error_code EC = NameOrErr.getError())
return EC; return EC;
S.Link = NameOrErr.get(); S.Link = NameOrErr.get();
} }
@ -200,15 +200,15 @@ error_code ELFDumper<ELFT>::dumpCommonSection(const Elf_Shdr *Shdr,
} }
template <class ELFT> template <class ELFT>
error_code std::error_code
ELFDumper<ELFT>::dumpCommonRelocationSection(const Elf_Shdr *Shdr, ELFDumper<ELFT>::dumpCommonRelocationSection(const Elf_Shdr *Shdr,
ELFYAML::RelocationSection &S) { ELFYAML::RelocationSection &S) {
if (error_code EC = dumpCommonSection(Shdr, S)) if (std::error_code EC = dumpCommonSection(Shdr, S))
return EC; return EC;
if (const Elf_Shdr *InfoSection = Obj.getSection(Shdr->sh_info)) { if (const Elf_Shdr *InfoSection = Obj.getSection(Shdr->sh_info)) {
ErrorOr<StringRef> NameOrErr = Obj.getSectionName(InfoSection); ErrorOr<StringRef> NameOrErr = Obj.getSectionName(InfoSection);
if (error_code EC = NameOrErr.getError()) if (std::error_code EC = NameOrErr.getError())
return EC; return EC;
S.Info = NameOrErr.get(); S.Info = NameOrErr.get();
} }
@ -222,13 +222,13 @@ ELFDumper<ELFT>::dumpRelSection(const Elf_Shdr *Shdr) {
assert(Shdr->sh_type == ELF::SHT_REL && "Section type is not SHT_REL"); assert(Shdr->sh_type == ELF::SHT_REL && "Section type is not SHT_REL");
auto S = make_unique<ELFYAML::RelocationSection>(); auto S = make_unique<ELFYAML::RelocationSection>();
if (error_code EC = dumpCommonRelocationSection(Shdr, *S)) if (std::error_code EC = dumpCommonRelocationSection(Shdr, *S))
return EC; return EC;
for (auto RI = Obj.begin_rel(Shdr), RE = Obj.end_rel(Shdr); RI != RE; for (auto RI = Obj.begin_rel(Shdr), RE = Obj.end_rel(Shdr); RI != RE;
++RI) { ++RI) {
ELFYAML::Relocation R; ELFYAML::Relocation R;
if (error_code EC = dumpRelocation(Shdr, &*RI, R)) if (std::error_code EC = dumpRelocation(Shdr, &*RI, R))
return EC; return EC;
S->Relocations.push_back(R); S->Relocations.push_back(R);
} }
@ -242,13 +242,13 @@ ELFDumper<ELFT>::dumpRelaSection(const Elf_Shdr *Shdr) {
assert(Shdr->sh_type == ELF::SHT_RELA && "Section type is not SHT_RELA"); assert(Shdr->sh_type == ELF::SHT_RELA && "Section type is not SHT_RELA");
auto S = make_unique<ELFYAML::RelocationSection>(); auto S = make_unique<ELFYAML::RelocationSection>();
if (error_code EC = dumpCommonRelocationSection(Shdr, *S)) if (std::error_code EC = dumpCommonRelocationSection(Shdr, *S))
return EC; return EC;
for (auto RI = Obj.begin_rela(Shdr), RE = Obj.end_rela(Shdr); RI != RE; for (auto RI = Obj.begin_rela(Shdr), RE = Obj.end_rela(Shdr); RI != RE;
++RI) { ++RI) {
ELFYAML::Relocation R; ELFYAML::Relocation R;
if (error_code EC = dumpRelocation(Shdr, &*RI, R)) if (std::error_code EC = dumpRelocation(Shdr, &*RI, R))
return EC; return EC;
R.Addend = RI->r_addend; R.Addend = RI->r_addend;
S->Relocations.push_back(R); S->Relocations.push_back(R);
@ -262,11 +262,11 @@ ErrorOr<ELFYAML::RawContentSection *>
ELFDumper<ELFT>::dumpContentSection(const Elf_Shdr *Shdr) { ELFDumper<ELFT>::dumpContentSection(const Elf_Shdr *Shdr) {
auto S = make_unique<ELFYAML::RawContentSection>(); auto S = make_unique<ELFYAML::RawContentSection>();
if (error_code EC = dumpCommonSection(Shdr, *S)) if (std::error_code EC = dumpCommonSection(Shdr, *S))
return EC; return EC;
ErrorOr<ArrayRef<uint8_t>> ContentOrErr = Obj.getSectionContents(Shdr); ErrorOr<ArrayRef<uint8_t>> ContentOrErr = Obj.getSectionContents(Shdr);
if (error_code EC = ContentOrErr.getError()) if (std::error_code EC = ContentOrErr.getError())
return EC; return EC;
S->Content = object::yaml::BinaryRef(ContentOrErr.get()); S->Content = object::yaml::BinaryRef(ContentOrErr.get());
S->Size = S->Content.binary_size(); S->Size = S->Content.binary_size();
@ -275,10 +275,11 @@ ELFDumper<ELFT>::dumpContentSection(const Elf_Shdr *Shdr) {
} }
template <class ELFT> template <class ELFT>
static error_code elf2yaml(raw_ostream &Out, const object::ELFFile<ELFT> &Obj) { static std::error_code elf2yaml(raw_ostream &Out,
const object::ELFFile<ELFT> &Obj) {
ELFDumper<ELFT> Dumper(Obj); ELFDumper<ELFT> Dumper(Obj);
ErrorOr<ELFYAML::Object *> YAMLOrErr = Dumper.dump(); ErrorOr<ELFYAML::Object *> YAMLOrErr = Dumper.dump();
if (error_code EC = YAMLOrErr.getError()) if (std::error_code EC = YAMLOrErr.getError())
return EC; return EC;
std::unique_ptr<ELFYAML::Object> YAML(YAMLOrErr.get()); std::unique_ptr<ELFYAML::Object> YAML(YAMLOrErr.get());
@ -288,7 +289,7 @@ static error_code elf2yaml(raw_ostream &Out, const object::ELFFile<ELFT> &Obj) {
return object::object_error::success; return object::object_error::success;
} }
error_code elf2yaml(raw_ostream &Out, const object::ObjectFile &Obj) { std::error_code elf2yaml(raw_ostream &Out, const object::ObjectFile &Obj) {
if (const auto *ELFObj = dyn_cast<object::ELF32LEObjectFile>(&Obj)) if (const auto *ELFObj = dyn_cast<object::ELF32LEObjectFile>(&Obj))
return elf2yaml(Out, *ELFObj->getELFFile()); return elf2yaml(Out, *ELFObj->getELFFile());

View File

@ -18,9 +18,8 @@
using namespace llvm; using namespace llvm;
using namespace llvm::object; using namespace llvm::object;
using std::error_code;
static error_code dumpObject(const ObjectFile &Obj) { static std::error_code dumpObject(const ObjectFile &Obj) {
if (Obj.isCOFF()) if (Obj.isCOFF())
return coff2yaml(outs(), cast<COFFObjectFile>(Obj)); return coff2yaml(outs(), cast<COFFObjectFile>(Obj));
if (Obj.isELF()) if (Obj.isELF())
@ -29,12 +28,12 @@ static error_code dumpObject(const ObjectFile &Obj) {
return obj2yaml_error::unsupported_obj_file_format; return obj2yaml_error::unsupported_obj_file_format;
} }
static error_code dumpInput(StringRef File) { static std::error_code dumpInput(StringRef File) {
if (File != "-" && !sys::fs::exists(File)) if (File != "-" && !sys::fs::exists(File))
return obj2yaml_error::file_not_found; return obj2yaml_error::file_not_found;
ErrorOr<Binary *> BinaryOrErr = createBinary(File); ErrorOr<Binary *> BinaryOrErr = createBinary(File);
if (error_code EC = BinaryOrErr.getError()) if (std::error_code EC = BinaryOrErr.getError())
return EC; return EC;
std::unique_ptr<Binary> Binary(BinaryOrErr.get()); std::unique_ptr<Binary> Binary(BinaryOrErr.get());
@ -54,7 +53,7 @@ int main(int argc, char *argv[]) {
PrettyStackTraceProgram X(argc, argv); PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
if (error_code EC = dumpInput(InputFilename)) { if (std::error_code EC = dumpInput(InputFilename)) {
errs() << "Error: '" << EC.message() << "'\n"; errs() << "Error: '" << EC.message() << "'\n";
return 1; return 1;
} }