Bug 17902

Summary: missing optimization: unused strings not deleted
Product: binutils Reporter: Rafael Ávila de Espíndola <rafael>
Component: goldAssignee: Rafael Ávila de Espíndola <rafael>
Status: ASSIGNED ---    
Severity: normal CC: ccoutant, emaste, ian, jsweval, peron.clem, sourceware
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:
Attachments: testcase

Description Rafael Ávila de Espíndola 2015-01-29 11:52:40 UTC
Created attachment 8090 [details]
testcase

The attached testcase has a 3 strings: "foo", "bar", "bar". Only "foo" is used.

Run

$ gcc -c test.s
$ ld  test.o  -o test.so --shared --gc-sections --icf=safe -O3
$ readelf  -x .rodata test.so

Hex dump of section '.rodata':
  0x000001e8 62617200 666f6f00                   bar.foo.

Note that gold merges the two "bar" entries, but fails to notice it can drop it completely.
Comment 1 Rafael Ávila de Espíndola 2015-02-03 15:15:18 UTC
I am working on a patch.
Comment 2 Clément Péron 2015-04-07 13:30:16 UTC
Hi,

Any Progress ? 

I made an ugly path to put each string in an unique section, .rodata.str1.__hash__

it's working fine but string merging is impossible except if the strings are identical.

I think group strings depending on the function, like for .text sections could be a good idea.

Good luck,
Clement
Comment 3 Rafael Ávila de Espíndola 2015-04-07 13:49:15 UTC
(In reply to Clément Péron from comment #2)
> Hi,
> 
> Any Progress ? 
> 
> I made an ugly path to put each string in an unique section,
> .rodata.str1.__hash__
> 
> it's working fine but string merging is impossible except if the strings are
> identical.
> 
> I think group strings depending on the function, like for .text sections
> could be a good idea.

I have a wip patch up for comments.

I have split various cleanup that also speed up --gc-sections. Most of these are already in.