Make gcc3.3 Eliminate Unused Static Functions
Argh, bogus line pasted into Makefile turned up in patch.
This should be better...
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: D: gcc 3.3 without patch: D: -rwxrwxr-x 1 rusty rusty 5115166 Jun 13 09:17 vmlinux D: gcc 3.3 with patch: D: -rwxrwxr-x 1 rusty rusty 5115166 Jun 13 09:58 vmlinux D: gcc 3.3 without patch (small unused function added): D: -rwxrwxr-x 1 rusty rusty 5115195 Jun 13 10:14 vmlinux D: gcc 3.3 with patch (small unused function added): D: -rwxrwxr-x 1 rusty rusty 5115166 Jun 13 10:15 vmlinux
Makefile +3 -1
@@ -213,10 +213,12 @@ 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) 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 \
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Makefile CFLAGS_KERNEL = · line 217
Quoted 7 lines · Rusty Russell
Argh, bogus line pasted into
Makefileturned up in patch.This should be better...
...Makefile +2
-0+# 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)
You have to add a -Wno-unused-function or you'll get a warning for every eliminated function.
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 SeedIn message <[email protected]> you write:
Quoted 7 lines · Rusty Russell
Review
Quoted 6 lines
Argh, bogus line pasted into
Makefileturned up in patch.This should be better...
...(quoted diff) +2
-0+# Needs gcc 3.3 or above to understand max-inline-insns-auto. +INLINE_OPTS := $(shell $(CC) -o /non/existent/file -c --param max-i
nline-insns-auto=0 -xc /dev/null 2>&1 | grep /non/existent/file >/dev/null && e cho -finline-functions --param max-inline-insns-auto=0)
Quoted 4 lines
Quoted 1 line
...
You have to add a -Wno-unused-function or you'll get a warning for every eliminated function.
No, suppressing warnings like that would be bad. Instead, you write functions like this:
#ifdef CONFIG_FOO
extern int register_foo(foo_fn myfunction);
#else
static inline int register_foo(foo_fn myfunction)
{
return 0;
}
#endif /* CONFIG_FOO */That way, there's no unused warning, but gcc knows enough to discard the function.
Hope that clarifies!
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.