-
Notifications
You must be signed in to change notification settings - Fork 509
Allow creating native library (static or shared) #1285
Comments
Thank you for talking a look at the project. First class support for building libraries like this is definitely something we would like to support in CoreRT eventually. This involves providing a different version of startup code ( |
#1498 is one of the problems that needs to be fixed to make this work. |
This is a great proposition and would be of immense value. Hopefully it will be implemented. |
Here is what's needed to make this happen. For now, I would worry about RyuJIT codegen only for all of this.
Now, you should be able to produce native .dll out of managed .exe. This native .dll should have CoreRT_wmain entrypoint that you can use to run it. You should be also able to export The next step is get rid of the fake main method and polish this so that you can actually build the native .dll from managed library:
@MichalStrehovsky Feel free to edit this post with anything else you can think of. |
@jkotas I'd love to pick this up. I'd get started on it, right away |
@tonerdo It's yours. Thanks! |
@tonerdo thanks for working on that! Been looking for a way to produce native libraries for the last week -- with no useful results. Hope you can put a prototype together soon, I'd be happy to test it! |
@bazzilic Yeah I saw your message in gitter, was going to respond. I've started working on it and will let you know once I got something |
@jkotas I notice that when I add
and I try to build a shared library. I get the below error at the linking stage Undefined symbols for architecture x86_64:
"_main", referenced from:
_PalGetModuleFileName in libRuntime.a(PalRedhawkUnix.cpp.o)
(maybe you meant: __Z11CoreRT_mainiPPc)
ld: symbol(s) not found for architecture x86_64 Typically this error is thrown by the linker when it doesn't find a |
The problem is that PalGetModuleFileName is referencing the main method here: corert/src/Native/Runtime/unix/PalRedhawkUnix.cpp Line 1211 in 5856164
I think that the fix for this should be to get rid of this code, and always require PalGetModuleFileName to take non-null argument (on Unix at least). |
@jkotas so from my tests I realize the we still need |
Some of this is covered by "The next step is get rid of the fake main method and polish this" in my write up. It is fine to have an option that initialize the runtime automatically when the library is loaded or when the first unmanaged method gets called. I would expect that this automatic options would be used by "simple" libraries. Folks complex programs will likely prefer the explicit initialization/shutdown methods. It is not unusual for the "C" libraries to have initialize method that has to be called before anything else from the library is used. |
* Include nativelib switch for compiler * suppress checking for entrypoint when -nativelib
* Fixes windows build error
@jkotas adding This happens when using both
Any ideas? |
On Windows, the methods have to be exported via .def file passed to the linker. |
Aaah, forgot about that. Is there are provision in the compiler to automatically generate DEF files or is this something I need to add? |
For now, you need to add it. It may be possible to auto generate it in future, but it should be separate issue. |
@nattress after a bit of google searches I've been able to come to the conclusion that the static library that contains that symbol wasn't compiled with position independent code in mind. I should mention that after pulling the latest master the problem symbol is no longer Full error output:
|
* add bootstrapper for native libraries (#1285) * overwrite main method when building library (#1285) * add stub for native library startup method (#1285) * Include nativelib switch for compiler * suppress checking for entrypoint when -nativelib * initialize runtime at start of reverse PInvoke, unix dlopen successful (#1285) * don't run library initializers for Multi module build (#1285) * update buildscript to build unix static library (#1285) * update buildscript to build Windows static library (#1285) * create and use NativeLibraryInitializerRootProvider (#1285) * use "shared" linker arg on unix to build shared library (#1285) * use system module to initialize NativeLibraryInitializerRootProvider (#1285) * initialize runtime just before initializing the thread (#1285) * move InitializeRuntime call to within TSF_Attached state check (#1285) * use static struct constructor to set InitializeRuntime pointer (#1285) * do not include main function in native library build (#1285) * move runtime initialization check to thread init (#1285) * use Thread* to determine whether to initialize runtime (#1285) * handle race conditions when initializing runtime (#1285)
@tonerdo Could you open github issues on the followup up work items for this that you are aware of, and link them to this issue? |
@jkotas will do 👍 |
if could be create native lib,thats will be great !!! |
We now have small workitems tracking the remaining work here (see issues linking to this). Let's not have duplicate issues open. |
It should be possible to create a library (either static or dynamic) which exposes a C API, and which does not require callers to be aware that it is not written in C.
The text was updated successfully, but these errors were encountered: