Conflict between two shared linux objects defining the same function name

My problem is with Python, Qt, PyQt and other stuff, but actually the question is how Linux ld.so .

QUESTION

If a program loads two different shared libraries that have the same entry point name (i.e. they define a function with the same name and signature), how can it determine which version it calls?

MY PROBLEM

I have a third-party, proprietary Linux application written in C ++ (although the source language does not matter) and it is dynamically linked to Qt3.3. The application includes a python interpreter that can be used to write scripts for it.

You can even use the python embedded application instead of the original with a command, for example:

 /path/to/the/program/python 

And he shows the following:

 Python 2.7.1 (r271:86832, Sep 16 2011, 18:16:32) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 

Using gcc 4.1.2. I created and installed PyQt4 from sources, as well as the Qt4 libraries that also exist on the system. I believe the build was successful because I can run the small PyQt4 application using:

 /path/to/the/program/python mypyqtapp.py 

However, if I load a program with its GUI and load the same script, it crashes the first time I call PyQt4 , which is an instance of the QApplication class.

Since the python environment is the same, I suspect it might be a conflict between the Qt3 library and Qt4. However, the strace -e trace=file command shows that in both cases, python finds and loads the correct Qt4 libraries.

So my question is that the program loads two shared libraries that define the same function, how does it know that it calls the correct one? Does the linux ld.so boot loader somehow qualify entry points with a file name or something else? I suspect that my problem may be that the application ended up loading two different QApplication instances and causing the wrong one, but how ld.so really works inside of me.

It is also possible that my problem is caused by something completely different.

Thanks.

+4
source share
1 answer

The conflict symbol detected only at the linkage (ld) stage, loader (ld-linux.so) does not check the conflict symbol.

When using multiple libraries containing a duplicate character, the first one loaded is used.

Actually, someone can use this feature. By providing LD_PRELOAD = overwrite.so, overwrite.so can overwrite any function the program needs.

+1
source

Source: https://habr.com/ru/post/1493490/


All Articles