Skip to content

Commit 24f0b6b

Browse files
author
Sjoerd Meijer
committed
[llvm-objdump] avoid crash disassembling unknown instruction
Disassembly of instructions can fail when llvm-objdump is not given the right set of architecture features, for example when the source is compiled with: clang -march=..+ext1+ext2 and disassembly is attempted with: llvm-objdump -mattr=+ext1 This patch avoids further analysing unknown instructions (as was happening before) when disassembly has failed. Differential Revision: https://reviews.llvm.org/D73531
1 parent 09217b6 commit 24f0b6b

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# RUN: yaml2obj %s -o %t
2+
# RUN: llvm-objdump -D -triple=thumbv8.1m.main-none-eabi %t | FileCheck %s
3+
4+
## This is a test case with "random" data/instructions, checking that
5+
## llvm-objdump handles such instructions cleanly. Disassembly of instructions
6+
## can fail when it e.g. is not given the right set of architecture features,
7+
## for example when the source is compiled with:
8+
##
9+
## clang -march=..+ext1+ext2
10+
##
11+
## and disassembly is attempted with:
12+
##
13+
## llvm-objdump -mattr=+ext1
14+
15+
# CHECK: 00000000 .text:
16+
# CHECK-NEXT: 0: cb <unknown>
17+
# CHECK-NEXT: 1: f3 f7 8b be b.w #-49898
18+
19+
--- !ELF
20+
FileHeader:
21+
Class: ELFCLASS32
22+
Data: ELFDATA2LSB
23+
Type: ET_REL
24+
Machine: EM_ARM
25+
Sections:
26+
- Name: .text
27+
Type: SHT_PROGBITS
28+
Content: "cbf3f78bbe"

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,14 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
14311431
outs() << CommentStream.str();
14321432
Comments.clear();
14331433

1434+
// If disassembly has failed, continue with the next instruction, to
1435+
// avoid analysing invalid/incomplete instruction information.
1436+
if (!Disassembled) {
1437+
outs() << "\n";
1438+
Index += Size;
1439+
continue;
1440+
}
1441+
14341442
// Try to resolve the target of a call, tail call, etc. to a specific
14351443
// symbol.
14361444
if (MIA && (MIA->isCall(Inst) || MIA->isUnconditionalBranch(Inst) ||

0 commit comments

Comments
 (0)