* beware of dead string constants
@ 2000-11-21 12:02 Peter Samuelson
2000-11-21 12:13 ` Jakub Jelinek
0 siblings, 1 reply; 13+ messages in thread
From: Peter Samuelson @ 2000-11-21 12:02 UTC (permalink / raw)
To: jgarzik, linux-kernel
While trying to clean up some code recently (CONFIG_MCA, hi Jeff), I
discovered that gcc 2.95.2 (i386) does not remove dead string
constants:
void foo (void)
{
if (0)
printk(KERN_INFO "bar");
}
Annoyingly, gcc forgets to drop the "<6>bar\0". It shows up in the
object file, needlessly clogging your cachelines.
This has ramifications for anyone thinking of converting #ifdefs to
if(){}, which is supposed to be the way of the future. In my situation
I am trying to convert '#ifdef CONFIG_MCA' to 'if (MCA_bus)' where
MCA_bus is #defined to 0 on most architectures.
'static' variables in block scope, same story.
This is mostly a heads-up to say that in this regard gcc is not ready
for prime time, so we really can't get away with using if() as an ifdef
yet, at least not without penalty.
I've just asked gcc-help@gcc.gnu.org about this; if I hear anything
interesting I'll report back.
Peter
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: beware of dead string constants
2000-11-21 12:02 Peter Samuelson
@ 2000-11-21 12:13 ` Jakub Jelinek
2000-11-21 12:24 ` Peter Samuelson
2000-11-21 20:51 ` J . A . Magallon
0 siblings, 2 replies; 13+ messages in thread
From: Jakub Jelinek @ 2000-11-21 12:13 UTC (permalink / raw)
To: Peter Samuelson; +Cc: jgarzik, linux-kernel
On Tue, Nov 21, 2000 at 06:02:35AM -0600, Peter Samuelson wrote:
>
> While trying to clean up some code recently (CONFIG_MCA, hi Jeff), I
> discovered that gcc 2.95.2 (i386) does not remove dead string
> constants:
>
> void foo (void)
> {
> if (0)
> printk(KERN_INFO "bar");
> }
>
> Annoyingly, gcc forgets to drop the "<6>bar\0". It shows up in the
> object file, needlessly clogging your cachelines.
gcc was never dropping such strings, I've commited a patch to fix this
a week ago into CVS.
Jakub
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: beware of dead string constants
2000-11-21 12:13 ` Jakub Jelinek
@ 2000-11-21 12:24 ` Peter Samuelson
2000-11-21 20:51 ` J . A . Magallon
1 sibling, 0 replies; 13+ messages in thread
From: Peter Samuelson @ 2000-11-21 12:24 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: jgarzik, linux-kernel
[Jakub Jelinek <jakub@redhat.com>]
> gcc was never dropping such strings, I've commited a patch to fix
> this a week ago into CVS.
Cool! What about block-scoped 'static' variables? Do those get
garbage-collected now as well?
Peter
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: beware of dead string constants
2000-11-21 12:13 ` Jakub Jelinek
2000-11-21 12:24 ` Peter Samuelson
@ 2000-11-21 20:51 ` J . A . Magallon
2000-11-22 1:14 ` Peter Samuelson
1 sibling, 1 reply; 13+ messages in thread
From: J . A . Magallon @ 2000-11-21 20:51 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: linux-kernel
On Tue, 21 Nov 2000 13:13:27 Jakub Jelinek wrote:
> On Tue, Nov 21, 2000 at 06:02:35AM -0600, Peter Samuelson wrote:
> >
> > While trying to clean up some code recently (CONFIG_MCA, hi Jeff), I
> > discovered that gcc 2.95.2 (i386) does not remove dead string
> > constants:
> >
> > void foo (void)
> > {
> > if (0)
> > printk(KERN_INFO "bar");
> > }
> >
Is it related to opt level ? -O3 does auto-inlining and -O2 does not
(discovered that here, auto inlining in kernel trashes the cache...)
--
Juan Antonio Magallon Lacarta #> cd /pub
mailto:jamagallon@able.es #> more beer
Linux 2.2.18-pre22-vm #7 SMP Sun Nov 19 03:29:20 CET 2000 i686 unknown
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: beware of dead string constants
2000-11-21 20:51 ` J . A . Magallon
@ 2000-11-22 1:14 ` Peter Samuelson
2000-11-22 8:27 ` Urban Widmark
0 siblings, 1 reply; 13+ messages in thread
From: Peter Samuelson @ 2000-11-22 1:14 UTC (permalink / raw)
To: J . A . Magallon; +Cc: Jakub Jelinek, linux-kernel
[I wrote]
> > > void foo (void)
> > > {
> > > if (0)
> > > printk(KERN_INFO "bar");
> > > }
> > >
[J . A . Magallon]
> Is it related to opt level ? -O3 does auto-inlining and -O2 does not
> (discovered that here, auto inlining in kernel trashes the cache...)
See for yourself. 'gcc -S' is most helpful. The above generates a
string constant "bar\0" for all optimization levels.
Jakub Jelinek claims to have fixed this particular bug in the last week
or so, although I have not downloaded and compiled recent CVS to verify
this. (Didn't someone at some point have a cgi frontend to
CVS-snapshot 'gcc -S'? I can't find it now.)
There is a similar case of scoped 'static' variables, like 'bar' here:
extern void baz (int *);
void foo (void)
{
if (0) {
static int bar[1024]; /* useless 4096-byte hole in bss */
baz(bar);
}
}
and according to Jeff Law, this case is *not* fixed yet.
Peter
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: beware of dead string constants
2000-11-22 1:14 ` Peter Samuelson
@ 2000-11-22 8:27 ` Urban Widmark
0 siblings, 0 replies; 13+ messages in thread
From: Urban Widmark @ 2000-11-22 8:27 UTC (permalink / raw)
To: Peter Samuelson; +Cc: linux-kernel
On Tue, 21 Nov 2000, Peter Samuelson wrote:
[someone wrote, and I am keeping it :) ]
> > > > void foo (void)
> > > > {
> > > > if (0)
> > > > printk(KERN_INFO "bar");
> > > > }
> > > >
[snip]
> Jakub Jelinek claims to have fixed this particular bug in the last week
> or so, although I have not downloaded and compiled recent CVS to verify
> this. (Didn't someone at some point have a cgi frontend to
> CVS-snapshot 'gcc -S'? I can't find it now.)
It is linked from the "Reporting bugs" page on the gcc site.
http://www.codesourcery.com/gcc-compile.shtml
And as far as I can tell the assembly output of compiling "foo" does not
contain the "bar" string (without using any -O at all ...)
GCC: (GNU) 2.97 20001121 (experimental)
/Urban
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: beware of dead string constants
@ 2000-11-22 18:48 Michael Elizabeth Chastain
2000-11-23 13:06 ` Werner Almesberger
0 siblings, 1 reply; 13+ messages in thread
From: Michael Elizabeth Chastain @ 2000-11-22 18:48 UTC (permalink / raw)
To: jamagallon, peter; +Cc: jakub, linux-kernel
> Jakub Jelinek claims to have fixed this particular bug in the last week
> or so, although I have not downloaded and compiled recent CVS to verify
> this.
I have a compiler from gcc.gnu.org's CVS tree that's only a few days old,
so I can verify Jakub's claim.
It Works For Me (tm).
There is a considerable amount of engineering and testing and releasology
and distribution between "CVS compiler" and "production compiler for
kernel builds" though.
> and according to Jeff Law, this case is *not* fixed yet.
My compiler behaves as Jeff says.
Michael Elizabeth Chastain
<mailto:mec@shout.net>
"love without fear"
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: beware of dead string constants
2000-11-22 18:48 Michael Elizabeth Chastain
@ 2000-11-23 13:06 ` Werner Almesberger
0 siblings, 0 replies; 13+ messages in thread
From: Werner Almesberger @ 2000-11-23 13:06 UTC (permalink / raw)
To: Michael Elizabeth Chastain; +Cc: linux-kernel
Michael Elizabeth Chastain wrote:
> I have a compiler from gcc.gnu.org's CVS tree that's only a few days old,
> so I can verify Jakub's claim.
BTW, do you have any estimate of how much dead string space it actually
removed ? (I.e. did the .data segment size change significantly, or was
is lost in the normal inter-gcc-version noise ?)
Just curious,
- Werner
--
_________________________________________________________________________
/ Werner Almesberger, ICA, EPFL, CH Werner.Almesberger@epfl.ch /
/_IN_N_032__Tel_+41_21_693_6621__Fax_+41_21_693_6610_____________________/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: beware of dead string constants
@ 2000-11-23 23:29 Bernd Eckenfels
2000-11-23 23:39 ` Jeff Garzik
0 siblings, 1 reply; 13+ messages in thread
From: Bernd Eckenfels @ 2000-11-23 23:29 UTC (permalink / raw)
To: linux-kernel
In article <14874.25691.629724.306563@wire.cadcamlab.org> you wrote:
> This is mostly a heads-up to say that in this regard gcc is not ready
> for prime time, so we really can't get away with using if() as an ifdef
> yet, at least not without penalty.
Humm.. whats the Advantage of this?
Greetings
Bernd
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: beware of dead string constants
2000-11-23 23:29 beware of dead string constants Bernd Eckenfels
@ 2000-11-23 23:39 ` Jeff Garzik
2000-11-24 3:36 ` Peter Samuelson
2000-11-24 4:15 ` Chris Wedgwood
0 siblings, 2 replies; 13+ messages in thread
From: Jeff Garzik @ 2000-11-23 23:39 UTC (permalink / raw)
To: Bernd Eckenfels; +Cc: linux-kernel
Bernd Eckenfels wrote:
>
> In article <14874.25691.629724.306563@wire.cadcamlab.org> you wrote:
> > This is mostly a heads-up to say that in this regard gcc is not ready
> > for prime time, so we really can't get away with using if() as an ifdef
> > yet, at least not without penalty.
>
> Humm.. whats the Advantage of this?
Advantage of what?
If you mean preferring 'if ()' over 'ifdef'... Linus. :) And I agree
with him: code looks -much- more clean without ifdefs. And the
compiler should be smart enough to completely eliminate code inside an
'if (0)' code block.
Jeff
--
Jeff Garzik |
Building 1024 | The chief enemy of creativity is "good" sense
MandrakeSoft | -- Picasso
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: beware of dead string constants
2000-11-23 23:39 ` Jeff Garzik
@ 2000-11-24 3:36 ` Peter Samuelson
2000-11-24 4:15 ` Chris Wedgwood
1 sibling, 0 replies; 13+ messages in thread
From: Peter Samuelson @ 2000-11-24 3:36 UTC (permalink / raw)
To: Jeff Garzik; +Cc: Bernd Eckenfels, linux-kernel
[Jeff Garzik]
> If you mean preferring 'if ()' over 'ifdef'... Linus. :) And I agree
> with him: code looks -much- more clean without ifdefs. And the
> compiler should be smart enough to completely eliminate code inside
> an 'if (0)' code block.
Plus the advantage/disadvantage of making the compiler parse almost
everything, which should eliminate syntax errors, variable name
misspellings, etc in little-used config options. The disadvantage is
that compilation speed goes down.
Peter
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: beware of dead string constants
2000-11-23 23:39 ` Jeff Garzik
2000-11-24 3:36 ` Peter Samuelson
@ 2000-11-24 4:15 ` Chris Wedgwood
1 sibling, 0 replies; 13+ messages in thread
From: Chris Wedgwood @ 2000-11-24 4:15 UTC (permalink / raw)
To: Jeff Garzik; +Cc: Bernd Eckenfels, linux-kernel
On Thu, Nov 23, 2000 at 06:39:25PM -0500, Jeff Garzik wrote:
Advantage of what?
If you mean preferring 'if ()' over 'ifdef'... Linus. :) And I agree
with him: code looks -much- more clean without ifdefs. And the
compiler should be smart enough to completely eliminate code inside an
'if (0)' code block.
Not only that; we should move to code where the compiler engine can
sanitize the code; the preprocessor alternative is obviously more
limited here.
The same can also be said for some of the many macro's that are
#defined; some would surely be better as inline functions is we could
ensure they would always be in-lined.
--cw
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: beware of dead string constants
@ 2000-11-26 14:29 Bernd Eckenfels
0 siblings, 0 replies; 13+ messages in thread
From: Bernd Eckenfels @ 2000-11-26 14:29 UTC (permalink / raw)
To: linux-kernel
In article <3A1DAAAD.28786302@mandrakesoft.com> you wrote:
> If you mean preferring 'if ()' over 'ifdef'... Linus. :) And I agree
> with him: code looks -much- more clean without ifdefs. And the
> compiler should be smart enough to completely eliminate code inside an
> 'if (0)' code block.
Oh I see. Well... hmmm... I think I have no Oppionion about that :)
Greetings
Bernd
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2000-11-26 14:59 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-11-23 23:29 beware of dead string constants Bernd Eckenfels
2000-11-23 23:39 ` Jeff Garzik
2000-11-24 3:36 ` Peter Samuelson
2000-11-24 4:15 ` Chris Wedgwood
-- strict thread matches above, loose matches on Subject: below --
2000-11-26 14:29 Bernd Eckenfels
2000-11-22 18:48 Michael Elizabeth Chastain
2000-11-23 13:06 ` Werner Almesberger
2000-11-21 12:02 Peter Samuelson
2000-11-21 12:13 ` Jakub Jelinek
2000-11-21 12:24 ` Peter Samuelson
2000-11-21 20:51 ` J . A . Magallon
2000-11-22 1:14 ` Peter Samuelson
2000-11-22 8:27 ` Urban Widmark
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox