Skip to content

Commit c87edaf

Browse files
quic-akaryakiAlexey Karyakinsvs-quic
authored
[Hexagon][llvm-objdump] Fix crash at a truncated instruction (llvm#142082)
Fixes llvm#141740. Co-authored-by: Alexey Karyakin <[email protected]> Co-authored-by: Sudharsan Veeravalli <[email protected]>
1 parent a236dc6 commit c87edaf

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Test disassembling of truncated instructions.
2+
3+
# RUN: yaml2obj %s -o %t
4+
# RUN: llvm-objdump --disassemble-all %t 2>&1 | FileCheck %s
5+
6+
# CHECK: 0000000 <.data>:
7+
# CHECK-NEXT: 0: 55 <unknown>
8+
9+
--- !ELF
10+
FileHeader:
11+
Class: ELFCLASS32
12+
Data: ELFDATA2LSB
13+
Type: ET_REL
14+
Machine: EM_HEXAGON
15+
Sections:
16+
- Name: .data
17+
Type: SHT_PROGBITS
18+
Flags: [ SHF_ALLOC ]
19+
AddressAlign: 0x1
20+
Content: 55
21+
- Type: SectionHeaderTable
22+
Sections:
23+
- Name: .data
24+
- Name: .strtab
25+
- Name: .shstrtab
26+
...

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -700,14 +700,18 @@ class HexagonPrettyPrinter : public PrettyPrinter {
700700
public:
701701
void printLead(ArrayRef<uint8_t> Bytes, uint64_t Address,
702702
formatted_raw_ostream &OS) {
703-
uint32_t opcode =
704-
(Bytes[3] << 24) | (Bytes[2] << 16) | (Bytes[1] << 8) | Bytes[0];
705703
if (LeadingAddr)
706704
OS << format("%8" PRIx64 ":", Address);
707705
if (ShowRawInsn) {
708706
OS << "\t";
709-
dumpBytes(Bytes.slice(0, 4), OS);
710-
OS << format("\t%08" PRIx32, opcode);
707+
if (Bytes.size() >= 4) {
708+
dumpBytes(Bytes.slice(0, 4), OS);
709+
uint32_t opcode =
710+
(Bytes[3] << 24) | (Bytes[2] << 16) | (Bytes[1] << 8) | Bytes[0];
711+
OS << format("\t%08" PRIx32, opcode);
712+
} else {
713+
dumpBytes(Bytes, OS);
714+
}
711715
}
712716
}
713717
void printInst(MCInstPrinter &IP, const MCInst *MI, ArrayRef<uint8_t> Bytes,

0 commit comments

Comments
 (0)