How do I strip local symbols from linux kernel module without breaking it?

Kimvais picture Kimvais · May 24, 2010 · Viewed 17.1k times · Source

If I do --strip-debug or --strip-unneeded, I have the .ko that lists all function names with nm, if I do just strip foo.ko I have a kernel module that refuses to load.

Does anyone know a quick shortcut how to remove all symbols that are not needed for module loading so that people cannot reverse engineer the API:s as easily?

PS: For all you open source bigots missionaries; this is something that general public will never be using in any case so no need to turn the question into a GPL flame war.

Answer

aorth picture aorth · Oct 26, 2011

I just built a kernel without realizing the kernel config had debug symbols enabled, so the size of the resulting modules were quite large. This worked for me:

# du -sh /lib/modules/3.1.0/
1.9G    /lib/modules/3.1.0/
# find /lib/modules/3.1.0/ -iname "*.ko" -exec strip --strip-debug {} \;
# du -sh /lib/modules/3.1.0/
134M    /lib/modules/3.1.0/

Find all files in /lib/modules/3.1.0 named *.ko and execute strip --strip-debug on each of them.