Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to strip a shared library after linking?

Let's suppose that I got lib.so, I compile the binary mySoft and I link this to lib.so.

At this point, considering that everything is working as expected, It's safe or not to take lib.so and strip it with strip -s lib.so ?

To be clear I'm not interested on linking other binaries to my lib.so after mySoft is properly generated, I'm only interested on keep mySoft working and gain some disk space and maybe a small edge in terms of performances.

like image 237
user1797612 Avatar asked Nov 07 '12 03:11

user1797612


People also ask

Are shared libraries linked?

Shared libraries (also called dynamic libraries) are linked into the program in two stages. First, during compile time, the linker verifies that all the symbols (again, functions, variables and the like) required by the program, are either linked into the program, or in one of its shared libraries.

How does shared library work?

Simply put, A shared library/ Dynamic Library is a library that is loaded dynamically at runtime for each application that requires it. Dynamic Linking doesn't require the code to be copied, it is done by just placing name of the library in the binary file.

Are shared libraries slower?

Programs that use shared libraries are usually slower than those that use statically-linked libraries. A more subtle effect is a reduction in "locality of reference." You may be interested in only a few of the routines in a library, and these routines may be scattered widely in the virtual address space of the library.


1 Answers

Yes, it's safe. strip only removes symbols that are not needed (because they have already been linked). Those symbols are useful for debugging, but they are never needed just for executing the code.

like image 60
Kerrek SB Avatar answered Oct 13 '22 21:10

Kerrek SB