Skip to content

Build an apphost with hostfxr and hostpolicy linked in#35087

Closed
lpereira wants to merge 5 commits intodotnet:masterfrom
lpereira:static-host
Closed

Build an apphost with hostfxr and hostpolicy linked in#35087
lpereira wants to merge 5 commits intodotnet:masterfrom
lpereira:static-host

Conversation

@lpereira
Copy link
Contributor

@lpereira lpereira commented Apr 17, 2020

This PR introduces a few changes:

  • It builds most of hostfxr as a static library, with the shared library being linked with this static library and some shared-specific code
  • It builds hostpolicy as a static library
  • It abstracts how the host looks for hostfxr functions, either by loading a DLL and finding symbols there, or referencing symbols from the executable directly
  • Provides a minimal hostpolicy_resolver that merely references some needed hostpolicy functions

I have not built this on anything other than x64 Linux. Right now, it shouldn't work anywhere else as it requires a ld-only flag to build the shared library from the static library in a way that it doesn't throw away the whole code. (I've force-pushed some changes that should make the hostpolicy DLL be built correctly regardless of the OS, so there's a good chance this will work fine in all platforms.)

The generated binary, static_apphost, isn't currently installed anywhere. It just lives in the artifacts directory. No changes have been performed to use this when publishing an application.

One of the concerns with this was about the size of the executable. This table summarizes it:

Executable name Size in bytes
apphost-linux-x64 181472
static_apphost-linux-x64 570312

This work started out as a big overhaul in how the whole hosting layer was built, but as I'm leaving the .NET team and I ran out of time, I ended up restarting the work and opting for a far simpler solution. There are a lot of things that I'd love to have done here, and I'll be happy to discuss that with anybody that wants to continue this work.

@ghost
Copy link

ghost commented Apr 17, 2020

Tagging subscribers to this area: @vitek-karas, @swaroop-sridhar
Notify danmosemsft if you want to be subscribed.

@lpereira lpereira requested a review from vitek-karas April 17, 2020 01:17
@lpereira
Copy link
Contributor Author

Found an issue with the hostpolicy DLL. Will fix this tomorrow morning.

@swaroop-sridhar
Copy link
Contributor

CC: @VSadov

@vitek-karas
Copy link
Member

  • Can you maybe create an issue and describe the possible improvements you had in mind?
  • Minor: personally I would prefer to leave most of the source files in the fxr/hostpolicy directory and only move the cmake and specific sources to the subdirectories.
  • This will need at least some tests, something super basic to validate that the thing actually runs.

This is part of the work to create an apphost that bundles both hostfxr
and hostpolicy.  The main distinction between the static and shared
versions of hostfxr is that the static version contains a hostpolicy
resolver that references the hostpolicy symbols directly rather than
loading them from a DLL.
This change is part of the work to enable an apphost that bundles both
hostfxr and hostpolicy.  There's no distinction between hostpolicy
that's built as a shared library and as a static library: the shared
library is built by linking an empty object file with the static
library.
Provide a hostfxr_iface class, that abstracts how the hostfxr functions called
by the early stage in the hosting layer is resolved.
This provides two implementations of hostfxr_iface: one for the static
apphost, which bundles hostfxr and hostpolicy, and another for the
conventional apphost, which loads them dynamically on startup.
@VSadov
Copy link
Member

VSadov commented Apr 23, 2020

I had issues with pushing commits to the original branch, so I will open another PR to continue with this:

#35368

@VSadov VSadov closed this Apr 23, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
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.

5 participants