New flag --keep-section <section_name> to prevent certain sections from being linker garbage collected.

Sriraman Tallam tmsriram@google.com
Thu Apr 19 23:34:00 GMT 2012


Hi Ian,

On Thu, Apr 19, 2012 at 2:49 PM, Ian Lance Taylor <iant@google.com> wrote:
> Sriraman Tallam <tmsriram@google.com> writes:
>
>>   This patch adds a new flag, --keep-section to allow specifying
>> section names that should not be gc'ed.
>>
>>   For use cases, as an example,  a statically linked executable with
>> pthreads needs .rodata.nptl_version to be debuggable with gdb but
>> --gc-sections simply discards it. With this option,
>> --keep-section,.rodata.nptl_version will solve the problem. The
>> -u,<symbolname> does not work if the symbol is local.
>
> I don't mind the patch, but where does .rodata.nptl_version come from?
> From the name it seems like this is something that the linker should
> handle automatically, rather than requiring a command line option.

It comes from libpthread.a when linking statically. For GNU ld, this
requirement can be placed in the linker script. For gold, I could hard
code the name in "is_section_name_included" function. Do you prefer
that?  Right now, to include symbols that are discarded by gc, we can
get away by using -u <symbol>. However, for local symbols this is a
problem which is the case with .rodata.nptl_version.

Thanks,
-Sri.

>
>
>>       * options.h (--keep-section): New option.
>>       * object.cc (Relobj::is_section_name_included): Return true
>>       if section name matches any section specified with --keep-section.
>>       * testsuite/Makefile.am (gc_keep_section_test): New test.
>>       * testsuite/Makefile.in: Regenerate.
>>       * testsuite/gc_keep_section_test.cc: New file.
>>       * testsuite/gc_keep_section_test.sh: New file.
>
>
>> +  // Keep all section names mentioned with option --keep-section.
>> +  for (options::String_set::const_iterator p
>> +      = parameters->options().keep_section_begin();
>> +       p != parameters->options().keep_section_end();
>> +       ++p)
>> +    {
>> +      const char* section_name = p->c_str();
>> +      if (strcmp (name, section_name) == 0)
>> +     return true;
>> +    }
>
> Just write
>    if (*p == name)
>      return true;
>
> The patch is OK with that change, if you still want to commit it.
>
> Thanks.
>
> Ian



More information about the Binutils mailing list