public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/54303] New: -fdata-sections -ffunction-sections and -fmerge-constants do not work well together
@ 2012-08-17 17:15 tom.rini at gmail dot com
  2012-08-20 19:32 ` [Bug c/54303] " vapier at gentoo dot org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: tom.rini at gmail dot com @ 2012-08-17 17:15 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54303

             Bug #: 54303
           Summary: -fdata-sections -ffunction-sections and
                    -fmerge-constants do not work well together
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tom.rini@gmail.com


Created attachment 28045
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28045
Testcase for the issue

The attached test-case demonstrates the problem I see:
$ arm-linux-gnueabi-gcc -Wall -fdata-sections -ffunction-sections -o
non-collected-strings.o -c non-collected-strings.c
$ arm-linux-gnueabi-gcc -Wl,--gc-sections -o non-collected-strings
non-collected-strings.o
$ strings non-collected-strings | grep here
This string should not be here
This string should be here
$ arm-linux-gnueabi-nm non-collected-strings| grep me
00000000004004d0 t frame_dummy
00000000004004f2 T keep_me
$ arm-linux-gnueabi-nm non-collected-strings.o | grep me
0000000000000000 T garbage_collect_me
0000000000000000 T keep_me
$ arm-linux-gnueabi-objdump -h non-collected-strings.o | grep str
non-collected-strings.o:     file format elf32-littlearm
  3 .rodata.str1.4 0000003c  00000000  00000000  00000034  2**2

And all strings in the object file are coalesced into a single section.

Note that on x86-64 this works as expected as the last step shows instead:
$ objdump -h non-collected-strings.o  | grep str
non-collected-strings.o:     file format elf64-x86-64
  3 .rodata.str1.8 0000001f  0000000000000000  0000000000000000  00000040  2**3
  5 .rodata.str1.1 0000001b  0000000000000000  0000000000000000  0000006f  2**0

I've verified this with a few different arm-linux-gnueabi toolchains (ELDK 4.2,
ELDK 5.2.1, Linaro (4:4.6.2-7 in Ubuntu) and this seems like a long-standing
thing, not Linaro-patch specific.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/54303] -fdata-sections -ffunction-sections and -fmerge-constants do not work well together
  2012-08-17 17:15 [Bug c/54303] New: -fdata-sections -ffunction-sections and -fmerge-constants do not work well together tom.rini at gmail dot com
@ 2012-08-20 19:32 ` vapier at gentoo dot org
  2012-08-21  0:35 ` marek.vasut at gmail dot com
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: vapier at gentoo dot org @ 2012-08-20 19:32 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54303

Mike Frysinger <vapier at gentoo dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |toolchain at gentoo dot org

--- Comment #1 from Mike Frysinger <vapier at gentoo dot org> 2012-08-20 19:31:54 UTC ---
should update the Target field to reflect that this is for ARM


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/54303] -fdata-sections -ffunction-sections and -fmerge-constants do not work well together
  2012-08-17 17:15 [Bug c/54303] New: -fdata-sections -ffunction-sections and -fmerge-constants do not work well together tom.rini at gmail dot com
  2012-08-20 19:32 ` [Bug c/54303] " vapier at gentoo dot org
@ 2012-08-21  0:35 ` marek.vasut at gmail dot com
  2012-09-04 19:51 ` ramana at gcc dot gnu.org
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: marek.vasut at gmail dot com @ 2012-08-21  0:35 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54303

Marek Vasut <marek.vasut at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |marek.vasut at gmail dot
                   |                            |com

--- Comment #2 from Marek Vasut <marek.vasut at gmail dot com> 2012-08-21 00:35:12 UTC ---
Confirmed on Debian:
gcc version 4.7.1 (Debian 4.7.1-3)


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/54303] -fdata-sections -ffunction-sections and -fmerge-constants do not work well together
  2012-08-17 17:15 [Bug c/54303] New: -fdata-sections -ffunction-sections and -fmerge-constants do not work well together tom.rini at gmail dot com
  2012-08-20 19:32 ` [Bug c/54303] " vapier at gentoo dot org
  2012-08-21  0:35 ` marek.vasut at gmail dot com
@ 2012-09-04 19:51 ` ramana at gcc dot gnu.org
  2012-09-04 20:34 ` tom.rini at gmail dot com
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: ramana at gcc dot gnu.org @ 2012-09-04 19:51 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54303

Ramana Radhakrishnan <ramana at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|ARM                         |arm*, x86_64-linux-gnu
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |ramana at gcc dot gnu.org
         Resolution|                            |INVALID

