-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macOS: dead_strip_dylibs ldflag causes missing symbols. #107
Comments
How do you link vtkPythonInterpreter? |
We explicitly do not link to libpython because it conflicts when it is transitively loaded through |
I asked how you link to vtkPythonInterpreter. Is it a dylib? |
Oh, the lack of "to" made me think you were asking about linking the library itself. Yes, this is in a shared build. |
OK, presumably: .. your python extension module claims not to need any .dylibs beyond vtkPythonInterpreter.dylib and that is true (btw, it esp. does not need a 2nd copy of the python interpreter code that knows nothing about the one linked to the exe, that's a certainty!). vtkPythonInterpreter.dylib does need python symbols, but that's fine because the executable will provide those. This does not seem to me different in a technical sense from any other .dylib loading that we do! Can someone explain what actually goes wrong here? |
We tell the executable to link to libpython (and it's on the link line) because it ends up calling vtkPythonInterpreter and the symbols need to be provided. However, |
I am afraid that is un-true and that is the point of https://github.com/python/cpython/search?q=%22-bundle+-undefined+dynamic_lookup%22&type=code Passing -lpython ever when also using a statically linked python is just wrong. CC @jschueller |
And I have yet to see a real example of this auto-stripping feature getting things wrong. Not a single one. |
That's fine for Anaconda, but pvpython is another top-level interpreter and it needs to link to libpython in order to work (as is any other executable that embeds Python rather than being used via |
If it is the case that |
I am in no way talking about "anaconda". |
vtkPythonInterpreter does not link to libpython at all because doing so conflicts with the "interpreter provides the symbols" pattern that is apparently wanted on macOS. But, we have other entry points into starting the interpreter than just |
OK, in that case, you should dynamically load and bind Saying that the top level module needs a DLL when it doesn't just so you don't have to load it yourself is not the best course of action. |
As esp. telling a dylib that it should load a dylib from which symbols will conflict with the executable that's just loaded it seems very dangerous. |
How does one do that? And why is that needed at all when just removing this flag works? The library is not loading libpython on its own. The executable is to provide it. We're trying to do that and using |
Please look at dlfcn |
AFAIK, the |
How does |
Just a note: I've spent weeks dealing with these kinds of linker problems and hours figuring out how to get it all correct. I've even written a linker patch so that the |
I'm sorry, I am just pointing out how things are meant to work. Correct linker flags are being made a scapegoat for the actual problem which seems to be in the design of VTK to me. Our libs shouldn't lie about what they need and over- or under- declare things and that is what these mechanisms achieve. These tricks VTK is doing are not things I would recommend. Software components should be correct and they should stand-alone (within the execution environment and ABI definitions provided by their creators such as that of a Python extension module). The Python upstream developers are also un-ambiguous in their advice. You should not link dynamically to the python interpreter unless you are embedding it (and even then, why not go static?). Here you are embedding it but hoping to use some hacks to make things easier, but they're dangerous and they are wrong.
It statically links them into the executable from libpython.a I'm glad to hear you have dived into the code! But honestly, I believe the initial assumption that there's anything wrong in the flags here that is wrong and that VTK is doing decidedly funky things. |
Great, let's do that. We'll need
What "hacks" are you referring to?
|
Please stop talking about 'linking' to anything. Linking exists in 3 contexts in this world: statically, dynamically (auto-loaded) and dynamically (run-time). I guess you are never using run-time, but still, I don't know what you mean. |
By "link" here, I mean "adding an LC_LOAD_DYLIB command to the binary". At least in a dynamic world. Static is different and (AFAIK), not really relevant here (we only really care about it on Linux, but is "best effort" on other platforms). |
but doesn't
That is not how you provide symbols from executables on macOS. The operating system already provides those symbols to the executable in the global namespace and the loader of any subsequent dylibs knows them already. This is indeed, what a |
Yes. And the tool that imported the
How does the Mach-O interpreter know what "those symbols" are? Where are they provided from? |
From the execution environment. Symbols make it all the way into executables and dylibs and the OS loaded loads and parses them. This happens on all OSes. |
OK. So let's figure out how to write a link line to make |
If your module(s) want symbols from the python dylib then have it autoload the dylib (unless you code runtime binding). Don't rely on the executable to provided it. That way it will work in both cases, say from another executable that didn't autoload the python dylib. If the OS loaded encounters the same dylib twice it will do the right thing and not load it twice. |
Go for it! I don't have time beyond what I've already spent! Cheers. |
But that conflicts with |
No, that's due to the changes in Python initialization around Python 3.8 (AFAIR). You just need to update. But yes, actually, this could get back to the craziness of having two interpreters with the same symbols in the same process address space. |
The point is, a very different |
We did the updates for 3.8…or at least we haven't had any problems with 3.8 with our current approach. Where are the docs on what we'd need to change for 3.8? |
These VTK things have been around for as long as I can remember, so I really hope you get it cleaned up! |
Sorry, I've got a lot of work to do. |
Well, Anaconda support isn't really the top of my list either. @jschueller I'm afraid further investigation at the moment might be up to you…things work for us as-is and there's the easy solution of dropping the flag available… |
This is conda-forge, not Anaconda. If I'm ever asked to look at this by my company then I will for sure get onto it but vtk didn't scratch any itch for my personal open source needs so i won't be able to spend time helping it on conda-forge, unless it's for quick tips. Rarely are tips quick 🙂 |
Ah, I'm obviously not well-versed in Anaconda's corner of things other than bug reports we get about it :) . Since conda-forge is a (the?) main way of getting ParaView through |
Reflining from https://gitlab.kitware.com/paraview/paraview/-/issues/19645
Also seen here: AnacondaRecipes/intel_repack-feedstock#8
When building on macOS, the
-dead_strip_dylibs
option is passed in. This causes the final executables (pvpython
,paraview
, etc.) to drop thelibpython3.X.dylib
reference because the executable itself does not call Python APIs directly. The actual calls are in a library (vtkPythonInterpreter
) which does not directly link libpython because doing so breaks when the symbols are provided by the executable itself (as is the case with Anaconda'spython
binary). There's no way to turn the flag's behavior off once it is on the command line, so not passing it is the solution for ParaView (and VTK).The text was updated successfully, but these errors were encountered: