Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/docs/CommandGuide/llvm-readelf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ OPTIONS

Display all notes.

.. option:: --offloading

Display list of HIP offload bundles.

.. option:: --pretty-print

When used with :option:`--elf-output-style`, JSON output will be formatted in
Expand Down
4 changes: 4 additions & 0 deletions llvm/docs/CommandGuide/llvm-readobj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ file formats.
Do not demangle symbol names in the output. This option is only for ELF and
XCOFF file formats. The option is enabled by default.

.. option:: --offloading

Display list of HIP offload bundles.

.. option:: --relocations, --relocs, -r

Display the relocation entries in the file.
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Object/OffloadBundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ struct OffloadBundleURI {
OffsetStr.getAsInteger(10, O);
Str = Str.drop_front(OffsetStr.size());

if (Str.consume_front("&size="))
if (!Str.consume_front("&size="))
return createStringError(object_error::parse_failed,
"Reading 'size' in URI");

Expand Down
18 changes: 9 additions & 9 deletions llvm/lib/Object/OffloadBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ Error OffloadBundleFatBin::readEntries(StringRef Buffer,
uint64_t EntryIDSize;
StringRef EntryID;

if (auto EC = Reader.readInteger(EntryOffset))
return errorCodeToError(object_error::parse_failed);
if (Error EC = Reader.readInteger(EntryOffset))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: since EC usually stands for "error code" and you're using an Error not std::error_code, I'd change the name to Err or similar.

return EC;

if (auto EC = Reader.readInteger(EntrySize))
return errorCodeToError(object_error::parse_failed);
if (Error EC = Reader.readInteger(EntrySize))
return EC;

if (auto EC = Reader.readInteger(EntryIDSize))
return errorCodeToError(object_error::parse_failed);
if (Error EC = Reader.readInteger(EntryIDSize))
return EC;

if (auto EC = Reader.readFixedString(EntryID, EntryIDSize))
return errorCodeToError(object_error::parse_failed);
if (Error EC = Reader.readFixedString(EntryID, EntryIDSize))
return EC;

auto Entry = std::make_unique<OffloadBundleEntry>(
EntryOffset + SectionOffset, EntrySize, EntryIDSize, EntryID);
Expand All @@ -125,7 +125,7 @@ OffloadBundleFatBin::create(MemoryBufferRef Buf, uint64_t SectionOffset,
// Read the Bundle Entries
Error Err = TheBundle->readEntries(Buf.getBuffer(), SectionOffset);
if (Err)
return errorCodeToError(object_error::parse_failed);
return Err;

return std::unique_ptr<OffloadBundleFatBin>(TheBundle);
}
Expand Down
27 changes: 27 additions & 0 deletions llvm/test/tools/llvm-readobj/ELF/AMDGPU/offloading-fail.test

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions llvm/test/tools/llvm-readobj/ELF/AMDGPU/offloading.test

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions llvm/tools/llvm-readobj/ObjDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "llvm/Object/Archive.h"
#include "llvm/Object/Decompressor.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Object/OffloadBinary.h"
#include "llvm/Object/OffloadBundle.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/ScopedPrinter.h"
Expand Down Expand Up @@ -230,4 +232,14 @@ void ObjDumper::printSectionsAsHex(const object::ObjectFile &Obj,
}
}

void ObjDumper::printOffloading(const object::ObjectFile &Obj) {
SmallVector<llvm::object::OffloadBundleFatBin> Bundles;
if (Error Err = object::extractOffloadBundleFatBinary(Obj, Bundles))
reportWarning(std::move(Err), Obj.getFileName());

// Print out all the FatBin Bundles that are contained in this buffer.
for (const auto &[Index, Bundle] : llvm::enumerate(Bundles))
Bundle.printEntriesAsURI();
}

} // namespace llvm
2 changes: 2 additions & 0 deletions llvm/tools/llvm-readobj/ObjDumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Object/OffloadBinary.h"
#include "llvm/Support/CommandLine.h"

#include <unordered_set>
Expand Down Expand Up @@ -186,6 +187,7 @@ class ObjDumper {
std::function<Error(const Twine &Msg)> WarningHandler;
void reportUniqueWarning(Error Err) const;
void reportUniqueWarning(const Twine &Msg) const;
void printOffloading(const object::ObjectFile &Obj);

protected:
ScopedPrinter &W;
Expand Down
1 change: 1 addition & 0 deletions llvm/tools/llvm-readobj/Opts.td
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def file_header : FF<"file-header", "Display file header">;
def headers : FF<"headers", "Equivalent to setting: --file-header, --program-headers, --section-headers">;
defm hex_dump : Eq<"hex-dump", "Display the specified section(s) as hexadecimal bytes">, MetaVarName<"<name or index>">;
def pretty_print : FF<"pretty-print", "Pretty print JSON output">;
def offloading : FF<"offloading", "Display the content of the offloading section">;
def relocs : FF<"relocs", "Display the relocation entries in the file">;
def section_data : FF<"section-data", "Display section data for each section shown. This option has no effect for GNU style output">;
def section_details : FF<"section-details", "Display the section details">;
Expand Down
5 changes: 5 additions & 0 deletions llvm/tools/llvm-readobj/llvm-readobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ static bool Notes;
static bool ProgramHeaders;
static bool SectionGroups;
static bool VersionInfo;
static bool Offloading;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this list is the wrong list to add this option, as it's the ELF-specific ones (according to the comment). It should be the list above (and in alphabetical order).


// Mach-O specific options.
static bool MachODataInCode;
Expand Down Expand Up @@ -288,6 +289,7 @@ static void parseOptions(const opt::InputArgList &Args) {
}
}
opts::VersionInfo = Args.hasArg(OPT_version_info);
opts::Offloading = Args.hasArg(OPT_offloading);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: These options are set in alphabetical order.


// Mach-O specific options.
opts::MachODataInCode = Args.hasArg(OPT_macho_data_in_code);
Expand Down Expand Up @@ -455,6 +457,8 @@ static void dumpObject(ObjectFile &Obj, ScopedPrinter &Writer,
Dumper->printGnuHashTable();
if (opts::VersionInfo)
Dumper->printVersionInfo();
if (opts::Offloading)
Dumper->printOffloading(Obj);
if (opts::StringTable)
Dumper->printStringTable();
if (Obj.isELF()) {
Expand Down Expand Up @@ -699,6 +703,7 @@ int llvm_readobj_main(int argc, char **argv, const llvm::ToolContext &) {
opts::DynamicTable = true;
opts::Notes = true;
opts::VersionInfo = true;
opts::Offloading = true;
opts::UnwindInfo = true;
opts::SectionGroups = true;
opts::HashHistogram = true;
Expand Down