[PATCH] D154665: fixed invalid symbol handling in ELFObjectFile::getSymbolName

Dayann D'almeida via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 7 00:07:28 PDT 2023


JestrTulip updated this revision to Diff 538010.
JestrTulip added a comment.

feedback


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154665/new/

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: not llvm-cm %t.o 2>&1 | FileCheck %s
+
+# CHECK: error: failed to get symbol name
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_X86_64
+Sections: 
+  - Name:         .foo
+    Type:         SHT_PROGBITS
+Symbols: 
+  - Name:         ""
+    Index:        0x43  ## Invalid section index
+    Type:         STT_SECTION
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.538010.patch
Type: text/x-patch
Size: 1280 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230707/5bac3a74/attachment.bin>


More information about the llvm-commits mailing list