Skip to content

Commit a1e80ac

Browse files
JestrTulipmtrofin
authored andcommitted
[Object] fixed invalid symbol handling in ELFObjectFile::getSymbolName
Found a bug in ElfObjectFile.h that occurred when there was an invalid Symbol Name in an object file. This error affected the behavior of the Expected<> value and leading it to abort, rather than behave as normal. I found this as I was adding tests to llvm-cm, as prompted by @jhenderson. Without this fix, upon encountering an invalid symbol and trying tot l get its name, the program states that ```Expected<T> must be checked before access or destruction``` and aborts. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D154665
1 parent 875b881 commit a1e80ac

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

llvm/include/llvm/Object/ELFObjectFile.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,10 @@ Expected<StringRef> ELFObjectFile<ELFT>::getSymbolName(DataRefImpl Sym) const {
530530

531531
// If the symbol name is empty use the section name.
532532
if ((*SymOrErr)->getType() == ELF::STT_SECTION) {
533-
if (Expected<section_iterator> SecOrErr = getSymbolSection(Sym)) {
534-
consumeError(Name.takeError());
533+
Expected<section_iterator> SecOrErr = getSymbolSection(Sym);
534+
if (SecOrErr)
535535
return (*SecOrErr)->getName();
536-
}
536+
return SecOrErr.takeError();
537537
}
538538
return Name;
539539
}

llvm/test/tools/llvm-objdump/ELF/section-symbols.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
# CHECK-NEXT: 00000003 R_X86_64_NONE {{$}}
2020
# CHECK-NEXT: 00000004 R_X86_64_NONE {{$}}
2121

22+
## Test that we consume an error in ELFObjectFile<ELFT>::getSectionName when disassembling.
23+
# RUN: llvm-objdump -d --syms %t1 2>&1 | \
24+
# RUN: FileCheck %s -DFILE=%t1 --check-prefix=CHECK-DISAS
25+
# CHECK-DISAS: warning: '[[FILE]]': invalid section index: 67
26+
2227
--- !ELF
2328
FileHeader:
2429
Class: ELFCLASS32

0 commit comments

Comments
 (0)