I have a Gentoo installation. For compiling the kernel I used the configuration from Ubuntu 14.04 kernel.

I find it hard to understand why the sizes of the modules libraries are so different:

In Ubuntu

oz123@ubuntu $ du -sh /lib/modules/4.2.0-36-generic/
202M    /lib/modules/4.2.0-36-generic/

In Gentoo

oz123@gentoo ~ # du -sh /lib/modules/4.2.8-gentoo-1/
1.8G    /lib/modules/4.2.8-gentoo-1/

Is this because of some compile time option? Am I missing something here?


I did

diff -r $DIR1 $DIR2 | grep $DIR2

This reveals that modules which are in both libraries are binary different, for example:

Binary files /lib/modules/4.2.0-36-generic/kernel/sound/pci/ac97/snd-ac97-codec.ko and /mnt/gentoo/lib/modules/4.2.8-gentoo-1/kernel/sound/pci/ac97/snd-ac97-codec.ko differ

The mystery starts to become more clear:

$ du -sh /lib/modules/4.2.0-36-generic/kernel/sound/usb/misc/snd-ua101.ko
36K /lib/modules/4.2.0-36-generic/kernel/sound/usb/misc/snd-ua101.ko
$ du -sh /mnt/gentoo/lib/modules/4.2.8-gentoo-1/kernel/sound/usb/misc/snd-ua101.ko
368K    /mnt/gentoo/lib/modules/4.2.8-gentoo-1/kernel/sound/usb/misc/snd-ua101.ko

This is consistent with a few modules I checked.

So the modules compiled in Gentoo are almost 10 times bigger, why???

Ah ... stripping is the answer...

laptop-oz ~ # du -sh /lib/modules/4.2.8-gentoo-1/kernel/sound/usb/snd-usbmidi-lib.ko
368K    /lib/modules/4.2.8-gentoo-1/kernel/sound/usb/snd-usbmidi-lib.ko
laptop-oz ~ # strip --strip-unneeded /lib/modules/4.2.8-gentoo-1/kernel/sound/usb/snd-usbmidi-lib.ko
laptop-oz ~ # du -sh /lib/modules/4.2.8-gentoo-1/kernel/sound/usb/snd-usbmidi-lib.ko
44K /lib/modules/4.2.8-gentoo-1/kernel/sound/usb/snd-usbmidi-lib.ko

Update 2

Stripping is not the only thing. I am suspecting also compile flags. To check this I installed figlet (version 2.2.5) on Ubuntu and compile the same version with emerge in gentoo:

In Ubuntu:

$ ls -l /usr/bin/figlet-figlet 
-rwxr-xr-x 1 root root 43504 Nov 26  2012 /usr/bin/figlet-figlet

In Gentoo:

# ls -l /usr/bin/figlet
-rwxr-xr-x 1 root root 47384 Jun  8 16:40 /usr/bin/figlet

This are my compile flags in Gentoo:

-O2 -pipe -march=haswell

It seems that when building figlet with -O1 I am getting a much more similar result to Ubuntu:

# ls -l /usr/bin/figlet
-rwxr-xr-x 1 root root 43288 Jun  8 17:10 /usr/bin/figlet

The little difference is really probably due to gcc version (in Ubuntu 4.8.4, in Gentoo 4.9.3).

  • You probably built a lot of modules when you compiled the kernel. – Bratchley Jun 8 '16 at 14:28
  • 1
    As I said, I used the same configuration as Ubuntu, it's not supposed to build more modules. – Oz123 Jun 8 '16 at 14:29

Since you have build the Gentoo modules yourself, you most probably forgot to remove debug info from them. Try

strip --strip-unneeded snd-ua101.ko

and see if it makes a difference.

Next time you rebuild modules for your system, strip all modules using

make INSTALL_MOD_STRIP=1 modules_install
  • 1
    Thanks for that! I am still suspecting the compile flags though. Can you confirm this? – Oz123 Jun 8 '16 at 14:54
  • @Oz123 Yes, compile flags have impact on executable size, as well as many other things like GCC version and libraries used. Do you know what compiler flags your Ubuntu was built with? – Dmitry Grigoryev Jun 8 '16 at 15:01
  • @Oz123 you can add strip to FEATURES. See the Section on Stripping Binaries: Project:Quality Assurance/Backtraces – eyoung100 Jun 10 '16 at 19:50
  • 1
    The guide says it's enabled by default for packages installed by portage. The kermel is installed by calling make if following the handbook... – Oz123 Jun 10 '16 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.