--- Comment #3 from Ramana Radhakrishnan <ramana at gcc dot gnu.org> 2012-09-04 19:51:07 UTC ---
Someone needs to tell the linker to garbage collect sections .... -Wl,
--gc-sections ?


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/54303] -fdata-sections -ffunction-sections and -fmerge-constants do not work well together
  2012-08-17 17:15 [Bug c/54303] New: -fdata-sections -ffunction-sections and -fmerge-constants do not work well together tom.rini at gmail dot com
                   ` (2 preceding siblings ...)
  2012-09-04 19:51 ` ramana at gcc dot gnu.org
@ 2012-09-04 20:34 ` tom.rini at gmail dot com
  2012-09-04 20:36 ` tom.rini at gmail dot com
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: tom.rini at gmail dot com @ 2012-09-04 20:34 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54303

Tom Rini <tom.rini at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|arm*, x86_64-linux-gnu      |arm*-linux-gnu

--- Comment #4 from Tom Rini <tom.rini at gmail dot com> 2012-09-04 20:34:18 UTC ---
(In reply to comment #3)
> Someone needs to tell the linker to garbage collect sections .... -Wl,
> --gc-sections ?

Please re-read the initial post.  This works, as expected on x86_64 and does
NOT on ARM as on ARM all of the strings are placed into a single .rodata
section while on x86_64 they are placed into per-function sections.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/54303] -fdata-sections -ffunction-sections and -fmerge-constants do not work well together
  2012-08-17 17:15 [Bug c/54303] New: -fdata-sections -ffunction-sections and -fmerge-constants do not work well together tom.rini at gmail dot com
                   ` (3 preceding siblings ...)
  2012-09-04 20:34 ` tom.rini at gmail dot com
@ 2012-09-04 20:36 ` tom.rini at gmail dot com
  2012-09-04 23:06 ` ramana at gcc dot gnu.org
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: tom.rini at gmail dot com @ 2012-09-04 20:36 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54303

Tom Rini <tom.rini at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |

--- Comment #5 from Tom Rini <tom.rini at gmail dot com> 2012-09-04 20:35:56 UTC ---
Putting back as unconfirmed.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/54303] -fdata-sections -ffunction-sections and -fmerge-constants do not work well together
  2012-08-17 17:15 [Bug c/54303] New: -fdata-sections -ffunction-sections and -fmerge-constants do not work well together tom.rini at gmail dot com
                   ` (4 preceding siblings ...)
  2012-09-04 20:36 ` tom.rini at gmail dot com
@ 2012-09-04 23:06 ` ramana at gcc dot gnu.org
  2012-10-01 17:55 ` pbrook at gcc dot gnu.org
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: ramana at gcc dot gnu.org @ 2012-09-04 23:06 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54303

--- Comment #6 from Ramana Radhakrishnan <ramana at gcc dot gnu.org> 2012-09-04 23:06:29 UTC ---
Oh I see, my bad to have missed your command line. Sorry.  

I see what's going on here. It's just luck that this works on x86_64 with your
invocation. 


>$ objdump -h non-collected-strings.o  | grep str
>non-collected-strings.o:     file format elf64-x86-64
>  3 .rodata.str1.8 0000001f  0000000000000000  0000000000000000  00000040  2**3
>  5 .rodata.str1.1 0000001b  0000000000000000  0000000000000000  0000006f  2**0

Try with -Os on x86_64 and it should fail there as well on trunk / earlier
versions of GCC. 

Notice one string has an alignment of 8 and the other 1 and that's what drew my
attention to the funniness in this testcase.

The reason for this is the play with CONSTANT_ALIGNMENT in the backends. If the
strings gets the same alignment you end up with the strings in the same
sections which means the whole thing doesn't work and if they have a different
alignment as with your invocation, it all works fine. :(


regards,
ramana


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/54303] -fdata-sections -ffunction-sections and -fmerge-constants do not work well together
  2012-08-17 17:15 [Bug c/54303] New: -fdata-sections -ffunction-sections and -fmerge-constants do not work well together tom.rini at gmail dot com
                   ` (5 preceding siblings ...)
  2012-09-04 23:06 ` ramana at gcc dot gnu.org
@ 2012-10-01 17:55 ` pbrook at gcc dot gnu.org
  2012-10-01 18:02 ` tom.rini at gmail dot com
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: pbrook at gcc dot gnu.org @ 2012-10-01 17:55 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54303

Paul Brook <pbrook at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pbrook at gcc dot gnu.org

