Skip to content

Commit a2e93dc

Browse files
quic-aregc-rhodes
authored andcommitted
[Hexagon][llvm-objdump] Start a fresh packet at symbol boundaries. (llvm#163466)
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 encountering a new symbol so that packets at symbol starts are guaranteed to start in their own packet. (cherry picked from commit 0cdebda)
1 parent dfdee9a commit a2e93dc

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
@@ -64,6 +64,10 @@ class HexagonDisassembler : public MCDisassembler {
6464

6565
void remapInstruction(MCInst &Instr) const;
6666

67+
Expected<bool> onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size,
68+
ArrayRef<uint8_t> Bytes,
69+
uint64_t Address) const override;
70+
6771
private:
6872
bool makeBundle(ArrayRef<uint8_t> Bytes, uint64_t Address,
6973
uint64_t &BytesToSkip, raw_ostream &CS) const;
@@ -604,6 +608,18 @@ DecodeStatus HexagonDisassembler::getSingleInstruction(MCInst &MI, MCInst &MCB,
604608
return Result;
605609
}
606610

611+
Expected<bool> HexagonDisassembler::onSymbolStart(SymbolInfoTy &Symbol,
612+
uint64_t &Size,
613+
ArrayRef<uint8_t> Bytes,
614+
uint64_t Address) const {
615+
// At the start of a symbol, force a fresh packet by resetting any
616+
// in-progress bundle state. This prevents packets from straddling label
617+
// boundaries when data (e.g. jump tables) appears in between.
618+
Size = 0;
619+
resetBundle();
620+
return true;
621+
}
622+
607623
static DecodeStatus DecodeRegisterClass(MCInst &Inst, unsigned RegNo,
608624
ArrayRef<MCPhysReg> Table) {
609625
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
@@ -717,11 +717,17 @@ class PrettyPrinter {
717717
} while (!Comments.empty());
718718
FOS.flush();
719719
}
720+
721+
// Hook invoked when starting to disassemble a symbol at the current position.
722+
// Default is no-op.
723+
virtual void onSymbolStart() {}
720724
};
721725
PrettyPrinter PrettyPrinterInst;
722726

723727
class HexagonPrettyPrinter : public PrettyPrinter {
724728
public:
729+
void onSymbolStart() override { reset(); }
730+
725731
void printLead(ArrayRef<uint8_t> Bytes, uint64_t Address,
726732
formatted_raw_ostream &OS) {
727733
if (LeadingAddr)
@@ -2216,6 +2222,8 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
22162222
Start += Size;
22172223
break;
22182224
}
2225+
// Allow targets to reset any per-symbol state.
2226+
DT->Printer->onSymbolStart();
22192227
formatted_raw_ostream FOS(OS);
22202228
Index = Start;
22212229
if (SectionAddr < StartAddress)

0 commit comments

Comments
 (0)