Support objcopy changing compression to or from zstd
authorAlan Modra <amodra@gmail.com>
Tue, 4 Oct 2022 02:44:05 +0000 (13:14 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 4 Oct 2022 08:12:54 +0000 (18:42 +1030)
commit758dd750bc6d752b290aefdd62048ca2ea5899d4
tree3e7808b8069ea87866143d6d29d917a472ad0a5e
parent034235cebd790d4f9a1728043a175d7d7d9338b1
Support objcopy changing compression to or from zstd

Commit 2cac01e3ffff lacked support for objcopy changing compression
style.  Add that support, which meant a rewrite of
bfd_compress_section_contents.  In the process I've fixed some memory
leaks.

* compress.c (bfd_is_section_compressed_info): Rename from
bfd_is_section_compressed_with_header and add ch_type param
to return compression header ch_type field.
Update all callers.
(decompress_section_contents): Remove buffer and size params.
Rewrite.  Update callers.
(bfd_init_section_compress_status): Free contents on failure.
(bfd_compress_section): Likewise.
* elf.c (_bfd_elf_make_section_from_shdr): Support objcopy
changing between any of the three compression schemes.  Report
"unable to compress/decompress" rather than "unable to
initialize compress/decompress status" on compress/decompress
failures.
* bfd-in2.h: Regenerate.
bfd/bfd-in2.h
bfd/compress.c
bfd/elf.c