+ /* Compress/decompress DWARF debug sections with names: .debug_* and
+ .zdebug_*, after the section flags is set. */
+ if ((flags & SEC_DEBUGGING)
+ && ((name[1] == 'd' && name[6] == '_')
+ || (name[1] == 'z' && name[7] == '_')))
+ {
+ enum { nothing, compress, decompress } action = nothing;
+ char *new_name;
+
+ if (bfd_is_section_compressed (abfd, newsect))
+ {
+ /* Compressed section. Check if we should decompress. */
+ if ((abfd->flags & BFD_DECOMPRESS))
+ action = decompress;
+ }
+ else
+ {
+ /* Normal section. Check if we should compress. */
+ if ((abfd->flags & BFD_COMPRESS))
+ action = compress;
+ }
+
+ new_name = NULL;
+ switch (action)
+ {
+ case nothing:
+ break;
+ case compress:
+ if (!bfd_init_section_compress_status (abfd, newsect))
+ {
+ (*_bfd_error_handler)
+ (_("%B: unable to initialize commpress status for section %s"),
+ abfd, name);
+ return FALSE;
+ }
+ if (name[1] != 'z')
+ {
+ unsigned int len = strlen (name);
+
+ new_name = bfd_alloc (abfd, len + 2);
+ if (new_name == NULL)
+ return FALSE;
+ new_name[0] = '.';
+ new_name[1] = 'z';
+ memcpy (new_name + 2, name + 1, len);
+ }
+ break;
+ case decompress:
+ if (!bfd_init_section_decompress_status (abfd, newsect))
+ {
+ (*_bfd_error_handler)
+ (_("%B: unable to initialize decommpress status for section %s"),
+ abfd, name);
+ return FALSE;
+ }
+ if (name[1] == 'z')
+ {
+ unsigned int len = strlen (name);
+
+ new_name = bfd_alloc (abfd, len);
+ if (new_name == NULL)
+ return FALSE;
+ new_name[0] = '.';
+ memcpy (new_name + 1, name + 2, len - 1);
+ }
+ break;
+ }
+ if (new_name != NULL)
+ bfd_rename_section (abfd, newsect, new_name);
+ }
+