]> granicus.if.org Git - llvm/commitdiff
[Object/ELF] - Make getSymbol() return Error.
authorGeorge Rimar <grimar@accesssoftek.com>
Thu, 3 Nov 2016 08:40:55 +0000 (08:40 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Thu, 3 Nov 2016 08:40:55 +0000 (08:40 +0000)
That is consistent with other methods around
and helps to handle error on a caller side.

Differential revision: https://reviews.llvm.org/D26247

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285886 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/ELF.h
include/llvm/Object/Error.h
lib/Object/Error.cpp

index 71f30ab16dd7da9f2d8d93416ac6da389a0d8701..71e27042af95e2c0143918c5071da458f85434d6 100644 (file)
@@ -158,10 +158,11 @@ public:
                                        ArrayRef<Elf_Word> ShndxTable) const;
   ErrorOr<const Elf_Shdr *> getSection(uint32_t Index) const;
 
-  const Elf_Sym *getSymbol(const Elf_Shdr *Sec, uint32_t Index) const {
+  ErrorOr<const Elf_Sym *> getSymbol(const Elf_Shdr *Sec,
+                                     uint32_t Index) const {
     Elf_Sym_Range Symbols = symbols(Sec);
     if (Index >= Symbols.size())
-      report_fatal_error("Invalid symbol index");
+      return object_error::invalid_symbol_index;
     return &Symbols[Index];
   }
 
index cd55e5dc26d7b2415833572ca3a8df33854983d6..eb938338715d64793dd3eed8e725975c2097869c 100644 (file)
@@ -34,6 +34,7 @@ enum class object_error {
   string_table_non_null_end,
   invalid_section_index,
   bitcode_section_not_found,
+  invalid_symbol_index,
 };
 
 inline std::error_code make_error_code(object_error e) {
index c1dfe673b61ed7f074bd8bb7a63434b6aaa18c8e..578da22c044f8d57fad08bbc776b52c42703474a 100644 (file)
@@ -50,6 +50,8 @@ std::string _object_error_category::message(int EV) const {
     return "Invalid section index";
   case object_error::bitcode_section_not_found:
     return "Bitcode section not found in object file";
+  case object_error::invalid_symbol_index:
+    return "Invalid symbol index";
   }
   llvm_unreachable("An enumerator of object_error does not have a message "
                    "defined.");