Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 817
Kimvais Avatar asked May 24 '10 08:05

Kimvais


1 Answers

With no answer to my previous questions, here are some guesses that could also be some clues, and a step to an answer:

From what I recall, a .ko is nothing but an .o file resulting from the merge of all the .o files generated by your source module, and the addition of a .modinfo section. At the end of any .ko building Makefile, there is an LD call: from what I recall, ld is called with the -r option, and this is what create that .o file that the Makefile calls a .ko. This resulting file is not to be confused with an archive or object library (.a file), that is just a format archiving / packaging multiple .o files as one: A merged object is the result of a link that produces yet another .o module: But in the resulting module, all sections that could be merged have been, and all public / external pairs that could be resolved have been inside those sections. So I assume that you end up with your .ko file containing all your "local" extern definitions:

  • Those that are extern because they are used to call across the .o modules in your .ko (but are not needed anymore since they are not supposed to be called from outside the .ko), and

  • those that the .ko module DO need to properly communicate with the loader and kernel.

The former have most likely already been resolved by ld during the merge, but ld has no way to know whether you intend to have them also callable from outside the .ko.

So the extraneous symbols you see are those that are extern for each of your .o files, but are not needed as extern for the resulting .ko. And what you are looking for is a way to strip only those.

Does this last paragraph properly describe the symbols you want to get rid of?

like image 72
filofel Avatar answered Sep 20 '22 15:09

filofel