Skip to content

Commit fcf4c6c

Browse files
committed
[Hexagon][llvm-objdump] Start a fresh packet at symbol boundaries.
Hexagon packets can visually straddle labels when data (e.g. jump tables) in the text section does not carry end-of-packet bits. In such cases the next instruction, even at a new symbol, appears to continue the previous packet. This patch resets packet state when encoutering a new symbol so that packets at symbol starts are guaranteed to start in their own packet.
1 parent bd6ed29 commit fcf4c6c

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ class HexagonDisassembler : public MCDisassembler {
6666

6767
void remapInstruction(MCInst &Instr) const;
6868

69+
Expected<bool> onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size,
70+
ArrayRef<uint8_t> Bytes,
71+
uint64_t Address) const override;
72+
6973
private:
7074
bool makeBundle(ArrayRef<uint8_t> Bytes, uint64_t Address,
7175
uint64_t &BytesToSkip, raw_ostream &CS) const;
@@ -567,6 +571,18 @@ DecodeStatus HexagonDisassembler::getSingleInstruction(MCInst &MI, MCInst &MCB,
567571
return Result;
568572
}
569573

574+
Expected<bool> HexagonDisassembler::onSymbolStart(SymbolInfoTy &Symbol,
575+
uint64_t &Size,
576+
ArrayRef<uint8_t> Bytes,
577+
uint64_t Address) const {
578+
// At the start of a symbol, force a fresh packet by resetting any
579+
// in-progress bundle state. This prevents packets from straddling label
580+
// boundaries when data (e.g. jump tables) appears in between.
581+
Size = 0;
582+
resetBundle();
583+
return true;
584+
}
585+
570586
static DecodeStatus DecodeRegisterClass(MCInst &Inst, unsigned RegNo,
571587
ArrayRef<MCPhysReg> Table) {
572588
if (RegNo < Table.size()) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: llvm-mc -triple=hexagon -mcpu=hexagonv75 -filetype=obj %s \
2+
// RUN: | llvm-objdump -d - \
3+
// RUN: | FileCheck %s
4+
5+
foo:
6+
{ nop }
7+
/// a nop without end-of-packet bits set to simulate data that is
8+
/// not a proper packet end.
9+
.long 0x7f004000
10+
bar:
11+
{ nop
12+
nop
13+
}
14+
15+
// CHECK-LABEL: <foo>:
16+
// CHECK: { nop }
17+
// CHECK-NEXT: { nop
18+
19+
/// The instruction starting after <bar> should start in a new packet.
20+
// CHECK-LABEL: <bar>:
21+
// CHECK: { nop
22+
// CHECK-NEXT: nop }
23+

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,11 +728,17 @@ class PrettyPrinter {
728728
} while (!Comments.empty());
729729
FOS.flush();
730730
}
731+
732+
// Hook invoked when starting to disassemble a symbol at the current position.
733+
// Default is no-op.
734+
virtual void onSymbolStart() {}
731735
};
732736
PrettyPrinter PrettyPrinterInst;
733737

734738
class HexagonPrettyPrinter : public PrettyPrinter {
735739
public:
740+
void onSymbolStart() override { reset(); }
741+
736742
void printLead(ArrayRef<uint8_t> Bytes, uint64_t Address,
737743
formatted_raw_ostream &OS) {
738744
if (LeadingAddr)
@@ -2228,6 +2234,8 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
22282234
Start += Size;
22292235
break;
22302236
}
2237+
// Allow targets to reset any per-symbol state.
2238+
DT->Printer->onSymbolStart();
22312239
formatted_raw_ostream FOS(OS);
22322240
Index = Start;
22332241
if (SectionAddr < StartAddress)

0 commit comments

Comments
 (0)