Add SHF_GNU_COMPRESSED

H.J. Lu hjl.tools@gmail.com
Tue Jul 20 05:37:00 GMT 2010


On Mon, Jul 19, 2010 at 8:28 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Mon, Jul 19, 2010 at 5:48 PM, Cary Coutant <ccoutant@google.com> wrote:
>>> objcopy.  --compress-debug-sections/--decompress-debug-sections
>>>
>>> works on hjl/gnu-compressed branch:
>>>
>>> [hjl@gnu-6 pr11819]$ ls -l ld-new
>>> -rwxr-xr-x 1 hjl hjl 4524567 Jul 19 15:50 ld-new
>>> [hjl@gnu-6 pr11819]$ ./objcopy --compress-debug-sections ld-new ld.gz
>>> [hjl@gnu-6 pr11819]$ ls -l ld.gz
>>> -rwxrwxr-x 1 hjl hjl 2862047 Jul 19 15:50 ld.gz
>>> [hjl@gnu-6 pr11819]$ ./objcopy --decompress-debug-sections  ld.gz ld-old
>>> [hjl@gnu-6 pr11819]$ cmp ld-new ld-old
>>> [hjl@gnu-6 pr11819]$
>>>
>>> Any comments?
>>
>> Very nice!
>>
>> I do have a few comments:
>>
>> In bfd/compress.c:
>>
>> +  /* Write the zlib header.  In this case, it should be "ZLIB" followed
>> +     by the uncompressed section size, 8 bytes in big-endian order.  */
>> +  memcpy (compressed_buffer, "ZLIB", 4);
>> +  compressed_buffer[4] = uncompressed_size >> 56;
>> +  compressed_buffer[5] = uncompressed_size >> 48;
>> +  compressed_buffer[6] = uncompressed_size >> 40;
>> +  compressed_buffer[7] = uncompressed_size >> 32;
>> +  compressed_buffer[8] = uncompressed_size >> 24;
>> +  compressed_buffer[9] = uncompressed_size >> 16;
>> +  compressed_buffer[10] = uncompressed_size >> 8;
>> +  compressed_buffer[11] = uncompressed_size;
>> +  compressed_size += 12;
>>
>> It was pointed out to me when I submitted the assembler patch that
>> this is going to produce warnings on 32-bit hosts. It's better to
>> shift the value right 8 bits at a time and build the buffer up from
>> right to left:
>>
>>  compressed_buffer[11] = uncompressed_size; uncompressed_size >>= 8;
>>  compressed_buffer[10] = uncompressed_size; uncompressed_size >>= 8;
>>
>> (See compress_debug() in gas/write.c.)
>>
>
> I will fix it.
>
>> +FUNCTION
>> +       bfd_init_section_decommpress_status
>> +
>> +SYNOPSIS
>> +       bfd_boolean bfd_init_section_decommpress_status
>> +         (bfd *abfd, asection *section);
>>
>> 1,$s/decommpress/decompress/g
>
> I will fix it.
>
>> In bfd/libbfd.c:
>>
>> +  if (section->decompress_status)
>>
>> Compare to DECOMPRESS_SECTION_NONE; it's not clear here what testing
>> for non-zero means when there are three enumerated values.
>>
>
> I will fix it.
>
> I will update linker to read SHF_GNU_COMPRESSED. Writing will be tricky.
> It will be done later.
>

Hi Cary,

I fixed the issues you raised and added linker read support. Linker write
has some problems mainly because string merge, which writes merged string
references to disk directly during output. To support --compress-debug-sections,
I may have to generate a temporary uncompressed output first and compress
it like objcopy.



-- 
H.J.



More information about the Binutils mailing list