Skip to content
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
16 changes: 16 additions & 0 deletions llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class HexagonDisassembler : public MCDisassembler {

void remapInstruction(MCInst &Instr) const;

Expected<bool> onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size,
ArrayRef<uint8_t> Bytes,
uint64_t Address) const override;

private:
bool makeBundle(ArrayRef<uint8_t> Bytes, uint64_t Address,
uint64_t &BytesToSkip, raw_ostream &CS) const;
Expand Down Expand Up @@ -567,6 +571,18 @@ DecodeStatus HexagonDisassembler::getSingleInstruction(MCInst &MI, MCInst &MCB,
return Result;
}

Expected<bool> HexagonDisassembler::onSymbolStart(SymbolInfoTy &Symbol,
uint64_t &Size,
ArrayRef<uint8_t> Bytes,
uint64_t Address) const {
// At the start of a symbol, force a fresh packet by resetting any
// in-progress bundle state. This prevents packets from straddling label
// boundaries when data (e.g. jump tables) appears in between.
Size = 0;
resetBundle();
return true;
}

static DecodeStatus DecodeRegisterClass(MCInst &Inst, unsigned RegNo,
ArrayRef<MCPhysReg> Table) {
if (RegNo < Table.size()) {
Expand Down
23 changes: 23 additions & 0 deletions llvm/test/tools/llvm-objdump/ELF/Hexagon/packet-reset-on-label.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: llvm-mc -triple=hexagon -mcpu=hexagonv75 -filetype=obj %s \
// RUN: | llvm-objdump -d - \
// RUN: | FileCheck %s

foo:
{ nop }
/// a nop without end-of-packet bits set to simulate data that is
/// not a proper packet end.
.long 0x7f004000
bar:
{ nop
nop
}

// CHECK-LABEL: <foo>:
// CHECK: { nop }
// CHECK-NEXT: { nop

/// The instruction starting after <bar> should start in a new packet.
// CHECK-LABEL: <bar>:
// CHECK: { nop
// CHECK-NEXT: nop }

8 changes: 8 additions & 0 deletions llvm/tools/llvm-objdump/llvm-objdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,11 +728,17 @@ class PrettyPrinter {
} while (!Comments.empty());
FOS.flush();
}

// Hook invoked when starting to disassemble a symbol at the current position.
// Default is no-op.
virtual void onSymbolStart() {}
};
PrettyPrinter PrettyPrinterInst;

class HexagonPrettyPrinter : public PrettyPrinter {
public:
void onSymbolStart() override { reset(); }

void printLead(ArrayRef<uint8_t> Bytes, uint64_t Address,
formatted_raw_ostream &OS) {
if (LeadingAddr)
Expand Down Expand Up @@ -2228,6 +2234,8 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
Start += Size;
break;
}
// Allow targets to reset any per-symbol state.
DT->Printer->onSymbolStart();
formatted_raw_ostream FOS(OS);
Index = Start;
if (SectionAddr < StartAddress)
Expand Down