[Object][ELF] Fix crash on no dynamic section.
authorMichael J. Spencer <bigcheesegs@gmail.com>
Thu, 7 Feb 2013 18:26:45 +0000 (18:26 +0000)
committerMichael J. Spencer <bigcheesegs@gmail.com>
Thu, 7 Feb 2013 18:26:45 +0000 (18:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174639 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/ELF.h
test/Object/readobj.test [new file with mode: 0644]

index a84461020e31c335dd18b08aa140d546d648d836..4a5eebf0266430603534c0fa07f6e7aa2030d1c1 100644 (file)
@@ -513,6 +513,8 @@ public:
       return Tmp;
     }
 
+    const char *get() const { return Current; }
+
   private:
     const uint64_t EntitySize;
     const char *Current;
@@ -2292,7 +2294,7 @@ library_iterator ELFObjectFile<ELFT>::begin_libraries_needed() const {
   }
 
   DataRefImpl DRI;
-  DRI.p = reinterpret_cast<uintptr_t>(&*i);
+  DRI.p = reinterpret_cast<uintptr_t>(i.get());
   return library_iterator(LibraryRef(DRI, this));
 }
 
@@ -2312,7 +2314,7 @@ error_code ELFObjectFile<ELFT>::getLibraryNext(DataRefImpl Data,
     ;
 
   DataRefImpl DRI;
-  DRI.p = reinterpret_cast<uintptr_t>(&*i);
+  DRI.p = reinterpret_cast<uintptr_t>(i.get());
   Result = LibraryRef(DRI, this);
   return object_error::success;
 }
@@ -2343,7 +2345,7 @@ template<class ELFT>
 library_iterator ELFObjectFile<ELFT>::end_libraries_needed() const {
   dyn_iterator e = end_dynamic_table();
   DataRefImpl DRI;
-  DRI.p = reinterpret_cast<uintptr_t>(&*e);
+  DRI.p = reinterpret_cast<uintptr_t>(e.get());
   return library_iterator(LibraryRef(DRI, this));
 }
 
diff --git a/test/Object/readobj.test b/test/Object/readobj.test
new file mode 100644 (file)
index 0000000..e29f404
--- /dev/null
@@ -0,0 +1,2 @@
+// Don't crash while reading non-dynamic files.
+RUN: llvm-readobj %p/Inputs/trivial-object-test.elf-x86-64