| 12 Dec 2024 |
GGG | (for the non-autoPatchcilHook interface) | 19:45:29 |
6pak | In reply to @gggkiller:matrix.org same way you do with autoPatchelfHook, add it to runtimeDeps but with autoPatchelfHook you can do --add-needed in postFixup | 19:51:40 |
6pak | In reply to @gggkiller:matrix.org
a more compact output:
$ dotnet run -- --print-imports result/lib/avalonia-ilspy/Avalonia.X11.dll
libc
libgdk-3.so.0
libGL.so.1
libglib-2.0.so.0
libgobject-2.0.so.0
libgtk-3.so.0
libICE.so.6
libSM.so.6
libX11.so.6
libXcursor.so.1
libXi.so.6
libXrandr.so.2
I had the same when playing around before | 19:52:06 |
6pak |  Download image.png | 19:52:10 |
GGG | don't you mean preFixup or fixupPhase? because autoPatchelfHook runs in postFixup | 19:52:55 |
6pak | I think both work but you should do it in postFixup for some ugly reason, don't remember exactly | 19:53:37 |
6pak | In reply to @gggkiller:matrix.org 6pak: currently considering what the CLI UX should be for setting the search paths, because it'll modify the DllImports and CIL has no concept of RPATH (although the DllImports can stand in for NT_NEEDED) we could emulate RPATH with a custom DllImportResolver | 19:56:21 |
6pak | and I think keeping the interface as close as possible to patchelf is the way to go | 19:56:57 |
GGG | I feel like it'd be better to just modify the DllImport themselves since we already have them on hand | 19:57:00 |
6pak | I was thinking of doing both | 19:57:16 |
GGG | ELFs and CIL assemblies aren't the same though, trying to emulate it could shoot ourselves in the foot | 19:59:49 |
GGG | also, I can't figure out if the DllImportResolver also handles NativeLibrary.Load | 20:03:11 |
GGG | if it doesn't then there's no point in using it | 20:03:18 |
6pak | it does | 20:03:24 |
GGG | * if it doesn't then there's no point in using it as we already statically know all the libraries that are loaded through DllImport | 20:03:35 |
6pak | actually maybe only for the libraryName overload that also takes in the assembly | 20:04:57 |
GGG | seems like neither do:
Given a library name, this method searches specific paths based on the runtime configuration, input parameters, and attributes of the calling assembly. If the searchPath parameter is non-null, the flags in this enumeration are used. Otherwise, the flags specified by the DefaultDllImportSearchPathsAttribute on the calling assembly, if any are present, are used. This method does not invoke the resolver registered using SetDllImportResolver(Assembly, DllImportResolver) method. Starting with .NET 5, this method does invoke the AssemblyLoadContext.LoadUnmanagedDll method and the AssemblyLoadContext.ResolvingUnmanagedDll event.
| 20:06:00 |
GGG | so I honestly don't think there's a point in using SetDllImportResolver as they're all static known strings we can modify directly | 20:06:36 |
GGG | not to mention if, for some reason, some app decides to use their own DllImportResolver then that'd make our tool not work | 20:08:44 |
6pak | In reply to @gggkiller:matrix.org
seems like neither do:
Given a library name, this method searches specific paths based on the runtime configuration, input parameters, and attributes of the calling assembly. If the searchPath parameter is non-null, the flags in this enumeration are used. Otherwise, the flags specified by the DefaultDllImportSearchPathsAttribute on the calling assembly, if any are present, are used. This method does not invoke the resolver registered using SetDllImportResolver(Assembly, DllImportResolver) method. Starting with .NET 5, this method does invoke the AssemblyLoadContext.LoadUnmanagedDll method and the AssemblyLoadContext.ResolvingUnmanagedDll event.
oh, I was thinking of AssemblyLoadContext.ResolvingUnmanagedDll then | 20:11:57 |
6pak | which I think is also called for dllimports | 20:12:08 |
GGG | ok, got it working by overriding the DllImports, I think I'll make a minimal version with it and then if you want to convert it to the ResolvingUnmanagedDll event, I'll leave it up to you since you know more about this library than me 6pak | 23:40:32 |
GGG | if you're okay with it | 23:40:34 |
| 13 Dec 2024 |
GGG | ok, managed to write the code for an auto patchcil command, haven't tested yet, will leave that for tomorrow https://github.com/GGG-KILLER/patchcil/blob/main/src/Commands/AutoCommand.cs | 06:33:41 |
GGG | seems to output the expected errors, although I'll have to see about finding the libraries:
$ patchcil auto -r linux-x64 --paths /nix/store/zc4zc1rcf3vj4x3zbqnkpjifj31qijbg-avalonia-ilspy-7.2-rc/lib/avalonia-ilspy/Avalonia.X11.dll
searching for dependencies of /nix/store/zc4zc1rcf3vj4x3zbqnkpjifj31qijbg-avalonia-ilspy-7.2-rc/lib/avalonia-ilspy/Avalonia.X11.dll
libICE.so.6 -> not found!
libSM.so.6 -> not found!
libc -> not found!
libX11.so.6 -> not found!
libXrandr.so.2 -> not found!
libXi.so.6 -> not found!
libXcursor.so.1 -> not found!
libglib-2.0.so.0 -> not found!
libgobject-2.0.so.0 -> not found!
libgtk-3.so.0 -> not found!
libgdk-3.so.0 -> not found!
libGL.so.1 -> not found!
patchcil-auto: 12 dependencies could not be satisfied
error: patchcil-auto could not satisfy dependency libICE.so.6 wanted by /nix/store/zc4zc1rcf3vj4x3zbqnkpjifj31qijbg-avalonia-ilspy-7.2-rc/lib/avalonia-ilspy/Avalonia.X11.dll
error: patchcil-auto could not satisfy dependency libSM.so.6 wanted by /nix/store/zc4zc1rcf3vj4x3zbqnkpjifj31qijbg-avalonia-ilspy-7.2-rc/lib/avalonia-ilspy/Avalonia.X11.dll
error: patchcil-auto could not satisfy dependency libc wanted by /nix/store/zc4zc1rcf3vj4x3zbqnkpjifj31qijbg-avalonia-ilspy-7.2-rc/lib/avalonia-ilspy/Avalonia.X11.dll
error: patchcil-auto could not satisfy dependency libX11.so.6 wanted by /nix/store/zc4zc1rcf3vj4x3zbqnkpjifj31qijbg-avalonia-ilspy-7.2-rc/lib/avalonia-ilspy/Avalonia.X11.dll
error: patchcil-auto could not satisfy dependency libXrandr.so.2 wanted by /nix/store/zc4zc1rcf3vj4x3zbqnkpjifj31qijbg-avalonia-ilspy-7.2-rc/lib/avalonia-ilspy/Avalonia.X11.dll
error: patchcil-auto could not satisfy dependency libXi.so.6 wanted by /nix/store/zc4zc1rcf3vj4x3zbqnkpjifj31qijbg-avalonia-ilspy-7.2-rc/lib/avalonia-ilspy/Avalonia.X11.dll
error: patchcil-auto could not satisfy dependency libXcursor.so.1 wanted by /nix/store/zc4zc1rcf3vj4x3zbqnkpjifj31qijbg-avalonia-ilspy-7.2-rc/lib/avalonia-ilspy/Avalonia.X11.dll
error: patchcil-auto could not satisfy dependency libglib-2.0.so.0 wanted by /nix/store/zc4zc1rcf3vj4x3zbqnkpjifj31qijbg-avalonia-ilspy-7.2-rc/lib/avalonia-ilspy/Avalonia.X11.dll
error: patchcil-auto could not satisfy dependency libgobject-2.0.so.0 wanted by /nix/store/zc4zc1rcf3vj4x3zbqnkpjifj31qijbg-avalonia-ilspy-7.2-rc/lib/avalonia-ilspy/Avalonia.X11.dll
error: patchcil-auto could not satisfy dependency libgtk-3.so.0 wanted by /nix/store/zc4zc1rcf3vj4x3zbqnkpjifj31qijbg-avalonia-ilspy-7.2-rc/lib/avalonia-ilspy/Avalonia.X11.dll
error: patchcil-auto could not satisfy dependency libgdk-3.so.0 wanted by /nix/store/zc4zc1rcf3vj4x3zbqnkpjifj31qijbg-avalonia-ilspy-7.2-rc/lib/avalonia-ilspy/Avalonia.X11.dll
error: patchcil-auto could not satisfy dependency libGL.so.1 wanted by /nix/store/zc4zc1rcf3vj4x3zbqnkpjifj31qijbg-avalonia-ilspy-7.2-rc/lib/avalonia-ilspy/Avalonia.X11.dll
patchcil-auto failed to find all the required dependencies.
Add the missing dependencies to --libs or use `--ignore-missing="foo.so.1 bar.so etc.so"`.
| 06:36:58 |
6pak | looks pretty good | 15:52:03 |
6pak | rid-graph-gen is interesting, but fyi there is a C# reader for the graph here https://github.com/dotnet/dotnet/blob/v9.0.101/src/nuget-client/src/NuGet.Core/NuGet.Packaging/RuntimeModel/JsonRuntimeFormat.cs | 15:52:34 |
6pak | which the sdk uses | 15:52:38 |
6pak | so you could have just done JsonRuntimeFormat.ReadRuntimeGraph(<$(RuntimeIdentifierGraphPath) from msbuild>).ExpandRuntime("linux-x64") | 15:53:14 |
6pak | and looking more into the runtimes/{rid}/native/{libname}.so pattern seems like it's only a build-time nuget thing | 16:24:33 |