aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2019-12-29 12:41:12 +1030
committerAlan Modra <amodra@gmail.com>2019-12-29 21:25:39 +1030
commita6e5765ff1c5fdebaf4953eed619a717178cc7e6 (patch)
tree168261734dfa6a6f1e32b0adcf7bd1344e611f7e /bfd
parent25d8195c020adf3f8ffc6c811df3d8cbbc09a4bd (diff)
downloadgdb-a6e5765ff1c5fdebaf4953eed619a717178cc7e6.zip
gdb-a6e5765ff1c5fdebaf4953eed619a717178cc7e6.tar.gz
gdb-a6e5765ff1c5fdebaf4953eed619a717178cc7e6.tar.bz2
PR15350, Fix compressed debug sections for PE targets
PR 15350 * bfd.c (bfd_update_compression_header): Write zlib header for formats other than ELF too.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog7
-rw-r--r--bfd/bfd.c84
2 files changed, 48 insertions, 43 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 838d9ee..af2ddfa 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+2019-12-29 Hannes Domani <ssbssa@yahoo.de>
+ Alan Modra <amodra@gmail.com>
+
+ PR 15350
+ * bfd.c (bfd_update_compression_header): Write zlib header for
+ formats other than ELF too.
+
2019-12-26 Alan Modra <amodra@gmail.com>
* som.c (setup_sections): Don't overflow space_strings_size. Use
diff --git a/bfd/bfd.c b/bfd/bfd.c
index a3c522c..b6821fa 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -2540,59 +2540,57 @@ void
bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
asection *sec)
{
- if ((abfd->flags & BFD_COMPRESS) != 0)
+ if ((abfd->flags & BFD_COMPRESS) == 0)
+ abort ();
+
+ switch (bfd_get_flavour (abfd))
{
- if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+ case bfd_target_elf_flavour:
+ if ((abfd->flags & BFD_COMPRESS_GABI) != 0)
{
- if ((abfd->flags & BFD_COMPRESS_GABI) != 0)
- {
- const struct elf_backend_data *bed
- = get_elf_backend_data (abfd);
+ const struct elf_backend_data *bed = get_elf_backend_data (abfd);
- /* Set the SHF_COMPRESSED bit. */
- elf_section_flags (sec) |= SHF_COMPRESSED;
+ /* Set the SHF_COMPRESSED bit. */
+ elf_section_flags (sec) |= SHF_COMPRESSED;
- if (bed->s->elfclass == ELFCLASS32)
- {
- Elf32_External_Chdr *echdr
- = (Elf32_External_Chdr *) contents;
- bfd_put_32 (abfd, ELFCOMPRESS_ZLIB, &echdr->ch_type);
- bfd_put_32 (abfd, sec->size, &echdr->ch_size);
- bfd_put_32 (abfd, 1 << sec->alignment_power,
- &echdr->ch_addralign);
- /* bfd_log2 (alignof (Elf32_Chdr)) */
- bfd_set_section_alignment (sec, 2);
- }
- else
- {
- Elf64_External_Chdr *echdr
- = (Elf64_External_Chdr *) contents;
- bfd_put_32 (abfd, ELFCOMPRESS_ZLIB, &echdr->ch_type);
- bfd_put_32 (abfd, 0, &echdr->ch_reserved);
- bfd_put_64 (abfd, sec->size, &echdr->ch_size);
- bfd_put_64 (abfd, 1 << sec->alignment_power,
- &echdr->ch_addralign);
- /* bfd_log2 (alignof (Elf64_Chdr)) */
- bfd_set_section_alignment (sec, 3);
- }
+ if (bed->s->elfclass == ELFCLASS32)
+ {
+ Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) contents;
+ bfd_put_32 (abfd, ELFCOMPRESS_ZLIB, &echdr->ch_type);
+ bfd_put_32 (abfd, sec->size, &echdr->ch_size);
+ bfd_put_32 (abfd, 1 << sec->alignment_power,
+ &echdr->ch_addralign);
+ /* bfd_log2 (alignof (Elf32_Chdr)) */
+ bfd_set_section_alignment (sec, 2);
}
else
{
- /* Clear the SHF_COMPRESSED bit. */
- 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
- order. */
- memcpy (contents, "ZLIB", 4);
- bfd_putb64 (sec->size, contents + 4);
- /* No way to keep the original alignment, just use 1 always. */
- bfd_set_section_alignment (sec, 0);
+ Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) contents;
+ bfd_put_32 (abfd, ELFCOMPRESS_ZLIB, &echdr->ch_type);
+ bfd_put_32 (abfd, 0, &echdr->ch_reserved);
+ bfd_put_64 (abfd, sec->size, &echdr->ch_size);
+ bfd_put_64 (abfd, 1 << sec->alignment_power,
+ &echdr->ch_addralign);
+ /* bfd_log2 (alignof (Elf64_Chdr)) */
+ bfd_set_section_alignment (sec, 3);
}
+ break;
}
+
+ /* Clear the SHF_COMPRESSED bit. */
+ elf_section_flags (sec) &= ~SHF_COMPRESSED;
+ /* Fall through. */
+
+ default:
+ /* Write the zlib header. It should be "ZLIB" followed by
+ the uncompressed section size, 8 bytes in big-endian
+ order. */
+ memcpy (contents, "ZLIB", 4);
+ bfd_putb64 (sec->size, contents + 4);
+ /* No way to keep the original alignment, just use 1 always. */
+ bfd_set_section_alignment (sec, 0);
+ break;
}
- else
- abort ();
}
/*