C library system-call wrappers, or the lack thereof
C library system-call wrappers, or the lack thereof
Posted Nov 15, 2018 18:15 UTC (Thu) by mathstuf (subscriber, #69389)In reply to: C library system-call wrappers, or the lack thereof by lgerbarg
Parent article: C library system-call wrappers, or the lack thereof
Posted Nov 15, 2018 19:07 UTC (Thu)
by mathstuf (subscriber, #69389)
[Link] (7 responses)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -Dmod_EXPORTS -I/System/Library/Frameworks/Python.framework/Versions/2.7/Headers -fPIC -MD -MT CMakeFiles/mod.dir/mod.c.o -MF CMakeFiles/mod.dir/mod.c.o.d -o CMakeFiles/mod.dir/mod.c.o -c ../mod.c
makes this:
$ otool -L mod.so
which still references a specific Python and is wrong anyways:
$ /opt/local/bin/python2.7 -m mod # Use a MacPorts Python
Posted Nov 15, 2018 23:25 UTC (Thu)
by lgerbarg (guest, #57988)
[Link] (6 responses)
If you can find the actual linker invocation (either the driver with -W,-bundle_loader, or the actual call through to ld64) I can probably tell you what’s going wrong with the invocation, though off the top of my head I ha w no idea out how to get CMake to pass through the correct flags.
Posted Nov 15, 2018 23:33 UTC (Thu)
by mathstuf (subscriber, #69389)
[Link] (5 responses)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -bundle -Wl,-headerpad_max_install_names -o mod.so CMakeFiles/mod.dir/mod.c.o -bundle_loader /System/Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -bundle -Wl,-headerpad_max_install_names -o mod.so CMakeFiles/mod.dir/mod.c.o -Wl,-bundle_loader,/System/Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib
Posted Nov 16, 2018 21:53 UTC (Fri)
by lgerbarg (guest, #57988)
[Link] (4 responses)
Posted Nov 16, 2018 22:06 UTC (Fri)
by mathstuf (subscriber, #69389)
[Link] (3 responses)
Posted Nov 16, 2018 22:08 UTC (Fri)
by mathstuf (subscriber, #69389)
[Link] (2 responses)
Posted Nov 18, 2018 21:12 UTC (Sun)
by lgerbarg (guest, #57988)
[Link] (1 responses)
Now that I understand what you are trying to do a bit more clearly (sorry about the confusion) -bundle_loader is not appropriate unless you can re-export the symbols from the main executable. I think that would be the best option from a technical perspective, but it is probably unreasonable since it would require changes and back ports to all of the python interpreters.
Assuming that you need to get this to work without making changes to python itself. I think you should pass ld "-undefined dynamic_lookup." It is kind of gross, but it should work for your use case. If there is ever a desire to improve this behavior for future pythons there changes to the interpreter that would make modules work better:
1) Reexporting the symbols from libpython out of the python interpreter itself and using -bundle_loader
Posted Nov 20, 2018 15:16 UTC (Tue)
by mathstuf (subscriber, #69389)
[Link]
> I think you should pass ld "-undefined dynamic_lookup." It is kind of gross
That works for today. And projects which don't only target macOS are almost never going to do what seems like a bad legacy behavior. The "gross" part of this solution is what led to the patch to ld64.
> Renaming or symlinking the library exporting the API to have an unversioned name (like "libpython.dylib") and then having python set an LC_RPATH to the directory containing the dylib/symlink. Then modules could link to them via "@rpath/libpython.dylib" .
The name of the file doesn't matter. The binary must be edited using `install_name_tool -id` to change what gets embedded in the linking binary. And RPATH on macOS is awful. It only applies if explicitly requested and if something says "use me via rpath", no tools (I know of) add the paths automatically and they must be manually added.
C library system-call wrappers, or the lack thereof
mod.so:
/System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.10)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No code object available for mod
C library system-call wrappers, or the lack thereof
C library system-call wrappers, or the lack thereof
C library system-call wrappers, or the lack thereof
C library system-call wrappers, or the lack thereof
C library system-call wrappers, or the lack thereof
C library system-call wrappers, or the lack thereof
or
2) Renaming or symlinking the library exporting the API to have an unversioned name (like "libpython.dylib") and then having python set an LC_RPATH to the directory containing the dylib/symlink. Then modules could link to them via "@rpath/libpython.dylib" .
C library system-call wrappers, or the lack thereof