Bug 18440 - ICF depends on the section name to detect constructors and destructors
Summary: ICF depends on the section name to detect constructors and destructors
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-21 02:27 UTC by Rafael Ávila de Espíndola
Modified: 2015-05-22 22:58 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rafael Ávila de Espíndola 2015-05-21 02:27:24 UTC
ICF has the following logic

	  // With --icf=safe, check if the mangled function name is a ctor
	  // or a dtor.  The mangled function name can be obtained from the
	  // section name by stripping the section prefix.
	  if (parameters->options().icf_safe_folding()
              && !is_function_ctor_or_dtor(section_name)
	      && (!target.can_check_for_function_pointers()
                  || section_has_function_pointers(*p, i)))
            {
	      continue;
            }

This unfortunately doesn't work if the compiler avoids producing the long section names (as llvm now can).

Is there a convenient pass over the symbols that could be used for this instead?
Comment 1 Sriraman Tallam 2015-05-21 04:09:58 UTC
On Wed, May 20, 2015 at 7:27 PM, rafael.espindola at gmail dot com
<sourceware-bugzilla@sourceware.org> wrote:
> https://sourceware.org/bugzilla/show_bug.cgi?id=18440
>
>             Bug ID: 18440
>            Summary: ICF depends on the section name to detect constructors
>                     and destructors
>            Product: binutils
>            Version: unspecified
>             Status: NEW
>           Severity: normal
>           Priority: P2
>          Component: gold
>           Assignee: ccoutant at gmail dot com
>           Reporter: rafael.espindola at gmail dot com
>                 CC: ian at airs dot com, tmsriram at google dot com
>   Target Milestone: ---
>
> ICF has the following logic
>
>           // With --icf=safe, check if the mangled function name is a ctor
>           // or a dtor.  The mangled function name can be obtained from the
>           // section name by stripping the section prefix.
>           if (parameters->options().icf_safe_folding()
>               && !is_function_ctor_or_dtor(section_name)
>               && (!target.can_check_for_function_pointers()
>                   || section_has_function_pointers(*p, i)))
>             {
>               continue;
>             }
>
> This unfortunately doesn't work if the compiler avoids producing the long
> section names (as llvm now can).

Can we use the symbol name directly?

>
> Is there a convenient pass over the symbols that could be used for this
> instead?
>
> --
> You are receiving this mail because:
> You are on the CC list for the bug.
Comment 2 Rafael Ávila de Espíndola 2015-05-21 12:16:54 UTC
> > This unfortunately doesn't work if the compiler avoids producing the long
> > section names (as llvm now can).
> 
> Can we use the symbol name directly?

That would be nice. Which is why I asked:

> > Is there a convenient pass over the symbols that could be used for this
> > instead?

Looks like there is, could we use the walk done from Symbol_table::add_from_relob to check if a section has just a constructor in it? We already use that walk to mark symbols as gc roots.
Comment 3 Sriraman Tallam 2015-05-22 22:58:31 UTC
On Thu, May 21, 2015 at 5:16 AM, rafael.espindola at gmail dot com
<sourceware-bugzilla@sourceware.org> wrote:
> https://sourceware.org/bugzilla/show_bug.cgi?id=18440
>
> --- Comment #2 from Rafael Ávila de Espíndola <rafael.espindola at gmail dot com> ---
>> > This unfortunately doesn't work if the compiler avoids producing the long
>> > section names (as llvm now can).
>>
>> Can we use the symbol name directly?
>
> That would be nice. Which is why I asked:
>
>> > Is there a convenient pass over the symbols that could be used for this
>> > instead?
>
> Looks like there is, could we use the walk done from
> Symbol_table::add_from_relob to check if a section has just a constructor in
> it? We already use that walk to mark symbols as gc roots.

I agree, just like gc_mark_symbol, you could call mark_ctor_or_dtor(sym).

Sri

>
> --
> You are receiving this mail because:
> You are on the CC list for the bug.