[llvm] r302395 - Hopefully one last commit to fix this patch, addresses string reference

Eric Beckmann via llvm-commits llvm-commits at lists.llvm.org
Sun May 7 18:48:55 PDT 2017


Author: ecbeckmann
Date: Sun May  7 20:48:55 2017
New Revision: 302395

URL: http://llvm.org/viewvc/llvm-project?rev=302395&view=rev
Log:
Hopefully one last commit to fix this patch, addresses string reference
issues.

Modified:
    llvm/trunk/include/llvm/Object/COFF.h
    llvm/trunk/lib/Object/COFFObjectFile.cpp
    llvm/trunk/tools/llvm-readobj/COFFDumper.cpp

Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=302395&r1=302394&r2=302395&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Sun May  7 20:48:55 2017
@@ -22,6 +22,7 @@
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Support/BinaryByteStream.h"
 #include "llvm/Support/COFF.h"
+#include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ErrorOr.h"
@@ -1074,7 +1075,7 @@ public:
   ResourceSectionRef() = default;
   explicit ResourceSectionRef(StringRef Ref) : BBS(Ref, support::little) {}
 
-  ErrorOr<StringRef> getEntryNameString(const coff_resource_dir_entry &Entry);
+  ErrorOr<ArrayRef<UTF16>> getEntryNameString(const coff_resource_dir_entry &Entry);
   ErrorOr<const coff_resource_dir_table &>
   getEntrySubDir(const coff_resource_dir_entry &Entry);
   ErrorOr<const coff_resource_dir_table &> getBaseTable();
@@ -1083,7 +1084,7 @@ private:
   BinaryByteStream BBS;
 
   ErrorOr<const coff_resource_dir_table &> getTableAtOffset(uint32_t Offset);
-  ErrorOr<StringRef> getDirStringAtOffset(uint32_t Offset);
+  ErrorOr<ArrayRef<UTF16>> getDirStringAtOffset(uint32_t Offset);
 };
 
 // Corresponds to `_FPO_DATA` structure in the PE/COFF spec.

Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=302395&r1=302394&r2=302395&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Sun May  7 20:48:55 2017
@@ -21,7 +21,6 @@
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Support/BinaryStreamReader.h"
 #include "llvm/Support/COFF.h"
-#include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -1597,7 +1596,7 @@ std::error_code BaseRelocRef::getRVA(uin
   if (auto EC = errorToErrorCode(X))                                           \
     return EC;
 
-ErrorOr<StringRef> ResourceSectionRef::getDirStringAtOffset(uint32_t Offset) {
+ErrorOr<ArrayRef<UTF16>> ResourceSectionRef::getDirStringAtOffset(uint32_t Offset) {
   BinaryStreamReader Reader = BinaryStreamReader(BBS);
   Reader.setOffset(Offset);
   uint16_t Length;
@@ -1606,13 +1605,10 @@ ErrorOr<StringRef> ResourceSectionRef::g
   // Strings are stored as 2-byte aligned unicode characters but readFixedString
   // assumes byte string, so we double length.
   RETURN_IF_ERROR(Reader.readArray(RawDirString, Length));
-  std::string DirString;
-  if (!llvm::convertUTF16ToUTF8String(RawDirString, DirString))
-    return object_error::parse_failed;
-  return DirString;
+  return RawDirString;
 }
 
-ErrorOr<StringRef>
+ErrorOr<ArrayRef<UTF16>>
 ResourceSectionRef::getEntryNameString(const coff_resource_dir_entry &Entry) {
   return getDirStringAtOffset(Entry.Identifier.getNameOffset());
 }

Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=302395&r1=302394&r2=302395&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Sun May  7 20:48:55 2017
@@ -44,6 +44,7 @@
 #include "llvm/Support/BinaryByteStream.h"
 #include "llvm/Support/BinaryStreamReader.h"
 #include "llvm/Support/COFF.h"
+#include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/DataExtractor.h"
@@ -1560,9 +1561,12 @@ void COFFDumper::printResourceDirectoryT
     SmallString<20> IDStr;
     raw_svector_ostream OS(IDStr);
     if (i < Table.NumberOfNameEntries) {
-      StringRef EntryNameString = unwrapOrError(RSF.getEntryNameString(Entry));
+      ArrayRef<UTF16> RawEntryNameString = unwrapOrError(RSF.getEntryNameString(Entry));
+      std::string EntryNameString;
+      if (!llvm::convertUTF16ToUTF8String(RawEntryNameString, EntryNameString))
+        error(object_error::parse_failed);
       OS << ": ";
-      OS << EntryNameString.str();
+      OS << EntryNameString;
     } else {
       if (Level == "Type") {
         ScopedPrinter Printer(OS);




More information about the llvm-commits mailing list