[llvm] bfa7d10 - [MachO] Fix unaligned load in extractSections (#68741)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 13:48:18 PDT 2023


Author: Thurston Dang
Date: 2023-10-10T13:48:13-07:00
New Revision: bfa7d10b9f1531f6bfca9d08c397347aef4a65b6

URL: https://github.com/llvm/llvm-project/commit/bfa7d10b9f1531f6bfca9d08c397347aef4a65b6
DIFF: https://github.com/llvm/llvm-project/commit/bfa7d10b9f1531f6bfca9d08c397347aef4a65b6.diff

LOG: [MachO] Fix unaligned load in extractSections (#68741)

A recent change to ubsan

(https://github.com/llvm/llvm-project/commit/792674400f6f04a074a3827349ed0e2ac10067f6)
exposed an unaligned load in MachOReader (see
https://lab.llvm.org/buildbot/#/builders/85/builds/19482 for an
example).

This patch fixes it by dropping the alignment.

Added: 
    

Modified: 
    llvm/lib/ObjCopy/MachO/MachOReader.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ObjCopy/MachO/MachOReader.cpp b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
index 2cbffc12adbf765..25f8c020cde94d5 100644
--- a/llvm/lib/ObjCopy/MachO/MachOReader.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
@@ -67,7 +67,8 @@ Expected<std::vector<std::unique_ptr<Section>>> static extractSections(
                                                         LoadCmd.C.cmdsize);
        Curr < End; ++Curr) {
     SectionType Sec;
-    memcpy((void *)&Sec, Curr, sizeof(SectionType));
+    memcpy((void *)&Sec, reinterpret_cast<const char *>(Curr),
+           sizeof(SectionType));
 
     if (MachOObj.isLittleEndian() != sys::IsLittleEndianHost)
       MachO::swapStruct(Sec);


        


More information about the llvm-commits mailing list