diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -230,7 +230,13 @@ }; for (size_t i = 0, n = nList.size(); i < n; ++i) { - const nlist_64 &sym = nList[i]; + nlist_64 sym; + // nlist_64 structs should be 64-bit-aligned according to the C++ language + // spec, but nList (which is mmap'ed from a file) may not be at an aligned + // offset. This memcpy() ensures that we have the correct alignment, but + // it should be optimized away on architectures that support unaligned + // reads. + memcpy(&sym, nList.data() + i, sizeof(nlist_64)); // Undefined symbol if (!sym.n_sect) {