[PATCH] D33014: Fix the Endianness bug by adding the little endian UTF marker.
Eric Beckmann via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 9 12:12:37 PDT 2017
ecbeckmann updated this revision to Diff 98337.
ecbeckmann added a comment.
Check endianness of system before adding marker.
https://reviews.llvm.org/D33014
Files:
llvm/lib/Object/COFFObjectFile.cpp
llvm/tools/llvm-readobj/COFFDumper.cpp
Index: llvm/tools/llvm-readobj/COFFDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/COFFDumper.cpp
+++ llvm/tools/llvm-readobj/COFFDumper.cpp
@@ -1562,6 +1562,14 @@
raw_svector_ostream OS(IDStr);
if (i < Table.NumberOfNameEntries) {
ArrayRef<UTF16> RawEntryNameString = unwrapOrError(RSF.getEntryNameString(Entry));
+ std::vector<UTF16> EndianCorrectedNameString;
+ if (llvm::sys::IsBigEndianHost) {
+ EndianCorrectedNameString.resize(RawEntryNameString.size() + 1);
+ std::copy(RawEntryNameString.begin(), RawEntryNameString.end(),
+ EndianCorrectedNameString.begin() + 1);
+ EndianCorrectedNameString[0] = UNI_UTF16_BYTE_ORDER_MARK_SWAPPED;
+ RawEntryNameString = makeArrayRef(EndianCorrectedNameString);
+ }
std::string EntryNameString;
if (!llvm::convertUTF16ToUTF8String(RawEntryNameString, EntryNameString))
error(object_error::parse_failed);
Index: llvm/lib/Object/COFFObjectFile.cpp
===================================================================
--- llvm/lib/Object/COFFObjectFile.cpp
+++ llvm/lib/Object/COFFObjectFile.cpp
@@ -1602,8 +1602,6 @@
uint16_t Length;
RETURN_IF_ERROR(Reader.readInteger(Length));
ArrayRef<UTF16> RawDirString;
- // 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));
return RawDirString;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33014.98337.patch
Type: text/x-patch
Size: 1535 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170509/837368e7/attachment.bin>
More information about the llvm-commits
mailing list