New flag --keep-section <section_name> to prevent certain sections from being linker garbage collected.
Ian Lance Taylor
iant@google.com
Thu Apr 19 22:01:00 GMT 2012
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.
> * 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