1 //===-- OffloadDump.cpp - Offloading dumper ---------------------*- 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 //===----------------------------------------------------------------------===//
10 /// This file implements the offloading-specific dumper for llvm-objdump.
12 //===----------------------------------------------------------------------===//
14 #include "OffloadDump.h"
15 #include "llvm-objdump.h"
16 #include "llvm/Object/ELFObjectFile.h"
17 #include "llvm/Support/Alignment.h"
20 using namespace llvm::object
;
21 using namespace llvm::objdump
;
23 /// Get the printable name of the image kind.
24 static StringRef
getImageName(const OffloadBinary
&OB
) {
25 switch (OB
.getImageKind()) {
41 static void printBinary(const OffloadBinary
&OB
, uint64_t Index
) {
42 outs() << "\nOFFLOADING IMAGE [" << Index
<< "]:\n";
43 outs() << left_justify("kind", 16) << getImageName(OB
) << "\n";
44 outs() << left_justify("arch", 16) << OB
.getArch() << "\n";
45 outs() << left_justify("triple", 16) << OB
.getTriple() << "\n";
46 outs() << left_justify("producer", 16)
47 << getOffloadKindName(OB
.getOffloadKind()) << "\n";
50 /// Print the embedded offloading contents of an ObjectFile \p O.
51 void llvm::dumpOffloadBinary(const ObjectFile
&O
) {
52 if (!O
.isELF() && !O
.isCOFF()) {
54 "--offloading is currently only supported for COFF and ELF targets",
59 SmallVector
<OffloadFile
> Binaries
;
60 if (Error Err
= extractOffloadBinaries(O
.getMemoryBufferRef(), Binaries
))
61 reportError(O
.getFileName(), "while extracting offloading files: " +
62 toString(std::move(Err
)));
64 // Print out all the binaries that are contained in this buffer.
65 for (uint64_t I
= 0, E
= Binaries
.size(); I
!= E
; ++I
)
66 printBinary(*Binaries
[I
].getBinary(), I
);
69 /// Print the contents of an offload binary file \p OB. This may contain
70 /// multiple binaries stored in the same buffer.
71 void llvm::dumpOffloadSections(const OffloadBinary
&OB
) {
72 SmallVector
<OffloadFile
> Binaries
;
73 if (Error Err
= extractOffloadBinaries(OB
.getMemoryBufferRef(), Binaries
))
74 reportError(OB
.getFileName(), "while extracting offloading files: " +
75 toString(std::move(Err
)));
77 // Print out all the binaries that are contained in this buffer.
78 for (uint64_t I
= 0, E
= Binaries
.size(); I
!= E
; ++I
)
79 printBinary(*Binaries
[I
].getBinary(), I
);