Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what would happened if I changed the C++ Dynamic Shared Library on Linux while my executable program using on it

I have a C++ dynamic shared library abc.so on Linux and my executable program dynamic loading it with dlopen, and then cover abc.so with a new version using rm + cp in case of change inode of the using abc.so, but there are also coredump sometimes, I realize that this may relate to the delay-loaded on dynamic shared library, but I can't confirm it, anybody could help me to figure out why? thanks very much!

like image 703
W.Terry Avatar asked Dec 14 '25 05:12

W.Terry


1 Answers

Without the possibility to investigate it myself, this becomes speculative but using:

rm abc.so
cp new_version.so abc.so

has no effect on programs that has already loaded abc.so. For programs linked with abc.so (or using dlopen to load it) it will present a problem if they are started (or uses dlopen) while the file is removed or it's being copied into place. A core dump could very well be the result.

A better way to replace your abc.so:

copy new_version.so to the same filesystem as abc.so (like the same directory)
mv new_version.so abc.so

This assures that there is always a complete version of abc.so where it's expected to be. Any program needing it will either get the old version or the new version - and there's nothing in between.

like image 151
Ted Lyngmo Avatar answered Dec 16 '25 22:12

Ted Lyngmo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!