Skip to content

Commit 8994b14

Browse files
committed
[DebugInfo] Fix crash caused by unhandled error.
Summary: This patch helps fix LLVM crash caused by unhandled error. Reviewers: clayborg, aprantl Reviewed By: clayborg Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78924
1 parent 55bcb96 commit 8994b14

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

llvm/lib/DebugInfo/GSYM/ObjectFileTransformer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,12 @@ llvm::Error ObjectFileTransformer::convert(const object::ObjectFile &Obj,
8282
size_t NumBefore = Gsym.getNumFunctionInfos();
8383
for (const object::SymbolRef &Sym : Obj.symbols()) {
8484
Expected<SymbolRef::Type> SymType = Sym.getType();
85+
if (!SymType) {
86+
consumeError(SymType.takeError());
87+
continue;
88+
}
8589
const uint64_t Addr = Sym.getValue();
86-
if (!SymType || SymType.get() != SymbolRef::Type::ST_Function ||
90+
if (SymType.get() != SymbolRef::Type::ST_Function ||
8791
!Gsym.IsValidTextAddress(Addr) || Gsym.hasFunctionInfoForAddress(Addr))
8892
continue;
8993
// Function size for MachO files will be 0
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## This test ensures that LLVM will not crash when converting a Mach-O object
2+
## file with a malformed symbol whose n_sect points to an invalid offset.
3+
4+
# RUN: yaml2obj %s -o %t
5+
# RUN: not llvm-gsymutil --convert %t -o %t.o 2>&1 | FileCheck %s
6+
7+
# CHECK: Loaded 0 functions from symbol table.
8+
9+
--- !mach-o
10+
FileHeader:
11+
magic: 0xFEEDFACF
12+
cputype: 0x01000007
13+
cpusubtype: 0x00000003
14+
filetype: 0x0000000A
15+
ncmds: 1
16+
sizeofcmds: 100
17+
flags: 0x00000000
18+
reserved: 0x00000000
19+
LoadCommands:
20+
- cmd: LC_SYMTAB
21+
cmdsize: 24
22+
symoff: 4096
23+
nsyms: 1
24+
stroff: 4144
25+
strsize: 6
26+
LinkEditData:
27+
NameList:
28+
- n_strx: 2 # _foo
29+
n_type: 0x0e
30+
n_sect: 3 # Points to an invalid offset.
31+
n_desc: 0
32+
n_value: 1234
33+
StringTable:
34+
- ''
35+
- ''
36+
- _foo

0 commit comments

Comments
 (0)