aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
authorJoseph Huber <jhuber6@vols.utk.edu>2022-06-02 14:25:49 -0400
committerJoseph Huber <jhuber6@vols.utk.edu>2022-07-01 21:13:28 -0400
commitd2d8b0aa4f80752722321d1e74e2d98761caaa61 (patch)
tree26061396a9dc76e670ca849cb307bae58d9e2053 /llvm/tools/llvm-objdump/llvm-objdump.cpp
parent228c8f9cc0b2bf615706567f121a422b1b0e7f83 (diff)
downloadllvm-d2d8b0aa4f80752722321d1e74e2d98761caaa61.zip
llvm-d2d8b0aa4f80752722321d1e74e2d98761caaa61.tar.gz
llvm-d2d8b0aa4f80752722321d1e74e2d98761caaa61.tar.bz2
[llvm-objdump] Add support for dumping embedded offloading data
In Clang/LLVM we are moving towards a new binary format to store many embedded object files to create a fatbinary. This patch adds support for dumping these embedded images in the `llvm-objdump` tool. This will allow users to query information about what is stored inside the binary. This has very similar functionality to the `cuobjdump` tool for thoe familiar with the Nvidia utilities. The proposed use is as follows: ``` $ clang input.c -fopenmp --offload-arch=sm_70 --offload-arch=sm_52 -c $ llvm-objdump -O input.o input.o: file format elf64-x86-64 OFFLOADIND IMAGE [0]: kind cubin arch sm_52 triple nvptx64-nvidia-cuda producer openmp OFFLOADIND IMAGE [1]: kind cubin arch sm_70 triple nvptx64-nvidia-cuda producer openmp ``` This will be expanded further once we start embedding more information into these offloading images. Right now we are planning on adding flags and entries for debug level, optimization, LTO usage, target features, among others. This patch only supports printing these sections, later we will want to support dumping files the user may be interested in via another flag. I am unsure if this should go here in `llvm-objdump` or `llvm-objcopy`. Reviewed By: MaskRay, tra, jhenderson, JonChesterfield Differential Revision: https://reviews.llvm.org/D126904
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index dc7083b..7cd47da 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -20,6 +20,7 @@
#include "ELFDump.h"
#include "MachODump.h"
#include "ObjdumpOptID.h"
+#include "OffloadDump.h"
#include "SourcePrinter.h"
#include "WasmDump.h"
#include "XCOFFDump.h"
@@ -58,6 +59,7 @@
#include "llvm/Object/MachO.h"
#include "llvm/Object/MachOUniversal.h"
#include "llvm/Object/ObjectFile.h"
+#include "llvm/Object/OffloadBinary.h"
#include "llvm/Object/Wasm.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
@@ -198,6 +200,7 @@ std::string objdump::MCPU;
std::vector<std::string> objdump::MAttrs;
bool objdump::ShowRawInsn;
bool objdump::LeadingAddr;
+static bool Offloading;
static bool RawClangAST;
bool objdump::Relocations;
bool objdump::PrintImmHex;
@@ -2480,6 +2483,8 @@ static void dumpObject(ObjectFile *O, const Archive *A = nullptr,
printRawClangAST(O);
if (FaultMapSection)
printFaultMaps(O);
+ if (Offloading)
+ dumpOffloadBinary(*O);
}
static void dumpObject(const COFFImportFile *I, const Archive *A,
@@ -2543,6 +2548,8 @@ static void dumpInput(StringRef file) {
dumpObject(O);
else if (MachOUniversalBinary *UB = dyn_cast<MachOUniversalBinary>(&Binary))
parseInputMachO(UB);
+ else if (OffloadBinary *OB = dyn_cast<OffloadBinary>(&Binary))
+ dumpOffloadSections(*OB);
else
reportError(errorCodeToError(object_error::invalid_file_type), file);
}
@@ -2646,6 +2653,7 @@ static void parseObjdumpOptions(const llvm::opt::InputArgList &InputArgs) {
}
DynamicRelocations = InputArgs.hasArg(OBJDUMP_dynamic_reloc);
FaultMapSection = InputArgs.hasArg(OBJDUMP_fault_map_section);
+ Offloading = InputArgs.hasArg(OBJDUMP_offloading);
FileHeaders = InputArgs.hasArg(OBJDUMP_file_headers);
SectionContents = InputArgs.hasArg(OBJDUMP_full_contents);
PrintLines = InputArgs.hasArg(OBJDUMP_line_numbers);
@@ -2813,7 +2821,7 @@ int main(int argc, char **argv) {
if (!ArchiveHeaders && !Disassemble && DwarfDumpType == DIDT_Null &&
!DynamicRelocations && !FileHeaders && !PrivateHeaders && !RawClangAST &&
!Relocations && !SectionHeaders && !SectionContents && !SymbolTable &&
- !DynamicSymbolTable && !UnwindInfo && !FaultMapSection &&
+ !DynamicSymbolTable && !UnwindInfo && !FaultMapSection && !Offloading &&
!(MachOOpt && (Bind || DataInCode || DyldInfo || DylibId || DylibsUsed ||
ExportsTrie || FirstPrivateHeader || FunctionStarts ||
IndirectSymbols || InfoPlist || LazyBind || LinkOptHints ||