PATCH: Add --compress-debug-sections=[none|zlib|zlib-gnu|zlib-gabi] to ld

H.J. Lu hjl.tools@gmail.com
Mon Apr 13 12:38:00 GMT 2015


On Sun, Apr 12, 2015 at 6:13 PM, Alan Modra <amodra@gmail.com> wrote:
> On Thu, Apr 09, 2015 at 03:07:20PM -0700, H.J. Lu wrote:
>> +  if (arg->link_info
>> +      && (arg->link_info->compress_debug & COMPRESS_DEBUG)
>> +      && arg->link_info->compress_debug != COMPRESS_DEBUG_GABI_ZLIB
>> +      && (asect->flags & SEC_DEBUGGING)
>> +      && name[1] == 'd'
>> +      && name[6] == '_')
>
> Here and in a couple of other places you omit checking the full prefix
> of the name.  Are you certain you won't see something like a ".de"
> section here?  It you might, then name[6] is a buffer overflow and a
> potential segfault.

elf.c has

  if ((flags & SEC_ALLOC) == 0)
    {
      /* The debugging sections appear to be recognized only by name,
         not any sort of flag.  Their SEC_ALLOC bits are cleared.  */
      if (name [0] == '.')
        {
          const char *p;
          int n;
          if (name[1] == 'd')
            p = ".debug", n = 6;
          else if (name[1] == 'g' && name[2] == 'n')
            p = ".gnu.linkonce.wi.", n = 17;
          else if (name[1] == 'g' && name[2] == 'd')
            p = ".gdb_index", n = 11; /* yes we really do mean 11.  */
          else if (name[1] == 'l')
            p = ".line", n = 5;
          else if (name[1] == 's')
            p = ".stab", n = 5;
          else if (name[1] == 'z')
            p = ".zdebug", n = 7;
          else
            p = NULL, n = 0;
          if (p != NULL && strncmp (name, p, n) == 0)
            flags |= SEC_DEBUGGING;
        }
    }

and

 /* 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] == '_')))
    {

When name[1] == 'd'.  It is pretty safe to check name[1] == 'd' &&
name[6] == '_'
when SEC_DEBUGGING is set.

Here is the completed patch.  OK for master?

Thanks.

-- 
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-compress-debug-sections-none-zlib-zlib-gnu-zlib-.patch
Type: text/x-patch
Size: 33704 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20150413/3408b3ff/attachment.bin>


More information about the Binutils mailing list