Skip to content

Use lib prefix in all native library names - #33236

Merged
tarekgh merged 1 commit into
dotnet:masterfrom
am11:feature/libraries-native-libprfix
Mar 7, 2020
Merged

Use lib prefix in all native library names#33236
tarekgh merged 1 commit into
dotnet:masterfrom
am11:feature/libraries-native-libprfix

Conversation

@am11

@am11 am11 commented Mar 5, 2020

Copy link
Copy Markdown
Member

Also consolidated related MSBuild properties in
/eng/native/naming.props file.

Fixes #33118

@stephentoub

Copy link
Copy Markdown
Member

IIRC, the DllImport loader will probe for the specified name + suffix (e.g. ".so") before it probes for the "lib" prefix + name + suffix. Given that, we might want to also update https://github.com/dotnet/runtime/blob/master/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs to include the "lib" prefix in each name, to skip one of the probing steps.

@jkotas

jkotas commented Mar 5, 2020

Copy link
Copy Markdown
Member

cc @tarekgh

@am11

am11 commented Mar 5, 2020

Copy link
Copy Markdown
Member Author

Would the cost of RuntimeInformation.IsOSPlatform(OSPlatform.OSX) check (#738; for dylib vs. so) overweigh in comparison to the probing logic; if they both are evaluated in static context?

@stephentoub

stephentoub commented Mar 5, 2020

Copy link
Copy Markdown
Member

Would the cost of RuntimeInformation.IsOSPlatform(OSPlatform.OSX) check (#738; for dylib vs. so) overweigh in comparison to the probing logic

Probing requires disk access. So, no :) But I'm also not sure why IsOSPlatform is relevant to this issue? The runtime is built for the target platform/OS; the ".dylib" vs ".so" is hardcoded.

@danmoseley

Copy link
Copy Markdown
Contributor

cc @tarekgh since he was on the issue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would lib.System.Native (and so forth) be better? more readable than libSystem.Native perhaps

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, this is not the Linux convention. usually `lib' is prefixed without dots.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plus adding the . might make it such that the loader won't find the library automatically as for anybody PInvoking to System.Native, I believe the runtime will try either System.Native or preappending lib, but it won't find it if it also needs to pre-append a dot.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

@tarekgh

tarekgh commented Mar 5, 2020

Copy link
Copy Markdown
Member

Thanks @danmosemsft for tagging me. @jkotas already tagged me before too.

@joperezr

joperezr commented Mar 5, 2020

Copy link
Copy Markdown
Member

I'll take a look at the failures on the builds to see what is wrong

@am11

am11 commented Mar 5, 2020

Copy link
Copy Markdown
Member Author

@joperezr, thank you. I am investigating macOS build failure locally, if you could point out issue with Windows failure, that would help a lot. :)

@joperezr

joperezr commented Mar 5, 2020

Copy link
Copy Markdown
Member

I think all of the issues are the same in all builds, which EDIT: The issue in the OSX build is during the installers build when trying to crossgen the shared framework. The error that the crossgen compiler is throwing looks like:

Unable to load Jit Compiler: libclrjit.dylib, hr=0x8007007e
Error: compilation failed for "/Users/runner/runners/2.165.0/work/1/s/artifacts/bin/pkg/netcoreapp5.0/runtime/OSX-Debug-x64/Microsoft.CSharp.dll" (0x8007007e)

The command we are sending to crossgen seem fine to me though:

/Users/runner/runners/2.165.0/work/1/s/artifacts/transport/coreclr/sharedFramework/crossgen @/Users/runner/runners/2.165.0/work/1/s/artifacts/obj/netcoreapp/Debug/netcoreapp5.0/osx-x64/crossgen/Microsoft.CSharp.rsp

And the .rsp contents are:

-nologo
-readytorun
-in /Users/runner/runners/2.165.0/work/1/s/artifacts/bin/pkg/netcoreapp5.0/runtime/OSX-Debug-x64/Microsoft.CSharp.dll
-out /Users/runner/runners/2.165.0/work/1/s/artifacts/bin/osx-x64.Debug/crossgen/netcoreapp/runtimes/osx-x64/lib/netcoreapp5.0/Microsoft.CSharp.dll
-platform_assemblies_paths /Users/runner/runners/2.165.0/work/1/s/artifacts/bin/pkg/netcoreapp5.0/runtime/OSX-Debug-x64/:/Users/runner/runners/2.165.0/work/1/s/artifacts/transport/coreclr/sharedFramework/:/Users/runner/runners/2.165.0/work/1/s/artifacts/transport/coreclr/:/Users/runner/runners/2.165.0/work/1/s/artifacts/bin/pkg/netcoreapp5.0/runtime/OSX-Debug-x64/
-JITPath /Users/runner/runners/2.165.0/work/1/s/artifacts/transport/coreclr/sharedFramework/libclrjit.so

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too familiar with this so probably @bartonjs should take a look, but looks like in here you are also changing the override of the default name

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and override default name

this part of the comment refers to the line below. There are two variants of this library produced by this script: shared and static. We have prefix override for each which this delta is removing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this change is correct. We could however preserve the override default name part of the comment for the next line which sets the OUTPUT_NAME on the static lib.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here, this is not only adding lib as a prefix, it is removing our override

@am11

am11 commented Mar 5, 2020

Copy link
Copy Markdown
Member Author

-JITPath /Users/runner/runners/2.165.0/work/1/s/artifacts/transport/coreclr/sharedFramework/libclrjit.so

this is the issue on macOS, @joperezr. crossgen's response file is picking up .so (linux extension) instead of macOS' .dylib extension, the dylib file does exist in that directory:

$ otool -L ./artifacts/bin/coreclr/OSX.x64.Debug/sharedFramework/libclrjit.dylib

./artifacts/bin/coreclr/OSX.x64.Debug/sharedFramework/libclrjit.dylib:
	@rpath/libclrjit.dylib (compatibility version 0.0.0, current version 0.0.0)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1673.126.0)
	/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 1069.11.0)
	/System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 59306.41.2)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.0.0)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.7.0)

Interestingly, the error message doesn't show the actual filename that was requested (and failed) to load: Unable to load Jit Compiler: libclrjit.dylib, hr=0x8007007e

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change, overall, makes me sad. We intentionally stripped off the lib prefix as part of "these aren't general purpose libraries, don't look here". But if we need to, we need to, I guess.

@jkotas jkotas Mar 5, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative may be to statically link these libraries into the runtime for Android where it is causing problems. We are going to have this option for single file flavor of CoreCLR anyway, so doing it for Android as well (or even everywhere) should not be a big deal.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC @akoeplinger and @marek-safar to be aware of the suggestion.

@marek-safar marek-safar Mar 6, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

statically link these libraries into the runtime

Xamarin.Android does not support this mode. I think this would be nice but we won't be in a position to deliver this for .net5. This looks more like .net6 enhancement because we would need to do native linking during publish phase (this depends on Android NDK, etc).

/cc @jonpryor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For CoreCLR, the plan is to statically link the libraries as part of the dotnet/runtime build (see #32823). We are not planning to do native linking during publish phase.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't work for us. The thinking right now is to copy the dynamic libs which are used (during publish) and extend that to full static linking for Android as we plan to do for iOS (and wasm) during publish

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious - why it does not work for you?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primary because of size. If an app uses no crypto we should not link libSystem.Net.Security.Native and you can apply that to all native libs where System.IO.Compression.Native is probably the biggest one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The moment someone brings in any managed HTTP implementation, client or server, it's going to end up requiring both of those. Presumably then the size concern would only be if they were using a platform-specific implementation (e.g. AndroidHttpHandler) where the platform provided all of that support?

Also consolidated related MSBuild properties in
`/eng/native/naming.props` file.
@am11
am11 marked this pull request as ready for review March 6, 2020 06:15
<CreatePackedPackage Condition="'$(CreatePackedPackage)' == ''">true</CreatePackedPackage>

<!-- indicates that lib prefix is not added to library names for Unix-like operating systems -->
<SkipLibraryPrefixFromUnix>true</SkipLibraryPrefixFromUnix>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the reason for this property? why would we want to skip the prefix?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of coreclr, the prefixes were not added in the original version. Apparently, there is a job on CI that crosscompile clrjit.so (Linux version) on Windows. That one was failing, so I restored it by skipping the prefix here. It will require a bit more investigation and it can be avoided (at least in theory) 😅

Comment thread src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs
@tarekgh

tarekgh commented Mar 6, 2020

Copy link
Copy Markdown
Member

all reviewers, do you have any objection proceeding with this PR? any more feedback?

For the issue linking the native library statically, we can track it as a different work item.

@tarekgh

tarekgh commented Mar 6, 2020

Copy link
Copy Markdown
Member

CC @janvorli

@akoeplinger akoeplinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@joperezr joperezr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM too

@tarekgh

tarekgh commented Mar 6, 2020

Copy link
Copy Markdown
Member

I have created the issue #33311 to track the static linking of the native libraries and I am going to merge this one.

@tarekgh
tarekgh merged commit 3d6f8a2 into dotnet:master Mar 7, 2020
@tarekgh

tarekgh commented Mar 7, 2020

Copy link
Copy Markdown
Member

Thanks @am11 for your help with this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change System.Native name to have lib prefix

10 participants