================
@@ -70,23 +59,18 @@ Error extractOffloadFiles(MemoryBufferRef Contents,
       return HeaderOrErr.takeError();
     const OffloadBinary::Header *Header = *HeaderOrErr;
 
-    // Create a copy of original memory containing only the current binary.
-    std::unique_ptr<MemoryBuffer> BufferCopy = MemoryBuffer::getMemBufferCopy(
-        Buffer->getBuffer().take_front(Header->Size),
-        Contents.getBufferIdentifier());
-
-    auto BinariesOrErr = OffloadBinary::create(*BufferCopy);
+    MemoryBufferRef Slice(Buffer->getBuffer().take_front(Header->Size),
+                          Contents.getBufferIdentifier());
+    auto BinariesOrErr = OffloadBinary::create(Slice);
     if (!BinariesOrErr)
       return BinariesOrErr.takeError();
 
-    // Share ownership among multiple OffloadFiles.
-    std::shared_ptr<MemoryBuffer> SharedBuffer =
-        std::shared_ptr<MemoryBuffer>(std::move(BufferCopy));
-
     for (auto &Binary : *BinariesOrErr) {
-      std::unique_ptr<SharedMemoryBuffer> SharedBufferPtr =
-          std::make_unique<SharedMemoryBuffer>(SharedBuffer);
-      Binaries.emplace_back(std::move(Binary), std::move(SharedBufferPtr));
+      std::unique_ptr<MemoryBuffer> View = MemoryBuffer::getMemBuffer(
+          Binary->getMemoryBufferRef().getBuffer(),
+          Binary->getMemoryBufferRef().getBufferIdentifier(),
+          /*RequiresNullTerminator=*/false);
+      Binaries.emplace_back(std::move(Binary), std::move(View));
     }
 
     Offset += Header->Size;
----------------
yxsamliu wrote:

Compressed binaries are not always 8-byte sized. When the linker combines 
multiple  sections, it may add padding before the next binary. The reader 
currently does not skip this padding, so it can fail to find the next header. 
Could we align  before reading the next binary and add a test that links two 
compressed sections?

https://github.com/llvm/llvm-project/pull/222774
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to