This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
optimization/192: String literals don't obey -fdata-sections
- To: gcc-gnats at gcc dot gnu dot org
- Subject: optimization/192: String literals don't obey -fdata-sections
- From: greyham at research dot canon dot com dot au
- Date: 3 May 2000 02:37:53 -0000
- Reply-To: greyham at research dot canon dot com dot au
- Resent-Cc: gcc-prs at gcc dot gnu dot org
- Resent-Reply-To: gcc-gnats@gcc.gnu.org, greyham@research.canon.com.au
>Number: 192
>Category: optimization
>Synopsis: String literals don't obey -fdata-sections
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: pessimizes-code
>Submitter-Id: net
>Arrival-Date: Tue May 02 19:46:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator: Graham Stoney
>Release: 2.95.2
>Organization:
>Environment:
Red Hat Linux 6.2
>Description:
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. I've verified
this is a problem at least for PowerPC and x86 targets, and I suspect all
others too.
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.something". Noting that string literals don't
have globally unique names, the "something" may need to be the function name
it appeared in, or derived from the string contents perhaps via a hash.
Either option would allow the section containing unused strings to be
optimised away correctly by the linker.
Similarly, with -fwritable-strings and -fdata-sections, the string data ends
up in ".data", not ".data.something" where I would have expected it.
Here's a trivial example showing the problem:
char *function()
{
return "unused string";
}
Running this through the latest gcc snapshot on:
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)
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: