Bug 17902 - missing optimization: unused strings not deleted
Summary: missing optimization: unused strings not deleted
Status: ASSIGNED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Rafael Ávila de Espíndola
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-29 11:52 UTC by Rafael Ávila de Espíndola
Modified: 2015-04-12 14:28 UTC (History)
6 users (show)

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


Attachments
testcase (183 bytes, text/plain)
2015-01-29 11:52 UTC, Rafael Ávila de Espíndola
Details

Note You need to log in before you can comment on or make changes to this bug.
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.