diff options
Diffstat (limited to 'tools/obj2yaml')
-rw-r--r-- | tools/obj2yaml/Android.mk | 2 | ||||
-rw-r--r-- | tools/obj2yaml/Error.cpp | 21 | ||||
-rw-r--r-- | tools/obj2yaml/Error.h | 33 | ||||
-rw-r--r-- | tools/obj2yaml/coff2yaml.cpp | 6 | ||||
-rw-r--r-- | tools/obj2yaml/elf2yaml.cpp | 88 | ||||
-rw-r--r-- | tools/obj2yaml/obj2yaml.cpp | 8 | ||||
-rw-r--r-- | tools/obj2yaml/obj2yaml.h | 10 |
7 files changed, 85 insertions, 83 deletions
diff --git a/tools/obj2yaml/Android.mk b/tools/obj2yaml/Android.mk index 8c8fdab..2994622 100644 --- a/tools/obj2yaml/Android.mk +++ b/tools/obj2yaml/Android.mk @@ -15,6 +15,8 @@ obj2yaml_SRC_FILES := \ obj2yaml_STATIC_LIBRARIES := \ libLLVMObject \ + libLLVMMC \ + libLLVMMCParser \ libLLVMBitReader \ libLLVMCore \ libLLVMSupport \ diff --git a/tools/obj2yaml/Error.cpp b/tools/obj2yaml/Error.cpp index 7be468d..0074128 100644 --- a/tools/obj2yaml/Error.cpp +++ b/tools/obj2yaml/Error.cpp @@ -13,18 +13,17 @@ using namespace llvm; namespace { -class _obj2yaml_error_category : public error_category { +class _obj2yaml_error_category : public std::error_category { public: - const char *name() const override; + const char *name() const LLVM_NOEXCEPT override; std::string message(int ev) const override; - error_condition default_error_condition(int ev) const override; }; } // namespace const char *_obj2yaml_error_category::name() const { return "obj2yaml"; } std::string _obj2yaml_error_category::message(int ev) const { - switch (ev) { + switch (static_cast<obj2yaml_error>(ev)) { case obj2yaml_error::success: return "Success"; case obj2yaml_error::file_not_found: @@ -33,21 +32,13 @@ std::string _obj2yaml_error_category::message(int ev) const { return "Unrecognized file type."; case obj2yaml_error::unsupported_obj_file_format: return "Unsupported object file format."; - default: - llvm_unreachable("An enumerator of obj2yaml_error does not have a message " - "defined."); } -} - -error_condition -_obj2yaml_error_category::default_error_condition(int ev) const { - if (ev == obj2yaml_error::success) - return errc::success; - return errc::invalid_argument; + llvm_unreachable("An enumerator of obj2yaml_error does not have a message " + "defined."); } namespace llvm { -const error_category &obj2yaml_category() { + const std::error_category &obj2yaml_category() { static _obj2yaml_error_category o; return o; } diff --git a/tools/obj2yaml/Error.h b/tools/obj2yaml/Error.h index a326664..4657f0d 100644 --- a/tools/obj2yaml/Error.h +++ b/tools/obj2yaml/Error.h @@ -10,33 +10,26 @@ #ifndef LLVM_TOOLS_ERROR_H #define LLVM_TOOLS_ERROR_H -#include "llvm/Support/system_error.h" +#include <system_error> namespace llvm { +const std::error_category &obj2yaml_category(); -const error_category &obj2yaml_category(); - -struct obj2yaml_error { - enum _ { - success = 0, - file_not_found, - unrecognized_file_format, - unsupported_obj_file_format - }; - _ v_; - - obj2yaml_error(_ v) : v_(v) {} - explicit obj2yaml_error(int v) : v_(_(v)) {} - operator int() const {return v_;} +enum class obj2yaml_error { + success = 0, + file_not_found, + unrecognized_file_format, + unsupported_obj_file_format }; -inline error_code make_error_code(obj2yaml_error e) { - return error_code(static_cast<int>(e), obj2yaml_category()); +inline std::error_code make_error_code(obj2yaml_error e) { + return std::error_code(static_cast<int>(e), obj2yaml_category()); } -template <> struct is_error_code_enum<obj2yaml_error> : std::true_type { }; -template <> struct is_error_code_enum<obj2yaml_error::_> : std::true_type { }; - } // namespace llvm +namespace std { +template <> struct is_error_code_enum<llvm::obj2yaml_error> : std::true_type {}; +} + #endif diff --git a/tools/obj2yaml/coff2yaml.cpp b/tools/obj2yaml/coff2yaml.cpp index 42b09d3..fed4533 100644 --- a/tools/obj2yaml/coff2yaml.cpp +++ b/tools/obj2yaml/coff2yaml.cpp @@ -31,7 +31,7 @@ public: } -static void check(error_code ec) { +static void check(std::error_code ec) { if (ec) report_fatal_error(ec.message()); } @@ -61,7 +61,7 @@ void COFFDumper::dumpSections(unsigned NumSections) { ArrayRef<uint8_t> sectionData; Obj.getSectionContents(Sect, sectionData); - Sec.SectionData = object::yaml::BinaryRef(sectionData); + Sec.SectionData = yaml::BinaryRef(sectionData); std::vector<COFFYAML::Relocation> Relocations; for (const auto &Reloc : Section.relocations()) { @@ -210,7 +210,7 @@ COFFYAML::Object &COFFDumper::getYAMLObj() { 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); yaml::Output Yout(Out); diff --git a/tools/obj2yaml/elf2yaml.cpp b/tools/obj2yaml/elf2yaml.cpp index 7642921..8b53ee7 100644 --- a/tools/obj2yaml/elf2yaml.cpp +++ b/tools/obj2yaml/elf2yaml.cpp @@ -26,11 +26,13 @@ class ELFDumper { const object::ELFFile<ELFT> &Obj; - error_code dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S); - error_code dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S); + std::error_code dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S); + std::error_code dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S); + std::error_code dumpCommonRelocationSection(const Elf_Shdr *Shdr, + ELFYAML::RelocationSection &S); template <class RelT> - error_code dumpRelocation(const Elf_Shdr *Shdr, const RelT *Rel, - ELFYAML::Relocation &R); + std::error_code dumpRelocation(const Elf_Shdr *Shdr, const RelT *Rel, + ELFYAML::Relocation &R); ErrorOr<ELFYAML::RelocationSection *> dumpRelSection(const Elf_Shdr *Shdr); ErrorOr<ELFYAML::RelocationSection *> dumpRelaSection(const Elf_Shdr *Shdr); @@ -72,21 +74,22 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() { break; case ELF::SHT_RELA: { ErrorOr<ELFYAML::RelocationSection *> S = dumpRelaSection(&Sec); - if (error_code EC = S.getError()) + if (std::error_code EC = S.getError()) return EC; Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get())); break; } case ELF::SHT_REL: { ErrorOr<ELFYAML::RelocationSection *> S = dumpRelSection(&Sec); - if (error_code EC = S.getError()) + if (std::error_code EC = S.getError()) return EC; Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get())); break; } + // FIXME: Support SHT_GROUP section format. default: { ErrorOr<ELFYAML::RawContentSection *> S = dumpContentSection(&Sec); - if (error_code EC = S.getError()) + if (std::error_code EC = S.getError()) return EC; Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get())); } @@ -102,7 +105,7 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() { } ELFYAML::Symbol S; - if (error_code EC = ELFDumper<ELFT>::dumpSymbol(SI, S)) + if (std::error_code EC = ELFDumper<ELFT>::dumpSymbol(SI, S)) return EC; switch (SI->getBinding()) @@ -125,13 +128,15 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() { } 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.Value = Sym->st_value; S.Size = Sym->st_size; + S.Visibility = Sym->st_other & 0x3; ErrorOr<StringRef> NameOrErr = Obj.getSymbolName(Sym); - if (error_code EC = NameOrErr.getError()) + if (std::error_code EC = NameOrErr.getError()) return EC; S.Name = NameOrErr.get(); @@ -140,7 +145,7 @@ error_code ELFDumper<ELFT>::dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S) { return obj2yaml_error::success; NameOrErr = Obj.getSectionName(Shdr); - if (error_code EC = NameOrErr.getError()) + if (std::error_code EC = NameOrErr.getError()) return EC; S.Section = NameOrErr.get(); @@ -149,9 +154,9 @@ error_code ELFDumper<ELFT>::dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S) { template <class ELFT> template <class RelT> -error_code ELFDumper<ELFT>::dumpRelocation(const Elf_Shdr *Shdr, - const RelT *Rel, - ELFYAML::Relocation &R) { +std::error_code ELFDumper<ELFT>::dumpRelocation(const Elf_Shdr *Shdr, + const RelT *Rel, + ELFYAML::Relocation &R) { R.Type = Rel->getType(Obj.isMips64EL()); R.Offset = Rel->r_offset; R.Addend = 0; @@ -162,7 +167,7 @@ error_code ELFDumper<ELFT>::dumpRelocation(const Elf_Shdr *Shdr, ErrorOr<StringRef> NameOrErr = Obj.getSymbolName(NamePair.first, NamePair.second); - if (error_code EC = NameOrErr.getError()) + if (std::error_code EC = NameOrErr.getError()) return EC; R.Symbol = NameOrErr.get(); @@ -170,34 +175,44 @@ error_code ELFDumper<ELFT>::dumpRelocation(const Elf_Shdr *Shdr, } template <class ELFT> -error_code ELFDumper<ELFT>::dumpCommonSection(const Elf_Shdr *Shdr, - ELFYAML::Section &S) { +std::error_code ELFDumper<ELFT>::dumpCommonSection(const Elf_Shdr *Shdr, + ELFYAML::Section &S) { S.Type = Shdr->sh_type; S.Flags = Shdr->sh_flags; S.Address = Shdr->sh_addr; S.AddressAlign = Shdr->sh_addralign; ErrorOr<StringRef> NameOrErr = Obj.getSectionName(Shdr); - if (error_code EC = NameOrErr.getError()) + if (std::error_code EC = NameOrErr.getError()) return EC; S.Name = NameOrErr.get(); if (Shdr->sh_link != ELF::SHN_UNDEF) { if (const Elf_Shdr *LinkSection = Obj.getSection(Shdr->sh_link)) { NameOrErr = Obj.getSectionName(LinkSection); - if (error_code EC = NameOrErr.getError()) + if (std::error_code EC = NameOrErr.getError()) return EC; S.Link = NameOrErr.get(); } } - if (Shdr->sh_info != ELF::SHN_UNDEF) { - if (const Elf_Shdr *InfoSection = Obj.getSection(Shdr->sh_info)) { - NameOrErr = Obj.getSectionName(InfoSection); - if (error_code EC = NameOrErr.getError()) - return EC; - S.Info = NameOrErr.get(); - } + + return obj2yaml_error::success; +} + +template <class ELFT> +std::error_code +ELFDumper<ELFT>::dumpCommonRelocationSection(const Elf_Shdr *Shdr, + ELFYAML::RelocationSection &S) { + if (std::error_code EC = dumpCommonSection(Shdr, S)) + return EC; + + if (const Elf_Shdr *InfoSection = Obj.getSection(Shdr->sh_info)) { + ErrorOr<StringRef> NameOrErr = Obj.getSectionName(InfoSection); + if (std::error_code EC = NameOrErr.getError()) + return EC; + S.Info = NameOrErr.get(); } + return obj2yaml_error::success; } @@ -207,13 +222,13 @@ ELFDumper<ELFT>::dumpRelSection(const Elf_Shdr *Shdr) { assert(Shdr->sh_type == ELF::SHT_REL && "Section type is not SHT_REL"); auto S = make_unique<ELFYAML::RelocationSection>(); - if (error_code EC = dumpCommonSection(Shdr, *S)) + if (std::error_code EC = dumpCommonRelocationSection(Shdr, *S)) return EC; for (auto RI = Obj.begin_rel(Shdr), RE = Obj.end_rel(Shdr); RI != RE; ++RI) { ELFYAML::Relocation R; - if (error_code EC = dumpRelocation(Shdr, &*RI, R)) + if (std::error_code EC = dumpRelocation(Shdr, &*RI, R)) return EC; S->Relocations.push_back(R); } @@ -227,13 +242,13 @@ ELFDumper<ELFT>::dumpRelaSection(const Elf_Shdr *Shdr) { assert(Shdr->sh_type == ELF::SHT_RELA && "Section type is not SHT_RELA"); auto S = make_unique<ELFYAML::RelocationSection>(); - if (error_code EC = dumpCommonSection(Shdr, *S)) + if (std::error_code EC = dumpCommonRelocationSection(Shdr, *S)) return EC; for (auto RI = Obj.begin_rela(Shdr), RE = Obj.end_rela(Shdr); RI != RE; ++RI) { ELFYAML::Relocation R; - if (error_code EC = dumpRelocation(Shdr, &*RI, R)) + if (std::error_code EC = dumpRelocation(Shdr, &*RI, R)) return EC; R.Addend = RI->r_addend; S->Relocations.push_back(R); @@ -247,23 +262,24 @@ ErrorOr<ELFYAML::RawContentSection *> ELFDumper<ELFT>::dumpContentSection(const Elf_Shdr *Shdr) { auto S = make_unique<ELFYAML::RawContentSection>(); - if (error_code EC = dumpCommonSection(Shdr, *S)) + if (std::error_code EC = dumpCommonSection(Shdr, *S)) return EC; ErrorOr<ArrayRef<uint8_t>> ContentOrErr = Obj.getSectionContents(Shdr); - if (error_code EC = ContentOrErr.getError()) + if (std::error_code EC = ContentOrErr.getError()) return EC; - S->Content = object::yaml::BinaryRef(ContentOrErr.get()); + S->Content = yaml::BinaryRef(ContentOrErr.get()); S->Size = S->Content.binary_size(); return S.release(); } 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); ErrorOr<ELFYAML::Object *> YAMLOrErr = Dumper.dump(); - if (error_code EC = YAMLOrErr.getError()) + if (std::error_code EC = YAMLOrErr.getError()) return EC; std::unique_ptr<ELFYAML::Object> YAML(YAMLOrErr.get()); @@ -273,7 +289,7 @@ static error_code elf2yaml(raw_ostream &Out, const object::ELFFile<ELFT> &Obj) { 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)) return elf2yaml(Out, *ELFObj->getELFFile()); diff --git a/tools/obj2yaml/obj2yaml.cpp b/tools/obj2yaml/obj2yaml.cpp index 7fe034d..944314a 100644 --- a/tools/obj2yaml/obj2yaml.cpp +++ b/tools/obj2yaml/obj2yaml.cpp @@ -19,7 +19,7 @@ using namespace llvm; using namespace llvm::object; -static error_code dumpObject(const ObjectFile &Obj) { +static std::error_code dumpObject(const ObjectFile &Obj) { if (Obj.isCOFF()) return coff2yaml(outs(), cast<COFFObjectFile>(Obj)); if (Obj.isELF()) @@ -28,12 +28,12 @@ static error_code dumpObject(const ObjectFile &Obj) { 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)) return obj2yaml_error::file_not_found; ErrorOr<Binary *> BinaryOrErr = createBinary(File); - if (error_code EC = BinaryOrErr.getError()) + if (std::error_code EC = BinaryOrErr.getError()) return EC; std::unique_ptr<Binary> Binary(BinaryOrErr.get()); @@ -53,7 +53,7 @@ int main(int argc, char *argv[]) { PrettyStackTraceProgram X(argc, argv); 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"; return 1; } diff --git a/tools/obj2yaml/obj2yaml.h b/tools/obj2yaml/obj2yaml.h index 73c58fa..6d81110 100644 --- a/tools/obj2yaml/obj2yaml.h +++ b/tools/obj2yaml/obj2yaml.h @@ -15,11 +15,11 @@ #include "llvm/Object/COFF.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Support/system_error.h" +#include <system_error> -llvm::error_code coff2yaml(llvm::raw_ostream &Out, - const llvm::object::COFFObjectFile &Obj); -llvm::error_code elf2yaml(llvm::raw_ostream &Out, - const llvm::object::ObjectFile &Obj); +std::error_code coff2yaml(llvm::raw_ostream &Out, + const llvm::object::COFFObjectFile &Obj); +std::error_code elf2yaml(llvm::raw_ostream &Out, + const llvm::object::ObjectFile &Obj); #endif |