@@ -58,8 +58,6 @@ private enum ImageFileMachine
58
58
59
59
private ExceptionDispatchInfo _lastException ;
60
60
61
- private static bool s_jitRegistered = RegisterJITModule ( ) ;
62
-
63
61
[ DllImport ( JitLibrary ) ]
64
62
private extern static IntPtr PAL_RegisterModule ( [ MarshalAs ( UnmanagedType . LPUTF8Str ) ] string moduleName ) ;
65
63
@@ -113,50 +111,41 @@ private IntPtr AllocException(Exception ex)
113
111
[ DllImport ( JitSupportLibrary ) ]
114
112
private extern static char * GetExceptionMessage ( IntPtr obj ) ;
115
113
116
- private JitConfigProvider _jitConfig ;
114
+ private static JitConfigProvider s_jitConfig ;
117
115
118
116
private readonly UnboxingMethodDescFactory _unboxingThunkFactory ;
119
117
120
- private static bool RegisterJITModule ( )
118
+ public static void RegisterJITModule ( JitConfigProvider jitConfig )
121
119
{
122
- if ( ( Environment . OSVersion . Platform == PlatformID . Unix ) || ( Environment . OSVersion . Platform == PlatformID . MacOSX ) )
120
+ s_jitConfig = jitConfig ;
121
+ if ( jitConfig . JitPath != null )
123
122
{
124
- return PAL_RegisterModule ( "libclrjitilc.so" ) != ( IntPtr ) 1 ;
123
+ NativeLibrary . SetDllImportResolver ( typeof ( CorInfoImpl ) . Assembly , JitLibraryResolver ) ;
125
124
}
126
- else
125
+
126
+ if ( Environment . OSVersion . Platform == PlatformID . Unix )
127
127
{
128
- return true ;
128
+ // TODO: The PAL_RegisterModule export should be removed from the JIT
129
+ // and the call to PAL_InitializeDLL should be moved to jitStartup.
130
+ // https://github.com/dotnet/coreclr/issues/27941
131
+ PAL_RegisterModule ( "libclrjitilc.so" ) ;
129
132
}
133
+
134
+ jitStartup ( GetJitHost ( jitConfig . UnmanagedInstance ) ) ;
130
135
}
131
136
132
- private IntPtr JitLibraryResolver ( string libraryName , System . Reflection . Assembly assembly , DllImportSearchPath ? searchPath )
137
+ private static IntPtr JitLibraryResolver ( string libraryName , System . Reflection . Assembly assembly , DllImportSearchPath ? searchPath )
133
138
{
134
139
IntPtr libHandle = IntPtr . Zero ;
135
140
if ( libraryName == JitLibrary )
136
141
{
137
- libHandle = NativeLibrary . Load ( _jitConfig . JitPath , assembly , searchPath ) ;
142
+ libHandle = NativeLibrary . Load ( s_jitConfig . JitPath , assembly , searchPath ) ;
138
143
}
139
144
return libHandle ;
140
145
}
141
146
142
- public CorInfoImpl ( JitConfigProvider jitConfig )
147
+ public CorInfoImpl ( )
143
148
{
144
- //
145
- // Global initialization
146
- //
147
- _jitConfig = jitConfig ;
148
- if ( ! s_jitRegistered )
149
- {
150
- throw new IOException ( "Failed to register JIT" ) ;
151
- }
152
-
153
- if ( _jitConfig . JitPath != null )
154
- {
155
- NativeLibrary . SetDllImportResolver ( typeof ( CorInfoImpl ) . Assembly , JitLibraryResolver ) ;
156
- }
157
-
158
- jitStartup ( GetJitHost ( _jitConfig . UnmanagedInstance ) ) ;
159
-
160
149
_jit = getJit ( ) ;
161
150
if ( _jit == IntPtr . Zero )
162
151
{
@@ -264,7 +253,7 @@ private void PublishCode()
264
253
var relocs = _relocs . ToArray ( ) ;
265
254
Array . Sort ( relocs , ( x , y ) => ( x . Offset - y . Offset ) ) ;
266
255
267
- int alignment = _jitConfig . HasFlag ( CorJitFlag . CORJIT_FLAG_SIZE_OPT ) ?
256
+ int alignment = s_jitConfig . HasFlag ( CorJitFlag . CORJIT_FLAG_SIZE_OPT ) ?
268
257
_compilation . NodeFactory . Target . MinimumFunctionAlignment :
269
258
_compilation . NodeFactory . Target . OptimumFunctionAlignment ;
270
259
@@ -3032,7 +3021,7 @@ private bool isMethodDefinedInCoreLib()
3032
3021
private uint getJitFlags ( ref CORJIT_FLAGS flags , uint sizeInBytes )
3033
3022
{
3034
3023
// Read the user-defined configuration options.
3035
- foreach ( var flag in _jitConfig . Flags )
3024
+ foreach ( var flag in s_jitConfig . Flags )
3036
3025
flags . Set ( flag ) ;
3037
3026
3038
3027
// Set the rest of the flags that don't make sense to expose publically.
0 commit comments