--- Comment #7 from Paul Brook <pbrook at gcc dot gnu.org> 2012-10-01 17:55:28 UTC ---
I believe the arm v.s. x86 differences are a red herring.  You'll notice that
one of the strings happens to be a multiple of 8 bytes long, so by default gcc
chooses to align it, in the hope that we'll hit a fast patch in memcpy.  On ARM
we choose to use word alignment unconditionally for similar reasons.  This is
reasonable, the effectiveness of this alignment will depend on the performance
characteristics of the str* and mem* functions.

Arguably this is a linker bug.  It should be able to remove unused elements
from mergeable string sections.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/54303] -fdata-sections -ffunction-sections and -fmerge-constants do not work well together
  2012-08-17 17:15 [Bug c/54303] New: -fdata-sections -ffunction-sections and -fmerge-constants do not work well together tom.rini at gmail dot com
                   ` (6 preceding siblings ...)
  2012-10-01 17:55 ` pbrook at gcc dot gnu.org
@ 2012-10-01 18:02 ` tom.rini at gmail dot com
  2012-10-01 21:14 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: tom.rini at gmail dot com @ 2012-10-01 18:02 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54303

--- Comment #8 from Tom Rini <tom.rini at gmail dot com> 2012-10-01 18:01:37 UTC ---
I could be confused, but how is this a linker issue when gcc puts all of the
strings into a single section?  To reiterate, if you have N functions each with
one string in it, on some platforms (ARM) you get one .rodata.str1.4 section
and on others you get N .rodata.str.somethings sections.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/54303] -fdata-sections -ffunction-sections and -fmerge-constants do not work well together
  2012-08-17 17:15 [Bug c/54303] New: -fdata-sections -ffunction-sections and -fmerge-constants do not work well together tom.rini at gmail dot com
                   ` (7 preceding siblings ...)
  2012-10-01 18:02 ` tom.rini at gmail dot com
@ 2012-10-01 21:14 ` jakub at gcc dot gnu.org
  2014-01-24 23:55 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-10-01 21:14 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54303

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-10-01 21:14:29 UTC ---
Not a linker bug.  SHF_MERGE sections have just duplicates merged, there is no
GC defined for them.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/54303] -fdata-sections -ffunction-sections and -fmerge-constants do not work well together
  2012-08-17 17:15 [Bug c/54303] New: -fdata-sections -ffunction-sections and -fmerge-constants do not work well together tom.rini at gmail dot com
                   ` (8 preceding siblings ...)
  2012-10-01 21:14 ` jakub at gcc dot gnu.org
@ 2014-01-24 23:55 ` pinskia at gcc dot gnu.org
  2014-01-25 19:34 ` tom.rini at gmail dot com
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-01-24 23:55 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54303

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I noticed this also when I was helping out an uboot developer here at Cavium
for Octeon.

Really I think someone should get LTO working for uboot.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/54303] -fdata-sections -ffunction-sections and -fmerge-constants do not work well together
  2012-08-17 17:15 [Bug c/54303] New: -fdata-sections -ffunction-sections and -fmerge-constants do not work well together tom.rini at gmail dot com
                   ` (9 preceding siblings ...)
  2014-01-24 23:55 ` pinskia at gcc dot gnu.org
@ 2014-01-25 19:34 ` tom.rini at gmail dot com
  2014-10-01 13:34 ` [Bug middle-end/54303] " aph at gcc dot gnu.org
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: tom.rini at gmail dot com @ 2014-01-25 19:34 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54303

--- Comment #11 from Tom Rini <tom.rini at gmail dot com> ---
(In reply to Andrew Pinski from comment #10)
> I noticed this also when I was helping out an uboot developer here at Cavium
> for Octeon.
> 
> Really I think someone should get LTO working for uboot.

Please note that for the record this is not a U-Boot bug but U-Boot showing a
compiler bug.  And given the nature of the bug, LTO would not help here I
suspect as the strings are merged together.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug middle-end/54303] -fdata-sections -ffunction-sections and -fmerge-constants do not work well together
  2012-08-17 17:15 [Bug c/54303] New: -fdata-sections -ffunction-sections and -fmerge-constants do not work well together tom.rini at gmail dot com
                   ` (10 preceding siblings ...)
  2014-01-25 19:34 ` tom.rini at gmail dot com
@ 2014-10-01 13:34 ` aph at gcc dot gnu.org
  2015-02-03 15:15 ` rafael.espindola at gmail dot com
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: aph at gcc dot gnu.org @ 2014-10-01 13:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54303

