Skip to content

Add --offoading option to llvm-readobj #143342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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 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
42 changes: 42 additions & 0 deletions llvm/test/tools/llvm-readobj/ELF/AMDGPU/offloading.test

Large diffs are not rendered by default.

13 changes: 13 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,15 @@ void ObjDumper::printSectionsAsHex(const object::ObjectFile &Obj,
}
}

void ObjDumper::printOffloading(const object::ObjectFile &Obj) {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: don't start a function with a blank line.

SmallVector<llvm::object::OffloadBundleFatBin> Bundles;
if (Error Err = object::extractOffloadBundleFatBinary(Obj, Bundles))
reportWarning(std::move(Err), Obj.getFileName());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd still like to see a test that shows this warning is printed when expected.


// 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
2 changes: 2 additions & 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 Expand Up @@ -64,6 +65,7 @@ def notes : FF<"notes", "Display notes">, Group<grp_elf>;
def program_headers : FF<"program-headers", "Display program headers">, Group<grp_elf>;
def version_info : FF<"version-info", "Display version sections">, Group<grp_elf>;


Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: spurious extra line.

// Mach-O specific options.
def grp_mach_o : OptionGroup<"kind">, HelpText<"OPTIONS (Mach-O specific)">;
def macho_data_in_code : FF<"macho-data-in-code", "Display Data in Code command">, Group<grp_mach_o>;
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;

// 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);

// 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