diff options
author | Pete Cooper <peter_cooper@apple.com> | 2016-03-23 18:00:10 +0000 |
---|---|---|
committer | Pete Cooper <peter_cooper@apple.com> | 2016-03-23 18:00:10 +0000 |
commit | e82f3a099fa5c3b81eca29c4d5d0ce9ae4cdd923 (patch) | |
tree | 0f0ced56f1410a8865ed0d2ca8e0225262287946 | |
parent | f20a55fcfd033e7a171bcdefa7e92fc758975fe4 (diff) | |
download | bcm5719-llvm-e82f3a099fa5c3b81eca29c4d5d0ce9ae4cdd923.tar.gz bcm5719-llvm-e82f3a099fa5c3b81eca29c4d5d0ce9ae4cdd923.zip |
Copy MachO struct to temporary to avoid unaligned load UB.
We were already copying this data to a temporary for endian swaps. Now
we just always copy it, but still only do the endian swaps when needed.
llvm-svn: 264172
-rw-r--r-- | lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp index 7a9dd4b7fb9..39860bbbdfa 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp @@ -380,11 +380,11 @@ readBinary(std::unique_ptr<MemoryBuffer> &mb, reinterpret_cast<const nlist_64 *>(start + symOffset); // Convert each nlist_64 to a lld::mach_o::normalized::Symbol. for(uint32_t i=0; i < symCount; ++i) { - const nlist_64 *sin = &symbols[i]; nlist_64 tempSym; - if (isBig != llvm::sys::IsBigEndianHost) { - tempSym = *sin; swapStruct(tempSym); sin = &tempSym; - } + memcpy(&tempSym, &symbols[i], sizeof(nlist_64)); + const nlist_64 *sin = &tempSym; + if (isBig != llvm::sys::IsBigEndianHost) + swapStruct(tempSym); Symbol sout; if (sin->n_strx > strSize) return true; |