Doing dead function elimination without -finline-functions in 2.95.2?

Doing dead function elimination without -finline-functions in 2.95.2?

Post by Graham Stone » Fri, 31 Mar 2000 04:00:00



Hi there,

I'm wondering if anyone can provide me a quick tip on how to do dead function
elimination optimizations with gcc-2.95.2, without resorting to
-finline-functions?

The compiler can know that a function is unused if it is static, and there are
no references to it in the same file. Using -finline-functions (with the
default -fno-keep-inline-functions) will eliminate such functions as a side
effect of attempting to inline them, provided their complexity is below the
inline-limit. However, I don't necessarily want to force all functions below
the inline-limit to be inlined; I just want static functions that don't get
called to be eliminated.

Here's why: I'm attempting to cross-compile the Linux kernel for an embedded
system which has no need for the /proc filesystem. Hence, CONFIG_PROC_FS is
undefined. The kernel code contains files with constructs like:

blah.c:
    static proc_blah_blah()
    {
        /* function dealing with /proc stuff */
    }

    #ifdef CONFIG_PROC_FS
    struct with reference to proc_blah_blah
    #endif

With CONFIG_PROC_FS undefined, I'd like to optimise away the function
proc_blah_blah automatically, without having to spray more
#ifdef CONFIG_PROC_FS's around all such functions. The compiler already has
enough information to eliminate them, but how do I get it to do so without
also asking it to try to inline _everything_?

Any suggestions?

Thanks,
Graham

 
 
 

Doing dead function elimination without -finline-functions in 2.95.2?

Post by Tim Princ » Fri, 31 Mar 2000 04:00:00


The old-fashioned unix way was to use the lorder and tsort scripts on the
list of .o files.  Build a list of .o files for makefile this way, and
strike those which refer only to themselves.


Quote:> Hi there,

> I'm wondering if anyone can provide me a quick tip on how to do dead
function
> elimination optimizations with gcc-2.95.2, without resorting to
> -finline-functions?

> The compiler can know that a function is unused if it is static, and there
are
> no references to it in the same file. Using -finline-functions (with the
> default -fno-keep-inline-functions) will eliminate such functions as a
side
> effect of attempting to inline them, provided their complexity is below
the
> inline-limit. However, I don't necessarily want to force all functions
below
> the inline-limit to be inlined; I just want static functions that don't
get
> called to be eliminated.

> Here's why: I'm attempting to cross-compile the Linux kernel for an
embedded
> system which has no need for the /proc filesystem. Hence, CONFIG_PROC_FS
is
> undefined. The kernel code contains files with constructs like:

> blah.c:
>     static proc_blah_blah()
>     {
> /* function dealing with /proc stuff */
>     }

>     #ifdef CONFIG_PROC_FS
>     struct with reference to proc_blah_blah
>     #endif

> With CONFIG_PROC_FS undefined, I'd like to optimise away the function
> proc_blah_blah automatically, without having to spray more
> #ifdef CONFIG_PROC_FS's around all such functions. The compiler already
has
> enough information to eliminate them, but how do I get it to do so without
> also asking it to try to inline _everything_?

> Any suggestions?

> Thanks,
> Graham


 
 
 

Doing dead function elimination without -finline-functions in 2.95.2?

Post by Graham Stone » Sat, 01 Apr 2000 04:00:00




>The old-fashioned unix way was to use the lorder and tsort scripts on the
>list of .o files.  Build a list of .o files for makefile this way, and
>strike those which refer only to themselves.

But I'm not trying to eliminate entire .o files; I'm just trying to eliminate
static functions in each .o which never get called.

Any other suggestions?

Thanks,
Graham

 
 
 

Doing dead function elimination without -finline-functions in 2.95.2?

Post by Etienne Lorrai » Sat, 01 Apr 2000 04:00:00



> But I'm not trying to eliminate entire .o files; I'm just trying to eliminate
> static functions in each .o which never get called.

> Any other suggestions?

  Compile with GCC option -ffunction-sections, which put every functions
 in their own section, rewrite the linker description file to put all
 sections ".text.<functionname>" in the ".text" segment, and more important
 "ask to binutil" / "send them a patch" to accept the flag --gc-section
 for the i386 target and process it as it is documented (ld manual).

  That's all.

  Hope that helps,
  Etienne.

 
 
 

Doing dead function elimination without -finline-functions in 2.95.2?

Post by Graham Stone » Tue, 04 Apr 2000 04:00:00



> But I'm not trying to eliminate entire .o files; I'm just trying to eliminate
> static functions in each .o which never get called.



Quote:>  Compile with GCC option -ffunction-sections, which put every functions
> in their own section, rewrite the linker description file to put all
> sections ".text.<functionname>" in the ".text" segment, and more important
> "ask to binutil" / "send them a patch" to accept the flag --gc-section
> for the i386 target and process it as it is documented (ld manual).

Interesting approach!  Sounds even better than what I was hoping for, since
this should also eliminate non-static functions which are never called, even
if others in the same .o file are.  Thank you, I'll give it a try.

Regards,
Graham

 
 
 

Doing dead function elimination without -finline-functions in 2.95.2?

Post by Graham Stone » Tue, 04 Apr 2000 04:00:00



> I'm trying to eliminate functions in each .o which never get called.



Quote:> Compile with GCC option -ffunction-sections, which put every functions
> in their own section, rewrite the linker description file to put all
> sections ".text.<functionname>" in the ".text" segment, and more important
> "ask to binutil" / "send them a patch" to accept the flag --gc-section
> for the i386 target and process it as it is documented (ld manual).

Has anyone managed to get -ffunction-sections to work in the Linux kernel on
a PowerPC system?  It looks like what I want, but I can't get it to fly.
I've added it to CFLAGS, and added a line to arch/ppc/vmlinux.lds in the
.text section saying:

    *(.text.*)

However, it won't link without --gc-section in LINKFLAGS, and with --gc-section
in LINKFLAGS, it generates a tiny vmlinux file which nm won't even recognise.

Any more suggestions?

Thanks,
Graham

 
 
 

1. Doing dead function elimination without -finline-functions in 2.95.2?



Has anyone managed to get -ffunction-sections to work in the Linux kernel on
a PowerPC system?  It looks like what I want, but I can't get it to fly.
I've added it to CFLAGS, and added a line to arch/ppc/vmlinux.lds in the
.text section saying:

    *(.text.*)

However, it won't link without --gc-section in LINKFLAGS, and with --gc-section
in LINKFLAGS, it generates a tiny vmlinux file which nm won't even recognise.

Any more suggestions?

Thanks,
Graham

2. EIDE Hard Drive Problem

3. function, function...who's got the function?

4. ddd debugger ?

5. Kernel level 95/NT like registry level functions?

6. pop3

7. BASH function: does the definition order of the function matter?

8. Problems with Linux/UltraSPARC

9. Call function within a function

10. Functions for JavaScript function are needed

11. passing variable number arguments from function to function

12. Tree of Functions calling Functions etc.

13. Main function calling another main function