[llvm] [MachO] Fix unaligned load in extractSections (PR #68741)
Thurston Dang via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 10 13:27:52 PDT 2023
https://github.com/thurstond created https://github.com/llvm/llvm-project/pull/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.
>From b37687344d667b0ac71f7d80e19c48e0629fc221 Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Tue, 10 Oct 2023 20:08:04 +0000
Subject: [PATCH] [MachO] Fix unaligned load in extractSections
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.
---
llvm/lib/ObjCopy/MachO/MachOReader.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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);
More information about the llvm-commits
mailing list