High-version glibc environment compiles .so files compatible with low-version machines

Background: The product needs to provide the user with a .so file to call. However, the user's server GLIB library version is relatively low, which is version 2.12. At the same time, because the server is a production environment, the library files cannot be upgraded casually. And our internal compilation machine has been upgraded to version 2.14 or above due to compatibility with new C++ features. As a result, the compiled .so file cannot be called normally on the client machine. Then find a way to make it compatible.

The client call error is as follows:

Obviously it is a GLIB version problem.

Solution:

At first, my idea was to use a static environment library compilation method similar to the Windows environment, but unfortunately no relevant information was found. Then change the way of thinking and find a way to specify the lower version of the library version when compiling and using. First check the situation in your own .so, use objdump to find that only memcpy uses glib2.14 in the library, then it is easy to handle. Let the customer check the version used by this function on their machine objdump -T /lib64/libc.so.6 |grep memcpy

Version specification can be done with the assembly instruction .symver (make sure the version specification of the assembly instruction is done before all calls to memcpy):

asm(".symver memcpy, memcpy@GLIBC_2.2.5");

After compiling, check the library situation again, everything is OK, and the version is down. The library is sent to the client, and everything works fine.

Reference: https://blog.csdn.net/nullzhou/article/details/51123435














Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324926857&siteId=291194637