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

Question: NativeAOT-LLVM: Native lib - what sets tls_CurrentThread #2347

Closed
yowl opened this issue Jul 20, 2023 · 5 comments
Closed

Question: NativeAOT-LLVM: Native lib - what sets tls_CurrentThread #2347

yowl opened this issue Jul 20, 2023 · 5 comments
Labels
area-NativeAOT-LLVM LLVM generation for Native AOT compilation (including Web Assembly) question Further information is requested

Comments

@yowl
Copy link
Contributor

yowl commented Jul 20, 2023

If we are building a shared nativelib as per the documentation at https://github.com/dotnet/runtimelab/blob/feature/NativeAOT-LLVM/docs/using-nativeaot/compiling.md, when new is called we make a call to RhpGcAlloc which uses tls_CurrentThread but what should initialize that?

@SingleAccretion
Copy link

The main initialization should happen as part of the RPI that initiated the call into managed call, see ThreadStore::AttachCurrentThread.

@jkotas jkotas added area-NativeAOT-LLVM LLVM generation for Native AOT compilation (including Web Assembly) question Further information is requested labels Jul 20, 2023
@yowl
Copy link
Contributor Author

yowl commented Jul 20, 2023

I wonder if something is not initializing property in wasi as I'm getting odd errors there

    Finished dev [unoptimized + debuginfo] target(s) in 20.33s
     Running `C:\github\cs-runtime-example-wasmtime\target\debug\cs-runtime-example.exe`
thread 'main' panicked at 'execution of foo:foo/floats#float32-param failed error while executing at wasm backtrace:
    0: 0xfa1454 - <unknown>!abort
    1: 0xfec3 - <unknown>!Assert(char const*, char const*, unsigned int, char const*)
    2: 0x25206 - <unknown>!SList<Thread, DefaultSListTraits<Thread, DoNothingFailFastPolicy>>::Iterator::_Validate(SList<Thread, DefaultSListTraits<Thread, DoNothingFailFastPolicy>>::Iterator::e_ValidateOperation) const
    3: 0x23c35 - <unknown>!SList<Thread, DefaultSListTraits<Thread, DoNothingFailFastPolicy>>::Iterator::Insert(Thread*)
    4: 0x23a9e - <unknown>!SList<Thread, DefaultSListTraits<Thread, DoNothingFailFastPolicy>>::PushHead(Thread*)
    5: 0x2393c - <unknown>!ThreadStore::AttachCurrentThread(bool)
    6: 0x23d05 - <unknown>!ThreadStore::AttachCurrentThread()
    7: 0x1e67c - <unknown>!Thread::ReversePInvokeAttachOrTrapThread(ReversePInvokeFrame*)
    8: 0x1ead8 - <unknown>!RhpReversePInvokeAttachOrTrapThread2
    9: 0x1ed40 - <unknown>!RhpReversePInvoke
   10: 0xcf014b - <unknown>!cswasi_wit_the_world_ExportsInterop__wasmExportFloat32Param

I will investigate some more.

@SingleAccretion
Copy link

Perhaps the runtime initialization callback (g_RuntimeInitializationCallback) is missing and EnsureRuntimeInitialized is not doing what it is supposed to do (usually you would expect it to be present due to the RhSetRuntimeInitializationCallback that runs in a global C++ constructor context).

@yowl
Copy link
Contributor Author

yowl commented Jul 21, 2023

Yes, there's a bit of history with wasm components :

bytecodealliance/preview2-prototyping#99

@yowl
Copy link
Contributor Author

yowl commented Jul 30, 2023

Closing as I have a bit better understanding now.

@yowl yowl closed this as completed Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-LLVM LLVM generation for Native AOT compilation (including Web Assembly) question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants