Skip to content
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

NativeAOT NativeLibrary example crash at runtime #268

Closed
VolodymyrBS opened this issue Oct 25, 2020 · 6 comments
Closed

NativeAOT NativeLibrary example crash at runtime #268

VolodymyrBS opened this issue Oct 25, 2020 · 6 comments

Comments

@VolodymyrBS
Copy link

VolodymyrBS commented Oct 25, 2020

I have tried to use NativeAOT NativeLibrary example but got an exception at runtime on Windows and WSL:
Windows
Exeption:

Exception thrown: read access violation. this was nullptr.

Stack Trace:
image

Enviroment:
OS Windows 10.0.19041.0
VisualStudio 16.8.0 Preview 5.0
Microsoft.DotNet.ILCompiler 6.0.0-alpha.1.20525.1

WSL:
gdb message:

(gdb) r
Starting program: a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
RuntimeInstance::GetThreadStore (this=0x0) at /__w/1/s/src/coreclr/src/nativeaot/Runtime/RuntimeInstance.cpp:50
50      /__w/1/s/src/coreclr/src/nativeaot/Runtime/RuntimeInstance.cpp: No such file or directory.
(gdb) bt
#0  RuntimeInstance::GetThreadStore (this=0x0) at /__w/1/s/src/coreclr/src/nativeaot/Runtime/RuntimeInstance.cpp:50
#1  0x00007fffff08ddc3 in GetThreadStore () at /__w/1/s/src/coreclr/src/nativeaot/Runtime/threadstore.cpp:40
#2  ThreadStore::AttachCurrentThread (fAcquireThreadStoreLock=true) at /__w/1/s/src/coreclr/src/nativeaot/Runtime/threadstore.cpp:136
#3  0x00007fffff08d650 in Thread::ReversePInvokeAttachOrTrapThread (this=0x409700, pFrame=0x7ffffffedf18) at /__w/1/s/src/coreclr/src/nativeaot/Runtime/thread.cpp:1200
#4  0x00007fffff22f6c6 in NativeLibrary_NativeLibrary_Class1__Add (a=0, b=1) at Class1.cs:11
#5  0x00000000004012b3 in callSumFunc (path=0x402004 "./bin/release/net5.0/linux-x64/native/NativeLibrary.so", funcName=0x402067 "add", firstInt=2, secondInt=8) at LoadLibrary.c:64
#6  0x00000000004011fe in main () at LoadLibrary.c:38

Enviroment:
OS Debian GNU/Linux 10
clang 7.0.1-8+deb10u2 (tags/RELEASE_701/final)
Microsoft.DotNet.ILCompiler 6.0.0-alpha.1.20525.1

@MichalStrehovsky
Copy link
Member

The runtime is not initialized. It needs #113 but that one is still not complete and I didn't have time to work on this yet.

We'll want to just do #113 (comment) if you would like to take this on.

Otherwise please use Native AOT from the CoreRT repo for now. (It's a different NuGet feed and different version.)

@jkotas
Copy link
Member

jkotas commented Oct 27, 2020

This was fixed by #270. The fix will be in the next daily build. Thank you for reporting this!

@wegylexy
Copy link

What about static lib? How to initialize the runtime when it is static-linked into another native DLL?

@MichalStrehovsky
Copy link
Member

What about static lib? How to initialize the runtime when it is static-linked into another native DLL?

Can you try adding this switch to the linker command line (when you link the resulting DLL):

On Windows:

/INCLUDE:CoreRT_StaticInitialization

On Linux:

--require-defined,CoreRT_StaticInitialization

On macOS:

-u,_CoreRT_StaticInitialization

@wegylexy
Copy link

@MichalStrehovsky
Copy link
Member

We probably don't include (lib)bootrapperdll(.a/.lib) in the static library so you might need to specify it at the linker command line as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants