Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of Shared Object files is huge

I compare three compilers:

  • GCC (x86) from Debian (6.3.0) produces hugo_x86.so with 7.8K,
  • GCC (ppc) from Codesourcery (4.6.0) produces hugo_46.so with 6.6K,
  • GCC (x86) from Buildroot 2017.08 (7.2.0) produces hugo.so with 7.5K,
  • GCC (ppc) from Buildroot 2017.08 (7.2.0) produces hugo.so with 67K,
  • GCC (ppc) from Buildroot 2017.08 (6.4.0) produces hugo.so with 67K and
  • GCC (ppc) from Buildroot 2017.08 (4.9.4) produces hugo.so with 67K

The code was taken from eli.thegreenplace.net:

int myglob = 42;

int ml_func(int a, int b)
{
    myglob += a;
    return b + myglob;
}

I ve compiled all sources like this:

powerpc-linux-gcc -c -o hugo.o hugo.c
powerpc-linux-gcc --shared -o hugo.so hugo.o

The difference between the files seems to be a padding (hexdump hugo.so | wc -l):

  • Debian (6.3.0): 381 lines
  • Codesourcery (4.6.0): 283 lines
  • Buildroot 2017.08 (7.2.0): 298 lines
  • Buildroot 2017.08 (6.4.0): 294 lines

(objdump -s shows a similar result)

Questions:

  1. How can I analyze the difference in the Object file best? (objdump, readelf, etc)
  2. How can I analyze the difference (e.g. default options) of the compiler best? (e.g. -dumpspecs)
  3. What could be the reason, for blowing up the shared object? How to increase the file size?

Thanks!

-- Edit: It is also independent of the GCC specs. I ve dumped (-dumpspec) the spec of the Codesourcery (4.6.0) GCC which produces a small shared object, and used it with the Buildroot GCC (-specs) and got again a 67K shared object.

like image 492
Charly Avatar asked Nov 27 '25 18:11

Charly


1 Answers

from How to reduce ELF section padding?:

It looks like this is due to binutils 2.27 increasing the default page size of PowerPC targets to 64k, resulting in bloated binaries on embedded platforms.

There's a discussion on the crosstool-NG github here.

Configuring binutils with --disable-relro should improve things.

You can also add -Wl,-z,max-page-size=0x1000 to gcc when compiling.

When adding BR2_BINUTILS_EXTRA_CONFIG_OPTIONS="--disable-relro" to my buildroot configuration, the share object size is reduced.

like image 139
Charly Avatar answered Nov 30 '25 10:11

Charly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!