Skip to content

[AMDGPU] Add disassembler diagnostics for invalid kernel descriptors #87400

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

Merged
merged 7 commits into from
Apr 18, 2024
Merged
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
6 changes: 3 additions & 3 deletions llvm/docs/AMDGPUUsage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4652,7 +4652,7 @@ The fields used by CP for code objects before V3 also match those specified in
entry point instruction
which must be 256 byte
aligned.
351:272 20 Reserved, must be 0.
351:192 20 Reserved, must be 0.
bytes
383:352 4 bytes COMPUTE_PGM_RSRC3 GFX6-GFX9
Reserved, must be 0.
Expand Down Expand Up @@ -5248,14 +5248,14 @@ The fields used by CP for code objects before V3 also match those specified in
5:0 6 bits ACCUM_OFFSET Offset of a first AccVGPR in the unified register file. Granularity 4.
Value 0-63. 0 - accum-offset = 4, 1 - accum-offset = 8, ...,
63 - accum-offset = 256.
6:15 10 Reserved, must be 0.
15:6 10 Reserved, must be 0.
bits
16 1 bit TG_SPLIT - If 0 the waves of a work-group are
launched in the same CU.
- If 1 the waves of a work-group can be
launched in different CUs. The waves
cannot use S_BARRIER or LDS.
17:31 15 Reserved, must be 0.
31:17 15 Reserved, must be 0.
bits
32 **Total size 4 bytes.**
======= ===================================================================================================================
Expand Down
31 changes: 15 additions & 16 deletions llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/XCOFF.h"
#include "llvm/MC/MCDisassembler/MCSymbolizer.h"
#include "llvm/Support/Error.h"
#include <cstdint>
#include <memory>
#include <vector>
Expand Down Expand Up @@ -139,28 +140,26 @@ class MCDisassembler {
/// start of a symbol, or the entire symbol.
/// This is used for example by WebAssembly to decode preludes.
///
/// Base implementation returns std::nullopt. So all targets by default ignore
/// to treat symbols separately.
/// Base implementation returns false. So all targets by default decline to
/// treat symbols separately.
///
/// \param Symbol - The symbol.
/// \param Size - The number of bytes consumed.
/// \param Address - The address, in the memory space of region, of the first
/// byte of the symbol.
/// \param Bytes - A reference to the actual bytes at the symbol location.
/// \param CStream - The stream to print comments and annotations on.
/// \return - MCDisassembler::Success if bytes are decoded
/// successfully. Size must hold the number of bytes that
/// were decoded.
/// - MCDisassembler::Fail if the bytes are invalid. Size
/// must hold the number of bytes that were decoded before
/// failing. The target must print nothing. This can be
/// done by buffering the output if needed.
/// - std::nullopt if the target doesn't want to handle the
/// symbol separately. Value of Size is ignored in this
/// case.
virtual std::optional<DecodeStatus>
onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef<uint8_t> Bytes,
uint64_t Address, raw_ostream &CStream) const;
/// \return - True if this symbol triggered some target specific
/// disassembly for this symbol. Size must be set with the
/// number of bytes consumed.
/// - Error if this symbol triggered some target specific
/// disassembly for this symbol, but an error was found with
/// it. Size must be set with the number of bytes consumed.
/// - False if the target doesn't want to handle the symbol
/// separately. The value of Size is ignored in this case,
/// and Err must not be set.
virtual Expected<bool> onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size,
ArrayRef<uint8_t> Bytes,
uint64_t Address) const;
// TODO:
// Implement similar hooks that can be used at other points during
// disassembly. Something along the following lines:
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/MC/MCDisassembler/MCDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ using namespace llvm;

MCDisassembler::~MCDisassembler() = default;

std::optional<MCDisassembler::DecodeStatus>
MCDisassembler::onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size,
ArrayRef<uint8_t> Bytes, uint64_t Address,
raw_ostream &CStream) const {
return std::nullopt;
Expected<bool> MCDisassembler::onSymbolStart(SymbolInfoTy &Symbol,
uint64_t &Size,
ArrayRef<uint8_t> Bytes,
uint64_t Address) const {
return false;
}

uint64_t MCDisassembler::suggestBytesToSkip(ArrayRef<uint8_t> Bytes,
Expand Down
Loading