This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

String optimization problem with -ffunction/data-sections


Hi gang,

I'm pushing the envelope in order to use gcc's flags -ffunction-sections and
-fdata-sections with ld's --gc-sections for dead function elimination in the
Linux kernel.

I've encountered a problem with constant strings from unused functions not
being optimised away along with the function. In other words, the unused
functions get optimised away, but the strings they used do not. This happens
at least for PowerPC and x86 targets.

The problem occurs because even with -fdata-sections specified, strings go in
section ".rodata". To be optimised away by ld with --gc-sections, they need to
go in a section like ".rodata.anonymous-string-identifier".
(e.g. ".rodata..LC0")

Similarly, with -fwritable-strings and -fdata-sections, the string data ends
up in ".data", not ".data..LCn" where I would have expected it.

Here's a trivial example showing the problem:
    char *function()
    {
	return "unused string";
    }

Running this through:
    http://www.codesourcery.com/gcc-compile.html
with options:
    -ffunction-sections -fdata-sections -fwritable-strings
yeilds:

        .file   "@2566.1"
        .version        "01.01"
gcc2_compiled.:
.data					#### Oh-oh! Plain old .data
.LC0:
        .string "unused string"
        .section        .text.function,"ax",@progbits
        .align 4
.globl function
        .type    function,@function
function:
        pushl   %ebp
        movl    %esp, %ebp
        movl    $.LC0, %eax
        popl    %ebp
        ret
.Lfe1:
        .size    function,.Lfe1-function
        .ident  "GCC: (GNU) 2.96 20000418 (experimental)

Any suggestions on a possible fix for inclusion in the next gcc release?

Thanks,
Graham
-- 
Graham Stoney
Principal Hardware/Software Engineer
Canon Information Systems Research Australia
Ph: +61 2 9805 2909  Fax: +61 2 9805 2929

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]