Andrew Haley <aph at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-10-01
                 CC|                            |aph at gcc dot gnu.org
     Ever confirmed|0                           |1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug middle-end/54303] -fdata-sections -ffunction-sections and -fmerge-constants do not work well together
  2012-08-17 17:15 [Bug c/54303] New: -fdata-sections -ffunction-sections and -fmerge-constants do not work well together tom.rini at gmail dot com
                   ` (11 preceding siblings ...)
  2014-10-01 13:34 ` [Bug middle-end/54303] " aph at gcc dot gnu.org
@ 2015-02-03 15:15 ` rafael.espindola at gmail dot com
  2015-02-04 11:41 ` jwrdegoede at fedoraproject dot org
  2015-05-07 15:51 ` segher at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: rafael.espindola at gmail dot com @ 2015-02-03 15:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54303

Rafael Avila de Espindola <rafael.espindola at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rafael.espindola at gmail dot com

--- Comment #13 from Rafael Avila de Espindola <rafael.espindola at gmail dot com> ---
See also
https://sourceware.org/bugzilla/show_bug.cgi?id=17902


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug middle-end/54303] -fdata-sections -ffunction-sections and -fmerge-constants do not work well together
  2012-08-17 17:15 [Bug c/54303] New: -fdata-sections -ffunction-sections and -fmerge-constants do not work well together tom.rini at gmail dot com
                   ` (12 preceding siblings ...)
  2015-02-03 15:15 ` rafael.espindola at gmail dot com
@ 2015-02-04 11:41 ` jwrdegoede at fedoraproject dot org
  2015-05-07 15:51 ` segher at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: jwrdegoede at fedoraproject dot org @ 2015-02-04 11:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54303

Hans de Goede <jwrdegoede at fedoraproject dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jwrdegoede at fedoraproject dot or
                   |                            |g

--- Comment #15 from Hans de Goede <jwrdegoede at fedoraproject dot org> ---
Hi Segher,

Great to hear that you're working on this. I just hit this while trying to get
the u-boot SPL (bootstrap loader, which must fit in internal SoC SRAM) down in
size, so it would be great to see a fix for this.

Regards,

Hans


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug middle-end/54303] -fdata-sections -ffunction-sections and -fmerge-constants do not work well together
  2012-08-17 17:15 [Bug c/54303] New: -fdata-sections -ffunction-sections and -fmerge-constants do not work well together tom.rini at gmail dot com
                   ` (13 preceding siblings ...)
  2015-02-04 11:41 ` jwrdegoede at fedoraproject dot org
@ 2015-05-07 15:51 ` segher at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: segher at gcc dot gnu.org @ 2015-05-07 15:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54303

--- Comment #17 from Segher Boessenkool <segher at gcc dot gnu.org> ---
Author: segher
Date: Thu May  7 15:51:01 2015
New Revision: 222880

URL: https://gcc.gnu.org/viewcvs?rev=222880&root=gcc&view=rev
Log:
        PR middle-end/192
        PR middle-end/54303
        * varasm.c (function_mergeable_rodata_prefix): New function.
        (mergeable_string_section): Use it.
        (mergeable_constant_section): Use it.

gcc/testsuite/
        * gcc.dg/fdata-sections-2.c: New file.

Added:
    trunk/gcc/testsuite/gcc.dg/fdata-sections-2.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/varasm.c


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2015-05-07 15:51 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-17 17:15 [Bug c/54303] New: -fdata-sections -ffunction-sections and -fmerge-constants do not work well together tom.rini at gmail dot com
2012-08-20 19:32 ` [Bug c/54303] " vapier at gentoo dot org
2012-08-21  0:35 ` marek.vasut at gmail dot com
2012-09-04 19:51 ` ramana at gcc dot gnu.org
2012-09-04 20:34 ` tom.rini at gmail dot com
2012-09-04 20:36 ` tom.rini at gmail dot com
2012-09-04 23:06 ` ramana at gcc dot gnu.org
2012-10-01 17:55 ` pbrook at gcc dot gnu.org
2012-10-01 18:02 ` tom.rini at gmail dot com
2012-10-01 21:14 ` jakub at gcc dot gnu.org
2014-01-24 23:55 ` pinskia at gcc dot gnu.org
2014-01-25 19:34 ` tom.rini at gmail dot com
2014-10-01 13:34 ` [Bug middle-end/54303] " aph at gcc dot gnu.org
2015-02-03 15:15 ` rafael.espindola at gmail dot com
2015-02-04 11:41 ` jwrdegoede at fedoraproject dot org
2015-05-07 15:51 ` segher at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).