diff options
Diffstat (limited to 'gas/write.c')
-rw-r--r-- | gas/write.c | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/gas/write.c b/gas/write.c index 1ae47a9..bc76962 100644 --- a/gas/write.c +++ b/gas/write.c @@ -1413,6 +1413,9 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED) struct z_stream_s *strm; int x; flagword flags = bfd_get_section_flags (abfd, sec); + unsigned int header_size, compression_header_size; + /* Maximimum compression header is 24 bytes. */ + bfd_byte compression_header[24]; if (seginfo == NULL || sec->size < 32 @@ -1427,18 +1430,26 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED) if (strm == NULL) return; + if (flag_compress_debug == COMPRESS_DEBUG_GABI_ZLIB) + stdoutput->flags |= BFD_COMPRESS | BFD_COMPRESS_GABI; + else + stdoutput->flags |= BFD_COMPRESS; + compression_header_size + = bfd_get_compression_header_size (stdoutput, NULL); + /* Create a new frag to contain the "ZLIB" header. */ + header_size = 12 + compression_header_size; first_newf = frag_alloc (ob); - if (obstack_room (ob) < 12) + if (obstack_room (ob) < header_size) first_newf = frag_alloc (ob); - if (obstack_room (ob) < 12) - as_fatal (_("can't extend frag %u chars"), 12); + if (obstack_room (ob) < header_size) + as_fatal (_("can't extend frag %u chars"), header_size); last_newf = first_newf; - obstack_blank_fast (ob, 12); + obstack_blank_fast (ob, header_size); last_newf->fr_type = rs_fill; - last_newf->fr_fix = 12; + last_newf->fr_fix = header_size; header = last_newf->fr_literal; - compressed_size = 12; + compressed_size = header_size; /* Stream the frags through the compression engine, adding new frags as necessary to accomodate the compressed output. */ @@ -1522,21 +1533,27 @@ compress_debug (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED) if (compressed_size >= uncompressed_size) return; - memcpy (header, "ZLIB", 4); - bfd_putb64 (uncompressed_size, header + 4); + if (compression_header_size) + memcpy (header, compression_header, compression_header_size); + memcpy (header + compression_header_size, "ZLIB", 4); + bfd_putb64 (uncompressed_size, header + compression_header_size + 4); /* Replace the uncompressed frag list with the compressed frag list. */ seginfo->frchainP->frch_root = first_newf; seginfo->frchainP->frch_last = last_newf; /* Update the section size and its name. */ + bfd_update_compression_header (abfd, (bfd_byte *) header, sec); x = bfd_set_section_size (abfd, sec, compressed_size); gas_assert (x); - compressed_name = (char *) xmalloc (strlen (section_name) + 2); - compressed_name[0] = '.'; - compressed_name[1] = 'z'; - strcpy (compressed_name + 2, section_name + 1); - bfd_section_name (stdoutput, sec) = compressed_name; + if (!compression_header_size) + { + compressed_name = (char *) xmalloc (strlen (section_name) + 2); + compressed_name[0] = '.'; + compressed_name[1] = 'z'; + strcpy (compressed_name + 2, section_name + 1); + bfd_section_name (stdoutput, sec) = compressed_name; + } } static void |