[lld] db78ee0 - [lld-macho] Fix address sanitizer for category merging (#91680)

via llvm-commits llvm-commits at lists.llvm.org
Thu May 9 17:56:50 PDT 2024


Author: alx32
Date: 2024-05-09T17:56:46-07:00
New Revision: db78ee0cb82669302a5e0f18a15fd53346a73823

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

LOG: [lld-macho] Fix address sanitizer for category merging (#91680)

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.

Added: 
    

Modified: 
    lld/MachO/ObjC.cpp

Removed: 
    


################################################################################
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);


        


More information about the llvm-commits mailing list