[lld] [lld-macho] Fix address sanitizer for category merging (PR #91680)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 9 16:46:26 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lld-macho
Author: None (alx32)
<details>
<summary>Changes</summary>
FIxing the address sanitizer issue reported in https://github.com/llvm/llvm-project/pull/91548 .
The problem comes from the assignment `auto bodyData = newSectionData` which defaults to `SmallVector<uint8_t> data = newSectionData` - which actually creates a copy of the data, placed on the stack.
By explicitly using `ArrayRef` instead, we make sure that the original copy is used.
We also change the assignment in `ObjcCategoryMerger::newStringData` from `auto` to `SmallVector<uint8_t> &` to make it explicit.
---
Full diff: https://github.com/llvm/llvm-project/pull/91680.diff
1 Files Affected:
- (modified) lld/MachO/ObjC.cpp (+2-2)
``````````diff
diff --git a/lld/MachO/ObjC.cpp b/lld/MachO/ObjC.cpp
index 96ec646095be8..9d1612beae872 100644
--- a/lld/MachO/ObjC.cpp
+++ b/lld/MachO/ObjC.cpp
@@ -1148,7 +1148,7 @@ void ObjcCategoryMerger::generateCatListForNonErasedCategories(
assert(nonErasedCatBody && "Failed to relocate non-deleted category");
// Allocate data for the new __objc_catlist slot
- auto bodyData = newSectionData(target->wordSize);
+ llvm::ArrayRef<uint8_t> bodyData = newSectionData(target->wordSize);
// We mark the __objc_catlist slot as belonging to the same file as the
// category
@@ -1279,7 +1279,7 @@ void ObjcCategoryMerger::doCleanup() { generatedSectionData.clear(); }
StringRef ObjcCategoryMerger::newStringData(const char *str) {
uint32_t len = strlen(str);
uint32_t bufSize = len + 1;
- auto &data = newSectionData(bufSize);
+ SmallVector<uint8_t> &data = newSectionData(bufSize);
char *strData = reinterpret_cast<char *>(data.data());
// Copy the string chars and null-terminator
memcpy(strData, str, bufSize);
``````````
</details>
https://github.com/llvm/llvm-project/pull/91680
More information about the llvm-commits
mailing list