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

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 13:28:57 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-binary-utilities

Author: Thurston Dang (thurstond)

<details>
<summary>Changes</summary>

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.


---
Full diff: https://github.com/llvm/llvm-project/pull/68741.diff


1 Files Affected:

- (modified) llvm/lib/ObjCopy/MachO/MachOReader.cpp (+1-1) 


``````````diff
diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.cpp b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
index 2cbffc12adbf765..9006f9e6d98d951 100644
--- a/llvm/lib/ObjCopy/MachO/MachOReader.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
@@ -67,7 +67,7 @@ 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);

``````````

</details>


https://github.com/llvm/llvm-project/pull/68741


More information about the llvm-commits mailing list