[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 02:53:21 +02:00
|
|
|
//===------ xcoff2yaml.cpp - XCOFF YAMLIO implementation --------*- 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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "obj2yaml.h"
|
|
|
|
#include "llvm/Object/XCOFFObjectFile.h"
|
|
|
|
#include "llvm/ObjectYAML/XCOFFYAML.h"
|
|
|
|
#include "llvm/Support/YAMLTraits.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::object;
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class XCOFFDumper {
|
|
|
|
const object::XCOFFObjectFile &Obj;
|
|
|
|
XCOFFYAML::Object YAMLObj;
|
|
|
|
void dumpHeader();
|
2019-05-28 16:37:59 +02:00
|
|
|
std::error_code dumpSymbols();
|
[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 02:53:21 +02:00
|
|
|
|
|
|
|
public:
|
2019-05-28 16:37:59 +02:00
|
|
|
XCOFFDumper(const object::XCOFFObjectFile &obj) : Obj(obj) {}
|
|
|
|
std::error_code dump();
|
[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 02:53:21 +02:00
|
|
|
XCOFFYAML::Object &getYAMLObj() { return YAMLObj; }
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2019-05-28 16:37:59 +02:00
|
|
|
std::error_code XCOFFDumper::dump() {
|
[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 02:53:21 +02:00
|
|
|
dumpHeader();
|
2019-07-09 20:09:11 +02:00
|
|
|
return dumpSymbols();
|
[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 02:53:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void XCOFFDumper::dumpHeader() {
|
2019-07-09 20:09:11 +02:00
|
|
|
|
|
|
|
YAMLObj.Header.Magic = Obj.getMagic();
|
|
|
|
YAMLObj.Header.NumberOfSections = Obj.getNumberOfSections();
|
|
|
|
YAMLObj.Header.TimeStamp = Obj.getTimeStamp();
|
|
|
|
|
|
|
|
// TODO FIXME only dump 32 bit header for now.
|
|
|
|
if (Obj.is64Bit())
|
|
|
|
report_fatal_error("64-bit XCOFF files not supported yet.");
|
|
|
|
YAMLObj.Header.SymbolTableOffset = Obj.getSymbolTableOffset32();
|
|
|
|
|
|
|
|
YAMLObj.Header.NumberOfSymTableEntries =
|
|
|
|
Obj.getRawNumberOfSymbolTableEntries32();
|
|
|
|
YAMLObj.Header.AuxHeaderSize = Obj.getOptionalHeaderSize();
|
|
|
|
YAMLObj.Header.Flags = Obj.getFlags();
|
[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 02:53:21 +02:00
|
|
|
}
|
|
|
|
|
2019-05-28 16:37:59 +02:00
|
|
|
std::error_code XCOFFDumper::dumpSymbols() {
|
|
|
|
std::vector<XCOFFYAML::Symbol> &Symbols = YAMLObj.Symbols;
|
|
|
|
|
|
|
|
for (const SymbolRef &S : Obj.symbols()) {
|
|
|
|
DataRefImpl SymbolDRI = S.getRawDataRefImpl();
|
|
|
|
const XCOFFSymbolEntry *SymbolEntPtr = Obj.toSymbolEntry(SymbolDRI);
|
|
|
|
XCOFFYAML::Symbol Sym;
|
|
|
|
|
|
|
|
Expected<StringRef> SymNameRefOrErr = Obj.getSymbolName(SymbolDRI);
|
|
|
|
if (!SymNameRefOrErr) {
|
|
|
|
return errorToErrorCode(SymNameRefOrErr.takeError());
|
|
|
|
}
|
|
|
|
Sym.SymbolName = SymNameRefOrErr.get();
|
|
|
|
|
|
|
|
Sym.Value = SymbolEntPtr->Value;
|
|
|
|
|
|
|
|
Expected<StringRef> SectionNameRefOrErr =
|
|
|
|
Obj.getSymbolSectionName(SymbolEntPtr);
|
|
|
|
if (!SectionNameRefOrErr)
|
|
|
|
return errorToErrorCode(SectionNameRefOrErr.takeError());
|
|
|
|
|
|
|
|
Sym.SectionName = SectionNameRefOrErr.get();
|
|
|
|
|
|
|
|
Sym.Type = SymbolEntPtr->SymbolType;
|
|
|
|
Sym.StorageClass = SymbolEntPtr->StorageClass;
|
|
|
|
Sym.NumberOfAuxEntries = SymbolEntPtr->NumberOfAuxEntries;
|
|
|
|
Symbols.push_back(Sym);
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::error_code();
|
|
|
|
}
|
|
|
|
|
[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 02:53:21 +02:00
|
|
|
std::error_code xcoff2yaml(raw_ostream &Out,
|
|
|
|
const object::XCOFFObjectFile &Obj) {
|
|
|
|
XCOFFDumper Dumper(Obj);
|
2019-05-28 16:37:59 +02:00
|
|
|
|
|
|
|
if (std::error_code EC = Dumper.dump())
|
|
|
|
return EC;
|
|
|
|
|
[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 02:53:21 +02:00
|
|
|
yaml::Output Yout(Out);
|
|
|
|
Yout << Dumper.getYAMLObj();
|
|
|
|
|
|
|
|
return std::error_code();
|
|
|
|
}
|