Skip to content
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

Load ShaderConductor dependencies on Mac and Linux #52

Open
Jorgemagic opened this issue Oct 15, 2019 · 4 comments
Open

Load ShaderConductor dependencies on Mac and Linux #52

Jorgemagic opened this issue Oct 15, 2019 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@Jorgemagic
Copy link
Contributor

Jorgemagic commented Oct 15, 2019

The dynamic libraries on Mac using rpath mechanisms to load dependency libraries, so is important to be in mind when you create a dylib, you must specify correct ID, dependencies and rpaths where linker will find dependency libraries.

If you download ShaderConductor Mac dylib from AzurePipeline artifacts and you use for example MacDependencies app, you can see:

File: libShaderConductor.dylib
ID: @rpath/libShaderConductor.dylib
Dependency with: @rpath/libdxcompiler.3.7.dylib
Rpaths: /Users/vts/agent/2.155.1/work/1/s/Build/ninja-osx-clang9-x64-Release/External/DirectXShaderCompiler/lib.

I created a netcore 3.0 app and make a NativeLibrary.Load to load libShaderConductor.dylib but it produces a fail when load dxcompiler library dependency.

Issues:
Dependency filename is wrong, @rpath/libdxcompiler.3.7.dylib must be @rpath/libdxcompiler.dylib
RPaths is wrong, RPaths could be @loader_path; @executable_path

Is possible fix this references using install_name_tool on Mac but maybe is possible fix it from ninja script.

This is an interesting article about this issue on Mac.

Edit. In Linux exists the same issue, it is possible fix with patchelf command but would be fixed in ninja script.

patchelf --set-sorname libdxcompiler.so libdxcompiler.so
patchelf --set-rpath '$ORIGIN' libShaderConductor.so
@Jorgemagic Jorgemagic changed the title Load ShaderConductor dependencies in Mac Load ShaderConductor dependencies on Mac Oct 15, 2019
@Jorgemagic Jorgemagic changed the title Load ShaderConductor dependencies on Mac Load ShaderConductor dependencies on Mac and Linux Oct 16, 2019
@JoelOtter
Copy link

JoelOtter commented Mar 16, 2020

It'd be good to get this fixed if possible, as it's blocking our adoption of this software on macOS. :) I'm happy to try and have a crack at it myself if you're able to direct me towards where the linking gets set up in the build process!

To anyone looking at this - it's possible to get it to work by renaming libdxcompiler.dylib to libdxcompiler.3.7.dylib and then symlinking the original filename to the new one (not sure if linker can resolve symlinks but dlopen can)

@gongminmin
Copy link
Contributor

I'm not farmilar with the shared lib on either linux or macos. The CI runs tests on these systems but doesn't fail. Maybe because they are resolved by linker, not dlopen?

Rename and symlink sound a good way. Does anyone can provide a PR? Thanks.

@trojanfoe
Copy link

trojanfoe commented Apr 16, 2020

It took me about 30 minutes with otool, install_name_tool and codesign to get the binary running on macOS 10.15.

I had to change the rpath for both the binary and the .dylibs. I had to change the name of the dependencies on libdxcompiler.3.7.dylib and I had to create an .entitlements file in order to turn off hardened runtime and codesign everything with my Apple Developer certificate so it would load the dylibs.

Even then it would not work until I did sudo spctl --master-disable :|

@gongminmin gongminmin added the help wanted Extra attention is needed label Apr 16, 2020
@gongminmin
Copy link
Contributor

Get back to this issue after all these years. I had a fix that might help. But I don't have en environment to test it. Anyone like to have a try? The change is in: gongminmin@05f4536

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants