2012-06-20 02:02:35 +08:00
|
|
|
//===------ utils/obj2yaml.cpp - obj2yaml conversion tool -------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2012-06-20 02:02:35 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "obj2yaml.h"
|
2018-04-14 02:26:06 +08:00
|
|
|
#include "Error.h"
|
2012-12-04 18:37:14 +08:00
|
|
|
#include "llvm/Object/Archive.h"
|
|
|
|
#include "llvm/Object/COFF.h"
|
2019-04-02 19:58:37 +08:00
|
|
|
#include "llvm/Object/Minidump.h"
|
2012-06-20 02:02:35 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2018-04-14 02:26:06 +08:00
|
|
|
#include "llvm/Support/InitLLVM.h"
|
2012-06-20 02:02:35 +08:00
|
|
|
|
2013-04-08 16:55:14 +08:00
|
|
|
using namespace llvm;
|
2014-05-07 13:18:51 +08:00
|
|
|
using namespace llvm::object;
|
2013-04-08 16:55:14 +08:00
|
|
|
|
2014-06-13 11:07:50 +08:00
|
|
|
static std::error_code dumpObject(const ObjectFile &Obj) {
|
2014-05-07 13:18:51 +08:00
|
|
|
if (Obj.isCOFF())
|
|
|
|
return coff2yaml(outs(), cast<COFFObjectFile>(Obj));
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
|
|
|
|
if (Obj.isXCOFF())
|
|
|
|
return xcoff2yaml(outs(), cast<XCOFFObjectFile>(Obj));
|
|
|
|
|
2014-05-14 13:07:47 +08:00
|
|
|
if (Obj.isELF())
|
|
|
|
return elf2yaml(outs(), Obj);
|
2017-03-31 03:44:09 +08:00
|
|
|
if (Obj.isWasm())
|
|
|
|
return wasm2yaml(outs(), cast<WasmObjectFile>(Obj));
|
2014-05-07 13:18:51 +08:00
|
|
|
|
|
|
|
return obj2yaml_error::unsupported_obj_file_format;
|
2013-04-08 16:55:14 +08:00
|
|
|
}
|
2012-06-20 02:02:35 +08:00
|
|
|
|
2017-06-17 07:29:54 +08:00
|
|
|
static Error dumpInput(StringRef File) {
|
2016-04-07 06:14:09 +08:00
|
|
|
Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(File);
|
|
|
|
if (!BinaryOrErr)
|
2017-06-17 07:29:54 +08:00
|
|
|
return BinaryOrErr.takeError();
|
2014-05-07 13:18:51 +08:00
|
|
|
|
2014-08-20 02:44:46 +08:00
|
|
|
Binary &Binary = *BinaryOrErr.get().getBinary();
|
2016-06-25 04:42:28 +08:00
|
|
|
// Universal MachO is not a subclass of ObjectFile, so it needs to be handled
|
|
|
|
// here with the other binary types.
|
|
|
|
if (Binary.isMachO() || Binary.isMachOUniversalBinary())
|
2017-06-17 07:29:54 +08:00
|
|
|
return errorCodeToError(macho2yaml(outs(), Binary));
|
2014-05-07 13:18:51 +08:00
|
|
|
// TODO: If this is an archive, then burst it and dump each entry
|
2014-08-01 22:31:55 +08:00
|
|
|
if (ObjectFile *Obj = dyn_cast<ObjectFile>(&Binary))
|
2017-06-17 07:29:54 +08:00
|
|
|
return errorCodeToError(dumpObject(*Obj));
|
2019-04-02 19:58:37 +08:00
|
|
|
if (MinidumpFile *Minidump = dyn_cast<MinidumpFile>(&Binary))
|
|
|
|
return minidump2yaml(outs(), *Minidump);
|
2014-05-07 13:18:51 +08:00
|
|
|
|
2017-06-17 07:29:54 +08:00
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reportError(StringRef Input, Error Err) {
|
|
|
|
if (Input == "-")
|
|
|
|
Input = "<stdin>";
|
|
|
|
std::string ErrMsg;
|
|
|
|
raw_string_ostream OS(ErrMsg);
|
2018-11-11 09:46:03 +08:00
|
|
|
logAllUnhandledErrors(std::move(Err), OS);
|
2017-06-17 07:29:54 +08:00
|
|
|
OS.flush();
|
|
|
|
errs() << "Error reading file: " << Input << ": " << ErrMsg;
|
|
|
|
errs().flush();
|
2014-05-07 13:18:51 +08:00
|
|
|
}
|
2013-04-08 16:39:59 +08:00
|
|
|
|
|
|
|
cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input file>"),
|
|
|
|
cl::init("-"));
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2018-04-14 02:26:06 +08:00
|
|
|
InitLLVM X(argc, argv);
|
2012-06-20 02:02:35 +08:00
|
|
|
cl::ParseCommandLineOptions(argc, argv);
|
|
|
|
|
2017-06-17 07:29:54 +08:00
|
|
|
if (Error Err = dumpInput(InputFilename)) {
|
|
|
|
reportError(InputFilename, std::move(Err));
|
2014-05-07 13:18:51 +08:00
|
|
|
return 1;
|
2012-06-20 02:02:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|