[lld] r198067 - [PECOFF] Skip empty .drectve sections.

Rui Ueyama ruiu at google.com
Thu Dec 26 19:34:34 PST 2013


Author: ruiu
Date: Thu Dec 26 21:34:34 2013
New Revision: 198067

URL: http://llvm.org/viewvc/llvm-project?rev=198067&view=rev
Log:
[PECOFF] Skip empty .drectve sections.

There are many object files in the standard library who have empty .drective
sections. Parsing the empty string is not wrong but a waste.

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp

Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=198067&r1=198066&r2=198067&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Thu Dec 26 21:34:34 2013
@@ -121,7 +121,7 @@ private:
 
   error_code addRelocationReferenceToAtoms();
   error_code findSection(StringRef name, const coff_section *&result);
-  std::string ArrayRefToString(ArrayRef<uint8_t> array);
+  StringRef ArrayRefToString(ArrayRef<uint8_t> array);
   error_code maybeReadLinkerDirectives();
 
   std::unique_ptr<const llvm::object::COFFObjectFile> _obj;
@@ -131,7 +131,7 @@ private:
   atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
 
   // The contents of .drectve section.
-  std::string _directives;
+  StringRef _directives;
 
   // A map from symbol to its name. All symbols should be in this map except
   // unnamed ones.
@@ -754,7 +754,7 @@ error_code FileCOFF::findSection(StringR
 
 // Convert ArrayRef<uint8_t> to std::string. The array contains a string which
 // may not be terminated by NUL.
-std::string FileCOFF::ArrayRefToString(ArrayRef<uint8_t> array) {
+StringRef FileCOFF::ArrayRefToString(ArrayRef<uint8_t> array) {
   // Skip the UTF-8 byte marker if exists. The contents of .drectve section
   // is, according to the Microsoft PE/COFF spec, encoded as ANSI or UTF-8
   // with the BOM marker.
@@ -773,7 +773,9 @@ std::string FileCOFF::ArrayRefToString(A
   size_t e = array.size();
   while (len < e && array[len] != '\0')
     ++len;
-  return std::string(reinterpret_cast<const char *>(&array[0]), len);
+  std::string *contents = new (_alloc)
+    std::string(reinterpret_cast<const char *>(&array[0]), len);
+  return StringRef(*contents).trim();
 }
 
 // Read .drectve section contents if exists, and store it to _directives.
@@ -785,7 +787,7 @@ error_code FileCOFF::maybeReadLinkerDire
     ArrayRef<uint8_t> contents;
     if (error_code ec = _obj->getSectionContents(section, contents))
       return ec;
-    _directives = std::move(ArrayRefToString(contents));
+    _directives = ArrayRefToString(contents);
   }
   return error_code::success();
 }





More information about the llvm-commits mailing list