[lld] 63173d1 - [lld-macho] Fix assert when splitting section

Keith Smiley via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 22 13:19:08 PST 2022


Author: Keith Smiley
Date: 2022-12-22T13:18:47-08:00
New Revision: 63173d11ecb50236e86578574584bd9a86e27387

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

LOG: [lld-macho] Fix assert when splitting section

Fixes https://github.com/llvm/llvm-project/issues/59649

Differential Revision: https://reviews.llvm.org/D140518

Added: 
    

Modified: 
    lld/MachO/InputFiles.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 174ad959c5bcd..49629ab6a9ce0 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -329,14 +329,14 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
                                                     : buf + sec.offset,
                               static_cast<size_t>(sec.size)};
 
-    auto splitRecords = [&](int recordSize) -> void {
+    auto splitRecords = [&](size_t recordSize) -> void {
       if (data.empty())
         return;
       Subsections &subsections = section.subsections;
       subsections.reserve(data.size() / recordSize);
       for (uint64_t off = 0; off < data.size(); off += recordSize) {
         auto *isec = make<ConcatInputSection>(
-            section, data.slice(off, recordSize), align);
+            section, data.slice(off, std::min(data.size(), recordSize)), align);
         subsections.push_back({off, isec});
       }
       section.doneSplitting = true;


        


More information about the llvm-commits mailing list