[PATCH] readelf: support zstd compressed debug sections [PR 29640]

Alan Modra amodra@gmail.com
Fri Oct 14 11:28:41 GMT 2022


So we have a zlib-gabi .debug_info section that increases in size with
zstd, so much so that it's better to leave the section uncompressed.
Things go horribly wrong due to leaving compress_status as
COMPRESS_SECTION_NONE.  The section is read again off disk using the
uncompressed size.  So you get the zlib section again with some
garbage at the end.

Also, if the section is to be left uncompressed, the input
SHF_COMPRESSED flag needs to be reset otherwise it is copied to
output.

I'm not ready to commit this, just thought I'd post the results of a
bit of debugging.

diff --git a/bfd/compress.c b/bfd/compress.c
index 364df14142b..5eef38bd50a 100644
--- a/bfd/compress.c
+++ b/bfd/compress.c
@@ -206,15 +206,15 @@ bfd_compress_section_contents (bfd *abfd, sec_ptr sec)
   if (compressed_size >= uncompressed_size)
     {
       memcpy (buffer, input_buffer, uncompressed_size);
-      sec->compress_status = COMPRESS_SECTION_NONE;
+      elf_section_flags (sec) &= ~SHF_COMPRESSED;
     }
   else
     {
       sec->size = uncompressed_size;
       bfd_update_compression_header (abfd, buffer, sec);
       sec->size = compressed_size;
-      sec->compress_status = COMPRESS_SECTION_DONE;
     }
+  sec->compress_status = COMPRESS_SECTION_DONE;
   sec->contents = buffer;
   free (input_buffer);
   return uncompressed_size;

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list