[PATCH] D154665: caught bug in ElfObjectFile.h

Dayann D'almeida via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 6 16:04:08 PDT 2023


JestrTulip created this revision.
Herald added a subscriber: emaste.
Herald added a reviewer: jhenderson.
Herald added a reviewer: MaskRay.
Herald added a project: All.
JestrTulip requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154665

Files:
  llvm/include/llvm/Object/ELFObjectFile.h
  llvm/test/tools/llvm-objdump/ELF/section-no-symbol-name.test


Index: llvm/test/tools/llvm-objdump/ELF/section-no-symbol-name.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/ELF/section-no-symbol-name.test
@@ -0,0 +1,18 @@
+# RUN: yaml2obj %s -o %t.o
+# RUN: llvm-objdump -d %t.o 2>&1 | FileCheck %s
+
+# CHECK: invalid section index:
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_X86_64
+Sections: 
+  - Name:         .foo
+    Type:         SHT_PROGBITS
+Symbols: 
+  - Name:         ""
+    Index:        0x43
+    Type:         STT_SECTION
\ No newline at end of file
Index: llvm/include/llvm/Object/ELFObjectFile.h
===================================================================
--- llvm/include/llvm/Object/ELFObjectFile.h
+++ llvm/include/llvm/Object/ELFObjectFile.h
@@ -530,10 +530,10 @@
 
   // 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());
+    if (Expected<section_iterator> SecOrErr = getSymbolSection(Sym))
       return (*SecOrErr)->getName();
-    }
+    else
+      return SecOrErr.takeError();
   }
   return Name;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154665.537918.patch
Type: text/x-patch
Size: 1276 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230706/3a50eb9c/attachment.bin>


More information about the llvm-commits mailing list