1 //===-- XCOFFDumper.cpp - XCOFF dumping utility -----------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements an XCOFF specific dumper for llvm-readobj.
11 //===----------------------------------------------------------------------===//
14 #include "ObjDumper.h"
15 #include "llvm-readobj.h"
16 #include "llvm/Object/XCOFFObjectFile.h"
17 #include "llvm/Support/ScopedPrinter.h"
20 using namespace object
;
24 class XCOFFDumper
: public ObjDumper
{
26 XCOFFDumper(const XCOFFObjectFile
&Obj
, ScopedPrinter
&Writer
)
27 : ObjDumper(Writer
), Obj(Obj
) {}
29 void printFileHeaders() override
;
30 void printSectionHeaders() override
;
31 void printRelocations() override
;
32 void printSymbols() override
;
33 void printDynamicSymbols() override
;
34 void printUnwindInfo() override
;
35 void printStackMap() const override
;
36 void printNeededLibraries() override
;
39 const XCOFFObjectFile
&Obj
;
41 } // anonymous namespace
43 void XCOFFDumper::printFileHeaders() {
44 DictScope
DS(W
, "FileHeader");
45 W
.printHex("Magic", Obj
.getMagic());
46 W
.printNumber("NumberOfSections", Obj
.getNumberOfSections());
48 // Negative timestamp values are reserved for future use.
49 int32_t TimeStamp
= Obj
.getTimeStamp();
51 // This handling of the time stamp assumes that the host system's time_t is
52 // compatible with AIX time_t. If a platform is not compatible, the lit
53 // tests will let us know.
54 time_t TimeDate
= TimeStamp
;
56 char FormattedTime
[21] = {};
58 strftime(FormattedTime
, 21, "%Y-%m-%dT%H:%M:%SZ", gmtime(&TimeDate
));
60 W
.printHex("TimeStamp", FormattedTime
, TimeStamp
);
62 W
.printHex("Timestamp", TimeStamp
);
64 W
.printHex("TimeStamp", TimeStamp
== 0 ? "None" : "Reserved Value",
68 W
.printHex("SymbolTableOffset", Obj
.getSymbolTableOffset());
69 int32_t SymTabEntries
= Obj
.getRawNumberOfSymbolTableEntries();
70 if (SymTabEntries
>= 0)
71 W
.printNumber("SymbolTableEntries", SymTabEntries
);
73 W
.printHex("SymbolTableEntries", "Reserved Value", SymTabEntries
);
75 W
.printHex("OptionalHeaderSize", Obj
.getOptionalHeaderSize());
76 W
.printHex("Flags", Obj
.getFlags());
78 // TODO FIXME Add support for the auxiliary header (if any) once
79 // XCOFFObjectFile has the necessary support.
82 void XCOFFDumper::printSectionHeaders() {
83 llvm_unreachable("Unimplemented functionality for XCOFFDumper");
86 void XCOFFDumper::printRelocations() {
87 llvm_unreachable("Unimplemented functionality for XCOFFDumper");
90 void XCOFFDumper::printSymbols() {
91 llvm_unreachable("Unimplemented functionality for XCOFFDumper");
94 void XCOFFDumper::printDynamicSymbols() {
95 llvm_unreachable("Unimplemented functionality for XCOFFDumper");
98 void XCOFFDumper::printUnwindInfo() {
99 llvm_unreachable("Unimplemented functionality for XCOFFDumper");
102 void XCOFFDumper::printStackMap() const {
103 llvm_unreachable("Unimplemented functionality for XCOFFDumper");
106 void XCOFFDumper::printNeededLibraries() {
107 llvm_unreachable("Unimplemented functionality for XCOFFDumper");
111 std::error_code
createXCOFFDumper(const object::ObjectFile
*Obj
,
112 ScopedPrinter
&Writer
,
113 std::unique_ptr
<ObjDumper
> &Result
) {
114 const XCOFFObjectFile
*XObj
= dyn_cast
<XCOFFObjectFile
>(Obj
);
116 return readobj_error::unsupported_obj_file_format
;
118 Result
.reset(new XCOFFDumper(*XObj
, Writer
));
119 return readobj_error::success
;