[llvm] 3d90a61 - [llvm-readobj] - Remove Error.cpp,.h and drop dependencies in the code.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 1 06:46:37 PDT 2020
Author: Georgii Rymar
Date: 2020-09-01T16:46:17+03:00
New Revision: 3d90a61cf2edc22f1f006de351a1812592a7648b
URL: https://github.com/llvm/llvm-project/commit/3d90a61cf2edc22f1f006de351a1812592a7648b
DIFF: https://github.com/llvm/llvm-project/commit/3d90a61cf2edc22f1f006de351a1812592a7648b.diff
LOG: [llvm-readobj] - Remove Error.cpp,.h and drop dependencies in the code.
We have Error.cpp/.h which contains some code for working with error codes.
In fact we use Error/Expected<> almost everywhere already and we can get rid
of these files.
Note: a few places in the code used readobj specific error codes,
e.g. `return readobj_error::unknown_symbol`. But these codes are never really used,
i.e. the code checks the fact of a success/error call only.
So I've changes them to `return inconvertibleErrorCode()` for now.
It seems that these places probably should be converted to use `Error`/`Expected<>`.
Differential revision: https://reviews.llvm.org/D86772
Added:
Modified:
llvm/test/tools/llvm-readobj/archive.test
llvm/tools/llvm-readobj/ARMEHABIPrinter.h
llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp
llvm/tools/llvm-readobj/CMakeLists.txt
llvm/tools/llvm-readobj/COFFDumper.cpp
llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h
llvm/tools/llvm-readobj/ELFDumper.cpp
llvm/tools/llvm-readobj/MachODumper.cpp
llvm/tools/llvm-readobj/ObjDumper.cpp
llvm/tools/llvm-readobj/WasmDumper.cpp
llvm/tools/llvm-readobj/Win64EHDumper.cpp
llvm/tools/llvm-readobj/WindowsResourceDumper.cpp
llvm/tools/llvm-readobj/XCOFFDumper.cpp
llvm/tools/llvm-readobj/llvm-readobj.cpp
Removed:
llvm/tools/llvm-readobj/Error.cpp
llvm/tools/llvm-readobj/Error.h
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/archive.test b/llvm/test/tools/llvm-readobj/archive.test
index e65808889131..3e6d74fb6608 100644
--- a/llvm/test/tools/llvm-readobj/archive.test
+++ b/llvm/test/tools/llvm-readobj/archive.test
@@ -96,5 +96,5 @@ symbols: []
# RUN: llvm-readelf --all %t2.a 2>&1 | FileCheck %s -DARFILE="%t2.a" --check-prefix=BROKEN
# BROKEN: File: [[ARFILE]](trivial.obj.elf-x86-64)
-# BROKEN: warning: '[[ARFILE]]': Unrecognized file type.
+# BROKEN: warning: '[[ARFILE]]': broken.a has an unsupported file type
# BROKEN: File: [[ARFILE]](trivial.obj.elf-x86-64)
diff --git a/llvm/tools/llvm-readobj/ARMEHABIPrinter.h b/llvm/tools/llvm-readobj/ARMEHABIPrinter.h
index 2c0912038c31..dfa2a3538d89 100644
--- a/llvm/tools/llvm-readobj/ARMEHABIPrinter.h
+++ b/llvm/tools/llvm-readobj/ARMEHABIPrinter.h
@@ -9,7 +9,6 @@
#ifndef LLVM_TOOLS_LLVM_READOBJ_ARMEHABIPRINTER_H
#define LLVM_TOOLS_LLVM_READOBJ_ARMEHABIPRINTER_H
-#include "Error.h"
#include "llvm-readobj.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Object/ELF.h"
@@ -367,7 +366,7 @@ ErrorOr<StringRef>
PrinterContext<ET>::FunctionAtAddress(unsigned Section,
uint64_t Address) const {
if (!Symtab)
- return readobj_error::unknown_symbol;
+ return inconvertibleErrorCode();
auto StrTableOrErr = ELF->getStringTableForSymtab(*Symtab);
if (!StrTableOrErr)
reportError(StrTableOrErr.takeError(), FileName);
@@ -380,11 +379,11 @@ PrinterContext<ET>::FunctionAtAddress(unsigned Section,
if (!NameOrErr) {
// TODO: Actually report errors helpfully.
consumeError(NameOrErr.takeError());
- return readobj_error::unknown_symbol;
+ return inconvertibleErrorCode();
}
return *NameOrErr;
}
- return readobj_error::unknown_symbol;
+ return inconvertibleErrorCode();
}
template <typename ET>
diff --git a/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp b/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp
index b7811171081a..c1db03a61c9f 100644
--- a/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp
+++ b/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp
@@ -62,7 +62,6 @@
// epilogue of the function.
#include "ARMWinEHPrinter.h"
-#include "Error.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/ARMWinEH.h"
@@ -217,7 +216,7 @@ Decoder::getSectionContaining(const COFFObjectFile &COFF, uint64_t VA) {
if (VA >= Address && (VA - Address) <= Size)
return Section;
}
- return readobj_error::unknown_symbol;
+ return inconvertibleErrorCode();
}
ErrorOr<object::SymbolRef> Decoder::getSymbol(const COFFObjectFile &COFF,
@@ -235,7 +234,7 @@ ErrorOr<object::SymbolRef> Decoder::getSymbol(const COFFObjectFile &COFF,
if (*Address == VA)
return Symbol;
}
- return readobj_error::unknown_symbol;
+ return inconvertibleErrorCode();
}
ErrorOr<SymbolRef> Decoder::getRelocatedSymbol(const COFFObjectFile &,
@@ -246,7 +245,7 @@ ErrorOr<SymbolRef> Decoder::getRelocatedSymbol(const COFFObjectFile &,
if (RelocationOffset == Offset)
return *Relocation.getSymbol();
}
- return readobj_error::unknown_symbol;
+ return inconvertibleErrorCode();
}
bool Decoder::opcode_0xxxxxxx(const uint8_t *OC, unsigned &Offset,
diff --git a/llvm/tools/llvm-readobj/CMakeLists.txt b/llvm/tools/llvm-readobj/CMakeLists.txt
index 7c636ef421f8..9e310f0e9228 100644
--- a/llvm/tools/llvm-readobj/CMakeLists.txt
+++ b/llvm/tools/llvm-readobj/CMakeLists.txt
@@ -15,7 +15,6 @@ add_llvm_tool(llvm-readobj
COFFDumper.cpp
COFFImportDumper.cpp
ELFDumper.cpp
- Error.cpp
llvm-readobj.cpp
MachODumper.cpp
ObjDumper.cpp
diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp
index b06bee7755d7..22e27b3e5a29 100644
--- a/llvm/tools/llvm-readobj/COFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/COFFDumper.cpp
@@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===//
#include "ARMWinEHPrinter.h"
-#include "Error.h"
#include "ObjDumper.h"
#include "StackMapPrinter.h"
#include "Win64EHDumper.h"
@@ -262,9 +261,9 @@ std::error_code COFFDumper::resolveSymbol(const coff_section *Section,
}
}
if (SymI == Obj->symbol_end())
- return readobj_error::unknown_symbol;
+ return inconvertibleErrorCode();
Sym = *SymI;
- return readobj_error::success;
+ return std::error_code();
}
// Given a section and an offset into this section the function returns the name
@@ -578,7 +577,7 @@ static std::error_code getSymbolAuxData(const COFFObjectFile *Obj,
ArrayRef<uint8_t> AuxData = Obj->getSymbolAuxData(Symbol);
AuxData = AuxData.slice(AuxSymbolIdx * Obj->getSymbolTableEntrySize());
Aux = reinterpret_cast<const T*>(AuxData.data());
- return readobj_error::success;
+ return std::error_code();
}
void COFFDumper::cacheRelocations() {
diff --git a/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h b/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h
index a82eca080cc9..035037f4eebc 100644
--- a/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h
+++ b/llvm/tools/llvm-readobj/DwarfCFIEHPrinter.h
@@ -9,7 +9,6 @@
#ifndef LLVM_TOOLS_LLVM_READOBJ_DWARFCFIEHPRINTER_H
#define LLVM_TOOLS_LLVM_READOBJ_DWARFCFIEHPRINTER_H
-#include "Error.h"
#include "llvm-readobj.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/BinaryFormat/Dwarf.h"
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index e28ab9e9adf0..fa821ff6a619 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -13,7 +13,6 @@
#include "ARMEHABIPrinter.h"
#include "DwarfCFIEHPrinter.h"
-#include "Error.h"
#include "ObjDumper.h"
#include "StackMapPrinter.h"
#include "llvm-readobj.h"
diff --git a/llvm/tools/llvm-readobj/Error.cpp b/llvm/tools/llvm-readobj/Error.cpp
deleted file mode 100644
index 1010f18a58c8..000000000000
--- a/llvm/tools/llvm-readobj/Error.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-//===- Error.cpp - system_error extensions for llvm-readobj -----*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This defines a new error_category for the llvm-readobj tool.
-//
-//===----------------------------------------------------------------------===//
-
-#include "Error.h"
-#include "llvm/Support/ErrorHandling.h"
-
-using namespace llvm;
-
-namespace {
-// FIXME: This class is only here to support the transition to llvm::Error. It
-// will be removed once this transition is complete. Clients should prefer to
-// deal with the Error value directly, rather than converting to error_code.
-class _readobj_error_category : public std::error_category {
-public:
- const char* name() const noexcept override;
- std::string message(int ev) const override;
-};
-} // namespace
-
-const char *_readobj_error_category::name() const noexcept {
- return "llvm.readobj";
-}
-
-std::string _readobj_error_category::message(int EV) const {
- switch (static_cast<readobj_error>(EV)) {
- case readobj_error::success: return "Success";
- case readobj_error::file_not_found:
- return "No such file.";
- case readobj_error::unsupported_file_format:
- return "The file was not recognized as a valid object file.";
- case readobj_error::unrecognized_file_format:
- return "Unrecognized file type.";
- case readobj_error::unsupported_obj_file_format:
- return "Unsupported object file format.";
- case readobj_error::unknown_symbol:
- return "Unknown symbol.";
- }
- llvm_unreachable("An enumerator of readobj_error does not have a message "
- "defined.");
-}
-
-namespace llvm {
-const std::error_category &readobj_category() {
- static _readobj_error_category o;
- return o;
-}
-} // namespace llvm
diff --git a/llvm/tools/llvm-readobj/Error.h b/llvm/tools/llvm-readobj/Error.h
deleted file mode 100644
index f390e1b96f8a..000000000000
--- a/llvm/tools/llvm-readobj/Error.h
+++ /dev/null
@@ -1,40 +0,0 @@
-//===- Error.h - system_error extensions for llvm-readobj -------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This declares a new error_category for the llvm-readobj tool.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_TOOLS_LLVM_READOBJ_ERROR_H
-#define LLVM_TOOLS_LLVM_READOBJ_ERROR_H
-
-#include <system_error>
-
-namespace llvm {
-const std::error_category &readobj_category();
-
-enum class readobj_error {
- success = 0,
- file_not_found,
- unsupported_file_format,
- unrecognized_file_format,
- unsupported_obj_file_format,
- unknown_symbol
-};
-
-inline std::error_code make_error_code(readobj_error e) {
- return std::error_code(static_cast<int>(e), readobj_category());
-}
-
-} // namespace llvm
-
-namespace std {
-template <> struct is_error_code_enum<llvm::readobj_error> : std::true_type {};
-}
-
-#endif
diff --git a/llvm/tools/llvm-readobj/MachODumper.cpp b/llvm/tools/llvm-readobj/MachODumper.cpp
index a26e1a058db9..a60fb8cef6a7 100644
--- a/llvm/tools/llvm-readobj/MachODumper.cpp
+++ b/llvm/tools/llvm-readobj/MachODumper.cpp
@@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//
-#include "Error.h"
#include "ObjDumper.h"
#include "StackMapPrinter.h"
#include "llvm-readobj.h"
diff --git a/llvm/tools/llvm-readobj/ObjDumper.cpp b/llvm/tools/llvm-readobj/ObjDumper.cpp
index 7b7c9553827f..a1c461a9e639 100644
--- a/llvm/tools/llvm-readobj/ObjDumper.cpp
+++ b/llvm/tools/llvm-readobj/ObjDumper.cpp
@@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===//
#include "ObjDumper.h"
-#include "Error.h"
#include "llvm-readobj.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Error.h"
diff --git a/llvm/tools/llvm-readobj/WasmDumper.cpp b/llvm/tools/llvm-readobj/WasmDumper.cpp
index 3b4502949967..bb07b9d5bd15 100644
--- a/llvm/tools/llvm-readobj/WasmDumper.cpp
+++ b/llvm/tools/llvm-readobj/WasmDumper.cpp
@@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//
-#include "Error.h"
#include "ObjDumper.h"
#include "llvm-readobj.h"
#include "llvm/Object/Wasm.h"
diff --git a/llvm/tools/llvm-readobj/Win64EHDumper.cpp b/llvm/tools/llvm-readobj/Win64EHDumper.cpp
index 380baae2eeb4..7e84c1bca35d 100644
--- a/llvm/tools/llvm-readobj/Win64EHDumper.cpp
+++ b/llvm/tools/llvm-readobj/Win64EHDumper.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "Win64EHDumper.h"
-#include "Error.h"
#include "llvm-readobj.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/ErrorHandling.h"
@@ -120,10 +119,10 @@ static std::error_code getSymbol(const COFFObjectFile &COFF, uint64_t VA,
return errorToErrorCode(Address.takeError());
if (*Address == VA) {
Sym = Symbol;
- return readobj_error::success;
+ return std::error_code();
}
}
- return readobj_error::unknown_symbol;
+ return inconvertibleErrorCode();
}
static std::string formatSymbol(const Dumper::Context &Ctx,
diff --git a/llvm/tools/llvm-readobj/WindowsResourceDumper.cpp b/llvm/tools/llvm-readobj/WindowsResourceDumper.cpp
index a2fb6aac3f93..fb085ecaa76e 100644
--- a/llvm/tools/llvm-readobj/WindowsResourceDumper.cpp
+++ b/llvm/tools/llvm-readobj/WindowsResourceDumper.cpp
@@ -11,7 +11,6 @@
//===----------------------------------------------------------------------===//
#include "WindowsResourceDumper.h"
-#include "Error.h"
#include "llvm/Object/WindowsResource.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/ScopedPrinter.h"
diff --git a/llvm/tools/llvm-readobj/XCOFFDumper.cpp b/llvm/tools/llvm-readobj/XCOFFDumper.cpp
index f60bc7667f06..3e34b9e104ed 100644
--- a/llvm/tools/llvm-readobj/XCOFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/XCOFFDumper.cpp
@@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//
-#include "Error.h"
#include "ObjDumper.h"
#include "llvm-readobj.h"
#include "llvm/Object/XCOFFObjectFile.h"
diff --git a/llvm/tools/llvm-readobj/llvm-readobj.cpp b/llvm/tools/llvm-readobj/llvm-readobj.cpp
index 49fa0eb7690a..a5849295a16a 100644
--- a/llvm/tools/llvm-readobj/llvm-readobj.cpp
+++ b/llvm/tools/llvm-readobj/llvm-readobj.cpp
@@ -19,7 +19,6 @@
//===----------------------------------------------------------------------===//
#include "llvm-readobj.h"
-#include "Error.h"
#include "ObjDumper.h"
#include "WindowsResourceDumper.h"
#include "llvm/DebugInfo/CodeView/GlobalTypeTableBuilder.h"
@@ -579,12 +578,16 @@ static void dumpArchive(const Archive *Arc, ScopedPrinter &Writer) {
reportError(std::move(E), Arc->getFileName());
continue;
}
- if (ObjectFile *Obj = dyn_cast<ObjectFile>(&*ChildOrErr.get()))
+
+ Binary *Bin = ChildOrErr->get();
+ if (ObjectFile *Obj = dyn_cast<ObjectFile>(Bin))
dumpObject(*Obj, Writer, Arc);
- else if (COFFImportFile *Imp = dyn_cast<COFFImportFile>(&*ChildOrErr.get()))
+ else if (COFFImportFile *Imp = dyn_cast<COFFImportFile>(Bin))
dumpCOFFImportFile(Imp, Writer);
else
- reportWarning(errorCodeToError(readobj_error::unrecognized_file_format),
+ reportWarning(createStringError(errc::invalid_argument,
+ Bin->getFileName() +
+ " has an unsupported file type"),
Arc->getFileName());
}
if (Err)
@@ -634,8 +637,7 @@ static void dumpInput(StringRef File, ScopedPrinter &Writer) {
else if (WindowsResource *WinRes = dyn_cast<WindowsResource>(&Binary))
dumpWindowsResourceFile(WinRes, Writer);
else
- reportError(errorCodeToError(readobj_error::unrecognized_file_format),
- File);
+ llvm_unreachable("unrecognized file type");
CVTypes.Binaries.push_back(std::move(*BinaryOrErr));
}
More information about the llvm-commits
mailing list