-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Make DllExport attribute to be built-in into .net #37556
Comments
Take a look at the DNNE package published at https://github.com/AaronRobinsonMSFT/DNNE and provide your feedback there.
We are not adding new features to .NET Framework, except security and reliability updates.
The technique used by the DllExport package is Windows-specific that conflicts with our cross-platform portability goals for .NET Core. The technique used by the DNNE package does not have this limitation. See #3750 for more details on this topic. Resolving as duplicate. |
I have briefly checked through DNNE, and idea is based upon having custom loader,
which is loaded by client before loading .net dll. (In your example The idea is good, but that requires indeed using that custom loader, From programming language interoperability perspective it's much easier to just to load With I suspect that indeed https://github.com/3F/DllExport might be limited to windows, but suspect solution could be ported to other OS's, like mac / linux. Also it's much more easier to have So my proposal would be still to reopen this ticket. Moreover - I want to have more functionality itself, and suspect it needs to be raised as a separate issue.
According to stackoverflow: It's indeed possible to force library to be freed, but .net runtime will be unaware of dll release. See on stack overflow following comment:
|
We agree. DNNE generates a library that you just load.
The implementation approach used by https://github.com/3F/DllExport is very Windows specific. There is no way to port it to other OSes.
|
Currently how overall generation logic works - DllExport library uses ildasm and ilasm libraries to disassemble and reassemble dll. I think ildasm and ilasm should be also portable to other OS's - theoretically could be done out of box. But if I would be in your shoes - I would consider modifying C# compiler itself, so it would be able to produce entry points suitable for other programming languages - so produced binary would be compatible with windows I'm also not sure about what kind of file format .net core dlls use. By quickly checking - I think they have 'MZ' header, refers that they are plain PE32 executables. Suspect on linux they work because dotnet is loading those .dll's, not native linux executables. So theoretically But then - why wont keep PE32 executable format as such, only export function entries as normal windows executable (You will have then (E.g. https://stackoverflow.com/questions/1548637/is-there-any-native-dll-export-functions-viewer ) It would indeed makes sense if .net core executable file format would be eventually documented and easily parsable/generatable in future by 3rd party libraries. |
Btw, this could be considered as overlapping with:
So for mixed mode call stack we need to have PE32 parser, with potentially function name extraction. Why we cannot create v1.0 which would be portable with current plain C style function / windows / PE32 / logic, and then upgrade to support C++ class model bit better. And for this task we need opposite operation - PE32 generator with function listing generation. |
These are already portable and built in the repo for cross-platform usage:
That is correct.
This is fully documented as the PE file format. The |
Btw, one thing still come to my mind. If we code in C++, we still need to do this
Eventually after standardization (e.g. c++ standardization or os standardization) kicks in - then we will have at the end one function, which works on all OSs. Of course it might take long time, but we could take first step towards this. On linux / mac we could have both - For linux LoadLibrary would be supported next to dlopen, but would work differently. Then no need to have
Thinking bit deeper - suspect clang supports already PE32 file generation, for gcc it might take some time to implement. PE32 file loading logic is most probably done in wine, so if you want, you could even chat with wine developers to drag wine implementation out of wine make it a built-in into linux. Btw, I have already tried to drag out dbghelp.dll from wine, might be non-trivial, and also protected by LGPL licensing, FYI: Eventually I've abandoned that approach, so there were not much comments or try-to-help from wine developers. Stack trace is still handled via So dragging wine without wine developers support is no-no approach. But creating new implementation of LoadLibrary from scratch - I think it's completely doable. Especially there exists libraries from which to take an example: |
Btw - win developers already took some step towards file format harmonization, see my conversation with Alexandre Julliard,
So wine developers modified gcc to be able to build linux executable with PE header as built-in into linux executable. Sounds like a hacky approach in overall, also not sure about implications of that decision - do we need to have wine emulator to run it ? So emulation is bit complex. |
Fyi: https://stackoverflow.com/a/57534949/2338477 In all honesty, this solution seems to be quite complicated compared to the other DllExport answer. The C++ code is doing a lot of heavy lifting to scan for resouces and entry points, etc. One argument for this answer could be that it is cross-platform. However, the other DllExport answer is also cross-platform as well, and a lot simpler to use. |
Background and Motivation
On nuget packages there already exists 3 different packages which are dealing with
[DllExport]
attribute - that is 1.UnmanagedExports
, 2.UnmanagedExports.Repack
and 3.DllExport
.From all of them - 3rd alternative seems to be most up-to-date and coherent with time.
There are however some regressions coming from .NET platform itself, for example
3F/DllExport#158
Proposed API
Integrate
[DllExport]
attribute to be as a built-in standard in .net.When talking about .net - I would prefer that functionality would come into .net framework, but if it's not possible - then .net core. (Up to you to decide).
Justification
Programming language interoperability with .net family will only grow with time - we are talking about C++, Java - and also interoperability can be done between .net framework and .net core.
(E.g. if main application is .net framework and takes long time to rebased under .net core - then DllExport could be potentially used as a solution).
No need for buggy c++/cli debugging expirience - C++ and C# can communicate directly.
Known limitations
At the moment assembly where you inject
DllExport
- assembly needs to use specific cpu architecture - e.g. x86 or x64, but not AnyCPU. I think this is acceptable limitation.The text was updated successfully, but these errors were encountered: