[llvm] a1e80ac - [Object] fixed invalid symbol handling in ELFObjectFile::getSymbolName
Mircea Trofin via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 11 17:07:39 PDT 2023
Author: Dayann D'almeida
Date: 2023-07-11T17:07:29-07:00
New Revision: a1e80acc6314066aeb55117127e1939d451bbc71
URL: https://github.com/llvm/llvm-project/commit/a1e80acc6314066aeb55117127e1939d451bbc71
DIFF: https://github.com/llvm/llvm-project/commit/a1e80acc6314066aeb55117127e1939d451bbc71.diff
LOG: [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
Added:
Modified:
llvm/include/llvm/Object/ELFObjectFile.h
llvm/test/tools/llvm-objdump/ELF/section-symbols.test
Removed:
################################################################################
diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h
index 275279597b140a..f3016cc141b0ed 100644
--- a/llvm/include/llvm/Object/ELFObjectFile.h
+++ b/llvm/include/llvm/Object/ELFObjectFile.h
@@ -530,10 +530,10 @@ Expected<StringRef> ELFObjectFile<ELFT>::getSymbolName(DataRefImpl Sym) const {
// If the symbol name is empty use the section name.
if ((*SymOrErr)->getType() == ELF::STT_SECTION) {
- if (Expected<section_iterator> SecOrErr = getSymbolSection(Sym)) {
- consumeError(Name.takeError());
+ Expected<section_iterator> SecOrErr = getSymbolSection(Sym);
+ if (SecOrErr)
return (*SecOrErr)->getName();
- }
+ return SecOrErr.takeError();
}
return Name;
}
diff --git a/llvm/test/tools/llvm-objdump/ELF/section-symbols.test b/llvm/test/tools/llvm-objdump/ELF/section-symbols.test
index 1dc416b38e8b79..ce7ea01a53aaaa 100644
--- a/llvm/test/tools/llvm-objdump/ELF/section-symbols.test
+++ b/llvm/test/tools/llvm-objdump/ELF/section-symbols.test
@@ -19,6 +19,11 @@
# CHECK-NEXT: 00000003 R_X86_64_NONE {{$}}
# CHECK-NEXT: 00000004 R_X86_64_NONE {{$}}
+## Test that we consume an error in ELFObjectFile<ELFT>::getSectionName when disassembling.
+# RUN: llvm-objdump -d --syms %t1 2>&1 | \
+# RUN: FileCheck %s -DFILE=%t1 --check-prefix=CHECK-DISAS
+# CHECK-DISAS: warning: '[[FILE]]': invalid section index: 67
+
--- !ELF
FileHeader:
Class: ELFCLASS32
More information about the llvm-commits
mailing list