Skip to contentSkip to conversation

Make gcc3.3 Eliminate Unused Static Functions

PATCH In review Rusty Russell 9 participants 11 messages Jun 13, 2003 – Jun 19, 2003 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make gcc3.3 Eliminate Unused Static Functions

In discussions with akpm: it'd be nice to discard unused functions (think CONFIG_PROC_FS=n) without needing to #ifdef around them.

Feedback welcome,
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

Name: Eliminate Unused Functions
Author: Rusty Russell
Status: Tested on 2.5.70-bk16

D: GCC 3.3 has the ability to eliminate unused static functions. This includes
D: code like this:
D:
D: static int unusedfunc(void) { ... };
D: int otherfunc(void)
D: {
D: (void)unusedfunc;
D: ...
D:
D: This means that macros can suppress the "unused" warning on functions
D: without preventing the function elimination. This should allow us to
D: remove a number of #ifdefs around unused functions.
D:
D: Unfortunately, this elimination is only performed if
D: -finline-functions is used. In order to prevent GCC automatically
D: inlining anything, we also specify "--param max-inline-insns-auto=0". D:
D: Earlier compilers don't understand this parameter, so we test for
D: it at build time.
D:

D: Results (all with gcc 3.3)
D:   Without patch:
D:       -rwxrwxr-x    1 rusty    rusty     5115166 Jun 13 09:17 vmlinux
D:   With patch:
D:       -rwxrwxr-x    1 rusty    rusty     5115166 Jun 13 09:58 vmlinux
D:   Without patch (small unused function added):
D:       -rwxrwxr-x    1 rusty    rusty     5115195 Jun 13 10:14 vmlinux
D:   With patch (small unused function added):
D:       -rwxrwxr-x    1 rusty    rusty     5115166 Jun 13 10:15 vmlinux
Makefile +4 -1
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal working-2.5.70-bk16-check_region/Makefile working-2.5.70-bk16-check_region-inline/Makefile
@@ -213,10 +213,13 @@ CFLAGS_KERNEL	=
 AFLAGS_KERNEL	=
 
 NOSTDINC_FLAGS  = -nostdinc -iwithprefix include
+# Needs gcc 3.3 or above to understand max-inline-insns-auto.
+INLINE_OPTS	:= $(shell $(CC) -o /non/existent/file -c --param max-inline-insns-auto=0 -xc /dev/null 2>&1 | grep /non/existent/file >/dev/null && echo -finline-functions --param max-inline-insns-auto=0)
 
+-finline-functions --param max-inline-insns-auto=0
 CPPFLAGS	:= -D__KERNEL__ -Iinclude
 CFLAGS 		:= $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \
-	  	   -fno-strict-aliasing -fno-common
+	  	   $(INLINE_OPTS) -fno-strict-aliasing -fno-common
 AFLAGS		:= -D__ASSEMBLY__ $(CPPFLAGS)
 
 export	VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION KERNELRELEASE ARCH \
#1 lore raw
Quoted 9 lines · In article <[email protected]> you wrote:
D: Results (all with gcc 3.3)
D:   Without patch:
D:       -rwxrwxr-x    1 rusty    rusty     5115166 Jun 13 09:17 vmlinux
D:   With patch:
D:       -rwxrwxr-x    1 rusty    rusty     5115166 Jun 13 09:58 vmlinux
D:   Without patch (small unused function added):
D:       -rwxrwxr-x    1 rusty    rusty     5115195 Jun 13 10:14 vmlinux
D:   With patch (small unused function added):
D:       -rwxrwxr-x    1 rusty    rusty     5115166 Jun 13 10:15 vmlinux

does that mean the current linux source tree does not benefit in any way from this patch?

Greetings
Bernd

Signature · 2 lines
eckes privat - http://www.eckes.org/
Project Freefire - http://www.freefire.org/
#2 lore raw
Quoted 2 lines · Bernd Eckenfels

does that mean the current linux source tree does not benefit in any way from this patch?

I suspect that currently all such instances are wrapped in #ifdef and are not currently compiled in. As he said in the original message, "it'd be nice to discard unused functions (think CONFIG_PROC_FS=n) without needing to #ifdef around them."

This would allow us to remove those #ifdefs.

Chris

Signature · 4 lines
Chris Friesen                    | MailStop: 043/33/F10
Nortel Networks                  | work: (613) 765-0557
3500 Carling Avenue              | fax:  (613) 765-2986
Nepean, ON K2H 8E9 Canada        | email: [email protected]
#3 lore raw
Quoted 11 lines · Chris Friesen
Quoted 2 lines · Bernd Eckenfels

does that mean the current linux source tree does not benefit in any way from this patch?

I suspect that currently all such instances are wrapped in #ifdef and are not currently compiled in. As he said in the original message, "it'd be nice to discard unused functions (think CONFIG_PROC_FS=n) without needing to #ifdef around them."

This would allow us to remove those #ifdefs.

... only if we say a min gcc version of 3.3 however, yes? Otherwise the kernel gets rather bloated. Just how wide-spread (and Good To Use) is gcc-3.3 now?

Signature · 2 lines
Tom Rini
http://gate.crashing.org/~trini/
#4 lore raw
Quoted 3 lines · Tom Rini

... only if we say a min gcc version of 3.3 however, yes? Otherwise the kernel gets rather bloated. Just how wide-spread (and Good To Use) is gcc-3.3 now?

Good point.

I have been using gcc-3.3 for awhile now with success, and I can recommend it at least for x86, but that really is not reason to force anyone to move to it (yet).

So this change will be nice when gcc 3.3 or greater is the minimum compiler, but not very nice until then. If we start eradicating ifdefs users of older compilers will get very bloated kernels.

I would also like it if we did not have to do the hackish inling stuff...

Robert Love

#5 lore raw
Quoted 11 lines · Robert Love
Quoted 3 lines · Tom Rini

... only if we say a min gcc version of 3.3 however, yes? Otherwise the kernel gets rather bloated. Just how wide-spread (and Good To Use) is gcc-3.3 now?

Good point.

I have been using gcc-3.3 for awhile now with success, and I can recommend it at least for x86, but that really is not reason to force anyone to move to it (yet).

But how much have you rebuilt, heavily tested, etc? I know that currently Debian/sid is building XFree86 4.1 at -O on all arches due to gcc-3.3 issues (some xdm auth problem on ppc and x86, other things elsewhere).

Quoted 3 lines

So this change will be nice when gcc 3.3 or greater is the minimum compiler, but not very nice until then. If we start eradicating ifdefs users of older compilers will get very bloated kernels.

Indeed.

Signature · 2 lines
Tom Rini
http://gate.crashing.org/~trini/
#6 lore raw
Quoted 4 lines · Tom Rini

But how much have you rebuilt, heavily tested, etc? I know that currently Debian/sid is building XFree86 4.1 at -O on all arches due to gcc-3.3 issues (some xdm auth problem on ppc and x86, other things elsewhere).

I believe Red Hat Rawhide (what I am running) is built with gcc 3.3.

Anyhow, my point was we _don't_ know if its ready so we cannot start doing things which are detrimental to users of earlier kernels. I was just adding that it does seem to compile the kernel fine for me, at least.

Robert Love

#7 lore raw
In reply to Tom Rini
Quoted 7 lines · Tom Rini
Quoted 6 lines · Robert Love
Quoted 3 lines · Tom Rini

... only if we say a min gcc version of 3.3 however, yes? Otherwise the kernel gets rather bloated. Just how wide-spread (and Good To Use) is gcc-3.3 now?

Quoted 8 lines
Quoted 5 lines

Good point.

I have been using gcc-3.3 for awhile now with success, and I can recommend it at least for x86, but that really is not reason to force anyone to move to it (yet).

But how much have you rebuilt, heavily tested, etc? I know that currently Debian/sid is building XFree86 4.1 at -O on all arches due to

s/4.1/4.2.1/

Quoted 4 lines

gcc-3.3 issues (some xdm auth problem on ppc and x86, other things elsewhere).
...
Tom Rini

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#8 lore raw
In reply to Tom Rini
Quoted 4 lines · Tom Rini

... only if we say a min gcc version of 3.3 however, yes? Otherwise the kernel gets rather bloated. Just how wide-spread (and Good To Use) is gcc-3.3 now?

I haven't seen a clear compiler bug yet, but found two bugs in assembler code with 2.95.3 that compiled without problems with 3.2.x. One of them has actually hit people, as you could see in the code. Most symptoms were "fixed", but the cause remained.

If nothing else, I'd like to keep 2.95 as a code checker for at least a year or two. Give 3.x some more time to mature.

Jörn

Signature · 3 lines
Measure. Don't tune for speed until you've measured, and even then
don't unless one part of the code overwhelms the rest.
-- Rob Pike
#9 lore raw
Quoted 4 lines · J�rn Engel

I haven't seen a clear compiler bug yet, but found two bugs in assembler code with 2.95.3 that compiled without problems with 3.2.x. One of them has actually hit people, as you could see in the code. Most symptoms were "fixed", but the cause remained.

Another data point... Earlier (I *think* it was this thread) someone mentioned problems with trying to build glibc with gcc 3.x and "ls" segfaulting. I've recently upgraded portions of my system (including libraries and compilers) with the packages from the Slackware 9.0 CD. I expect a certain amount of pain (due to library version conflicts) every time I go through the upgrade process, but this time the pain feels different... I absolutely cannot get getty and uugetty from the getty-ps-2.1.0 package to work: segmentation faults. Even tried building from source: no good. My old getty and uugetty binaries (version 2.0.7j) seem to work ok with the new libraries, but rebuilding the 2.0.7j code with gcc-3.2.2 results in segfaults.

The behavior seems to be independent of kernel version (2.5.70-2.5.72). Here's the relevant version list (referenced libraries reported by ldd):

kernel 2.5.72
glibc 2.3.1
libtermcap 2.0.8
ld-2.3.1
gcc 3.2.2
binutils 2.13.90.0.18

The Slackware default install uses agetty rather than the getty-ps package, which may partly explain why my particular symptom hasn't been reported previously (to my knowledge). I'm curious to know if this problem exists with a virgin Slackware 9 installation, and will probably have an answer by this weekend, time permitting.

Signature · 4 lines
-----------------------------------------------------------------------
Bob Tracy                   WTO + WIPO = DMCA? http://www.anti-dmca.org
[email protected]
-----------------------------------------------------------------------
#10 lore raw
Quoted 11 lines · Bob Tracy

Another data point... Earlier (I *think* it was this thread) someone mentioned problems with trying to build glibc with gcc 3.x and "ls" segfaulting. I've recently upgraded portions of my system (including libraries and compilers) with the packages from the Slackware 9.0 CD. I expect a certain amount of pain (due to library version conflicts) every time I go through the upgrade process, but this time the pain feels different... I absolutely cannot get getty and uugetty from the getty-ps-2.1.0 package to work: segmentation faults. Even tried building from source: no good. My old getty and uugetty binaries (version 2.0.7j) seem to work ok with the new libraries, but rebuilding the 2.0.7j code with gcc-3.2.2 results in segfaults.

That was me, but it wasn't this thread. I was talking about building glibc against the 2.5.x kernel headers, that caused problems. glibc 2.3.2 with gcc 3.3 against the 2.4.20 headers is perfectly stable, and passes all tests in "make check". Even with "-O3 -march=athlon-xp -mfpmath=sse", the only tests that fail are in the trig functions (SSE on the Althon only has 32 bit precision so the values are truncated).

Signature · 1 line
Chris