Introduce mono_runtime_init_tls to centralize all of the late runtime TLS initialization.
commit1fd343ac44155a5955624931402d88da87117ca2
authorRodrigo Kumpera <kumpera@gmail.com>
Thu, 13 Jun 2013 20:57:11 +0000 (13 16:57 -0400)
committerRodrigo Kumpera <kumpera@gmail.com>
Thu, 13 Jun 2013 21:05:06 +0000 (13 17:05 -0400)
treeaeb197f6b1a4bc601534c32c5f7ae1f0d0a21cc0
parentbd8cc934ed2db3f7e8bca438961aa750d4fd5e9b
Introduce mono_runtime_init_tls to centralize all of the late runtime TLS initialization.

TLS initialization must be done as early as possible since runtime initialization
might be intermingled with 3rd party code running that sometimes create additional
slots. Those extra TLS slots do interfere with AOT compilation that might see a
different set of offsets when compiling than when running.

The current piece of problem is AOT image loading. If the AOT image is not found,
the dynamic linker in 10.9 will create a TLS slot to hold error data. AOT image
loading is triggered in between the creation of the runtime TLS slots.

Since AOT image loading never happens during compilation, the dynamic linker
would never create the slot and things would otherwise remain working.

The solution is to move all TLS initialization to before any assembly is loaded
and, transitively, AOT image loading.
mono/metadata/domain.c
mono/metadata/marshal.c
mono/metadata/marshal.h
mono/metadata/runtime.c
mono/metadata/runtime.h
mono/metadata/threadpool.c
mono/metadata/threadpool.h
mono/metadata/threads-types.h
mono/metadata/threads.c