[llvm] r270797 - llvm-dwp: Ensure uncompressed sections are not relocated during processing of later inputs

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Wed May 25 16:37:08 PDT 2016


Author: dblaikie
Date: Wed May 25 18:37:06 2016
New Revision: 270797

URL: http://llvm.org/viewvc/llvm-project?rev=270797&view=rev
Log:
llvm-dwp: Ensure uncompressed sections are not relocated during processing of later inputs

Richard Smith identified this in post commit review of r270466. The
string sections in particular (in the future, possibly all sections - so
I'm not going to bother pulling out just the string sections for the
extra lifetime handling right now) need to remain valid during
processing of all inputs so that elements of the DWPStringPool can be
looked up repeatedly without having to make in-memory copies of string
contents in the noncompressed case (more common in dwp+dwp merge steps
where the memory is a bigger problem because the files are larger).

Using the SmallVector (or any vector) a reallocation on push_back could
cause any of the nested SmallStrings in small mode to move in memory and
invalid pointers to their contents. Using a deque the SmallStrings will
never move around since no elements are removed from the container.

Modified:
    llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp

Modified: llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp?rev=270797&r1=270796&r2=270797&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp (original)
+++ llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp Wed May 25 18:37:06 2016
@@ -39,6 +39,7 @@
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
+#include <deque>
 #include <iostream>
 #include <memory>
 
@@ -360,7 +361,7 @@ std::string buildDWODescription(StringRe
 }
 
 static Error handleCompressedSection(
-    SmallVector<SmallString<32>, 4> &UncompressedSections, StringRef &Name,
+    std::deque<SmallString<32>> &UncompressedSections, StringRef &Name,
     StringRef &Contents) {
   if (!Name.startswith("zdebug_"))
     return Error();
@@ -384,7 +385,7 @@ static Error handleSection(
     const MCSection *StrSection, const MCSection *StrOffsetSection,
     const MCSection *TypesSection, const MCSection *CUIndexSection,
     const MCSection *TUIndexSection, const SectionRef &Section, MCStreamer &Out,
-    SmallVector<SmallString<32>, 4> &UncompressedSections,
+    std::deque<SmallString<32>> &UncompressedSections,
     uint32_t (&ContributionOffsets)[8], UnitIndexEntry &CurEntry,
     StringRef &CurStrSection, StringRef &CurStrOffsetSection,
     std::vector<StringRef> &CurTypesSection, StringRef &InfoSection,
@@ -489,7 +490,7 @@ static Error write(MCStreamer &Out, Arra
   SmallVector<OwningBinary<object::ObjectFile>, 128> Objects;
   Objects.reserve(Inputs.size());
 
-  SmallVector<SmallString<32>, 4> UncompressedSections;
+  std::deque<SmallString<32>> UncompressedSections;
 
   for (const auto &Input : Inputs) {
     auto ErrOrObj = object::ObjectFile::createObjectFile(Input);




More information about the llvm-commits mailing list