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
This commit is contained in:
Pete Cooper 2016-03-23 18:00:10 +00:00
parent f20a55fcfd
commit e82f3a099f
1 changed files with 4 additions and 4 deletions

View File

@ -380,11 +380,11 @@ readBinary(std::unique_ptr<MemoryBuffer> &mb,
reinterpret_cast<const nlist_64 *>(start + symOffset); reinterpret_cast<const nlist_64 *>(start + symOffset);
// Convert each nlist_64 to a lld::mach_o::normalized::Symbol. // Convert each nlist_64 to a lld::mach_o::normalized::Symbol.
for(uint32_t i=0; i < symCount; ++i) { for(uint32_t i=0; i < symCount; ++i) {
const nlist_64 *sin = &symbols[i];
nlist_64 tempSym; nlist_64 tempSym;
if (isBig != llvm::sys::IsBigEndianHost) { memcpy(&tempSym, &symbols[i], sizeof(nlist_64));
tempSym = *sin; swapStruct(tempSym); sin = &tempSym; const nlist_64 *sin = &tempSym;
} if (isBig != llvm::sys::IsBigEndianHost)
swapStruct(tempSym);
Symbol sout; Symbol sout;
if (sin->n_strx > strSize) if (sin->n_strx > strSize)
return true; return true;