[PATCH] readelf: support zstd compressed debug sections [PR 29640]
Fangrui Song
maskray@google.com
Sun Oct 16 20:46:52 GMT 2022
On 2022-10-16, Alan Modra wrote:
>On Fri, Oct 14, 2022 at 10:39:17PM +1030, Alan Modra wrote:
>> On Fri, Oct 14, 2022 at 09:58:41PM +1030, Alan Modra wrote:
>> > So we have a zlib-gabi .debug_info section that increases in size with
>> > zstd, so much so that it's better to leave the section uncompressed.
>> > Things go horribly wrong due to leaving compress_status as
>> > COMPRESS_SECTION_NONE. The section is read again off disk using the
>> > uncompressed size. So you get the zlib section again with some
>> > garbage at the end.
>> >
>> > Also, if the section is to be left uncompressed, the input
>> > SHF_COMPRESSED flag needs to be reset otherwise it is copied to
>> > output.
>> >
>> > I'm not ready to commit this, just thought I'd post the results of a
>> > bit of debugging.
>>
>> And if I'd run the testsuite before posting, I may have posted a
>> better patch.. Using COMPRESS_SECTION_DONE led to .debug -> .zdebug
>> renaming of sections, so it appears we want another compress_status
>> that says the final section contents are in sec->contents.
>
>Another compress_status isn't elegant. I'm about to commit this:
>
> * bfd.c (bfd_convert_section_contents): Handle zstd.
> * compress.c (bfd_compress_section_contents): When section
> contents are uncompressed set SEC_IN_MEMORY flag,
> compress_status to COMRESS_SECTION_NONE, and clear
> SHF_COMPRESSED. Set SEC_IN_MEMORY for compressed contents.
> (bfd_get_full_section_contents): Don't check section size
> against file size when SEC_IN_MEMORY.
> (bfd_cache_section_contents): Delete function.
> * elf32-arm.c (elf32_arm_get_synthetic_symtab): Expand
> bfd_cache_section_contents here.
> * bfd-in2.h: Regenerate.
Thanks. Commit 206e9791cb09459bf92603428370c16bfde282ac
fixed the issue.
~/Dev/binutils-gdb/out/debug/binutils/objcopy -O elf32-x86-64 a.o a-x32.o --compress-debug-sections=zstd
~/Dev/binutils-gdb/out/debug/binutils/readelf -wi a-x32.o # good
Is this readelf patch ok for installing?
More information about the Binutils
mailing list