[U-Boot-Users] Code duplication...

Robin Getz rgetz at blackfin.uclinux.org
Fri Jun 22 23:32:15 CEST 2007


I was looking to try to prune the code size of U-Boot down a bit, and noticed with:

rgetz at imhotep:~/u-boot> bfin-elf-nm u-boot | grep " [tT] " | awk '{ print $3}' | sort |  uniq -c | grep -v " 1 "

      3 ___fswab16   (12 bytes each)
      6 ___fswab32   (36 bytes each)
      2 _NetCopyIP   ( 6 bytes each)
      2 _NetWriteIP  (22 bytes each)
      2 _zalloc      (12 bytes each)
      2 _zfree       ( 6 bytes each)

because these functions are included in .h files, as functions:

include/linux/byteorder/swab.h

static __inline__ __attribute__((const)) __u16 __fswab16(__u16 x)
{
        return __arch__swab16(x);
}

And when compiling with gcc -Os, __inline__  is a suggestion, not a requirement.

From:
http://gcc.gnu.org/onlinedocs/gcc-4.2.0/gcc/Function-Attributes.html

always_inline
    Generally, functions are not inlined unless optimization is specified. 
    For functions declared inline, this attribute inlines the function even 
    if no optimization level was specified. 

http://gcc.gnu.org/onlinedocs/gcc-4.2.0/gcc/Inline.html#Inline makes the suggestion:

The combination of inline and extern has almost the effect of a macro. The way 
to use it is to put a function definition in a header file with these 
keywords, and put another copy of the definition (lacking inline and 
extern) in a library file. The definition in the header file will cause 
most calls to the function to be inlined. If any uses of the function
remain, they will refer to the single copy in the library.

Today - they get included in every .o file which includes it, and when the link happens, duplicates are not removed.

For grep ___fswab16 * -R, I get
Binary file net/bootp.o matches
Binary file net/tftp.o matches
Binary file net/net.o matches

and bfin-elf-objdump -d net/libnet.a | grep "___fswab16>:" tells me:

00000000 <___fswab16>:
00000000 <___fswab16>:
00000000 <___fswab16>:

it was included 3 times from the three .o files.

First question is - does anyone see the same thing on their platform - or is it something wonky with my toolchain.

Next question is - for a savings of 250 bytes, does anyone care?

-Robin




More information about the U-Boot mailing list