[llvm] cb06571 - Avoid dangling reference on SectionList

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 5 00:44:26 PST 2020


Author: serge-sans-paille
Date: 2020-03-05T09:42:24+01:00
New Revision: cb06571a441c36e540808e397881e42bece99a85

URL: https://github.com/llvm/llvm-project/commit/cb06571a441c36e540808e397881e42bece99a85
DIFF: https://github.com/llvm/llvm-project/commit/cb06571a441c36e540808e397881e42bece99a85.diff

LOG: Avoid dangling reference on SectionList

Bug spotted by https://cookieplmonster.github.io/2020/02/01/emulator-bug-llvm-bug/

Basically, holding references to object inside a resized vector is a bad idea.

Differential Revision: https://reviews.llvm.org/D75110

Added: 
    

Modified: 
    llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
index a2f6df32de0c..7cfc491f8fdf 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
@@ -26,6 +26,7 @@
 #include "llvm/Support/Host.h"
 #include "llvm/Support/Mutex.h"
 #include "llvm/Support/SwapByteOrder.h"
+#include <deque>
 #include <map>
 #include <system_error>
 #include <unordered_map>
@@ -251,7 +252,9 @@ class RuntimeDyldImpl {
 
   // A list of all sections emitted by the dynamic linker.  These sections are
   // referenced in the code by means of their index in this list - SectionID.
-  typedef SmallVector<SectionEntry, 64> SectionList;
+  // Because references may be kept while the list grows, use a container that
+  // guarantees reference stability.
+  typedef std::deque<SectionEntry> SectionList;
   SectionList Sections;
 
   typedef unsigned SID; // Type for SectionIDs


        


More information about the llvm-commits mailing list