[PATCH] [PR binutils/15350] Fix compressed debug sections for PE targets

Hannes Domani via binutils binutils@sourceware.org
Fri Dec 27 18:48:00 GMT 2019


When objcopy --compress-debug-sections was used, it actually did the
compression, but the zlib header was not written, so the resulting debug info
was invalid.

bfd/ChangeLog:

2019-12-27  Hannes Domani  <ssbssa@yahoo.de>

	* bfd.c (bfd_update_compression_header):
	Write zlib header for compressed debug sections of PE files.
---
 bfd/bfd.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/bfd/bfd.c b/bfd/bfd.c
index a3c522cbf8..a935def35f 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -2542,9 +2542,11 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
 {
   if ((abfd->flags & BFD_COMPRESS) != 0)
     {
-      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
+	  || bfd_get_flavour (abfd) == bfd_target_coff_flavour)
 	{
-	  if ((abfd->flags & BFD_COMPRESS_GABI) != 0)
+	  if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
+	      && (abfd->flags & BFD_COMPRESS_GABI) != 0)
 	    {
 	      const struct elf_backend_data *bed
 		= get_elf_backend_data (abfd);
@@ -2579,7 +2581,8 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
 	  else
 	    {
 	      /* Clear the SHF_COMPRESSED bit.  */
-	      elf_section_flags (sec) &= ~SHF_COMPRESSED;
+	      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+		elf_section_flags (sec) &= ~SHF_COMPRESSED;
 
 	      /* Write the zlib header.  It should be "ZLIB" followed by
 		 the uncompressed section size, 8 bytes in big-endian
-- 
2.24.1



More information about the Binutils mailing list