Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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 using URI syntax.

.. 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 using URI syntax.

.. 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
29 changes: 29 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
Loading