Reputation: 303
I'm running a tiny embedded linux system, my application uses a whole bunch of dynamically linked libraries (*.SO files).
I'm trying to save disk space, so I thought I could zip up all the .SO files into one compressed zip file.
Then, when the app starts, I would unzip all the .SO files, then open them using the dlopenext C function, then after opening them, delete them all, because the static libraries will now be in memory?
Will I still be able to look up and call functions in the static libraries after I delete the *SO files from the disk, it should be in memory now right?
Any ideas?
Upvotes: 1
Views: 1076
Reputation: 51840
On Linux, even if you delete something from disk, it's not really getting deleted if something had an open handle to it. It will only get deleted at the point the handle is closed.
So the answer is both yes and no. Yes, you can delete them and keep using them. No, it won't help you save space.
You can check whether UPX (http://upx.sourceforge.net) works on your target platform. It might help bringing on-disk sizes down.
Another way to decrease code sizes is to build statically. If that's an option in your case, then this will allow you to do dead code stripping. You would first build every library as a static archive and use the:
-fdata-sections -ffunction-sections
GCC options. For your final executable, you would use those two options plus this linker option:
-Wl,--gc-sections
Again, this will only really help when building static libraries. Dynamic libs cannot be dead code stripped (for obvious reasons; it's not known yet what parts of the library your executable is using.)
Do this only for the libraries you're currently shipping with the executable, of course. Do not statically link against system libraries.
Upvotes: 3
Reputation: 4380
On most *ix implemenmtations, a file exists on the file system until there are no more open references or links to it. So, while deleting the file may well make it appear to be gone (does not show up in an ls
) that likely does not mean the disk space has been released.
Upvotes: 1