[lld] 91fef00 - [ELF] Catch zlib deflateInit2 error

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed May 1 11:32:09 PDT 2024


Author: Fangrui Song
Date: 2024-05-01T11:32:04-07:00
New Revision: 91fef0013f2668d1dc0623ede21cf4048d9a733e

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

LOG: [ELF] Catch zlib deflateInit2 error

The function may return Z_MEM_ERROR or Z_STREAM_ERR. The former does not
have a good way of testing. The latter will be possible with a pending
change that allows setting the compression level, which will come with a
test.

Added: 
    

Modified: 
    lld/ELF/OutputSections.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 3e58ed4bda2d3c..1b09e5b0a55742 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -301,7 +301,11 @@ static SmallVector<uint8_t, 0> deflateShard(ArrayRef<uint8_t> in, int level,
   // 15 and 8 are default. windowBits=-15 is negative to generate raw deflate
   // data with no zlib header or trailer.
   z_stream s = {};
-  deflateInit2(&s, level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
+  auto res = deflateInit2(&s, level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
+  if (res != 0) {
+    errorOrWarn("--compress-sections: deflateInit2 returned " + Twine(res));
+    return {};
+  }
   s.next_in = const_cast<uint8_t *>(in.data());
   s.avail_in = in.size();
 


        


More information about the llvm-commits mailing list