This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: New flag --keep-section <section_name> to prevent certain sections from being linker garbage collected.
- From: Ian Lance Taylor <iant at google dot com>
- To: Sriraman Tallam <tmsriram at google dot com>
- Cc: binutils <binutils at sourceware dot org>
- Date: Thu, 19 Apr 2012 14:49:32 -0700
- Subject: Re: New flag --keep-section <section_name> to prevent certain sections from being linker garbage collected.
- References: <CAAs8HmwewDcEdmY31qK4iraZbzwgJmngVm3TF55cZnS-c1DuKw@mail.gmail.com>
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