@@ -59,7 +59,6 @@ sealed class DSOCacheEntry
59
59
[ NativeAssembler ( NumberFormat = LlvmIrVariableNumberFormat . Hexadecimal ) ]
60
60
public ulong real_name_hash ;
61
61
public bool ignore ;
62
- public bool is_jni_library ;
63
62
64
63
[ NativeAssembler ( UsesDataProvider = true ) ]
65
64
public uint name_index ;
@@ -239,27 +238,15 @@ sealed class XamarinAndroidBundledAssembly
239
238
}
240
239
#pragma warning restore CS0649
241
240
242
- sealed class DsoCacheState
243
- {
244
- public List < StructureInstance < DSOCacheEntry > > DsoCache = [ ] ;
245
- public List < DSOCacheEntry > JniPreloadDSOs = [ ] ;
246
- public List < StructureInstance < DSOCacheEntry > > AotDsoCache = [ ] ;
247
- public LlvmIrStringBlob NamesBlob = null ! ;
248
- }
249
-
250
241
// Keep in sync with FORMAT_TAG in src/monodroid/jni/xamarin-app.hh
251
242
const ulong FORMAT_TAG = 0x00025E6972616D58 ; // 'Xmari^XY' where XY is the format version
252
243
253
- // List of library names to ignore when generating the list of JNI-using libraries to preload
254
- internal static readonly HashSet < string > DsoCacheJniPreloadIgnore = new ( StringComparer . OrdinalIgnoreCase ) {
255
- "libmonodroid.so" ,
256
- } ;
257
-
258
244
SortedDictionary < string , string > ? environmentVariables ;
259
245
SortedDictionary < string , string > ? systemProperties ;
260
246
SortedDictionary < string , string > ? runtimeProperties ;
261
247
StructureInstance ? application_config ;
262
-
248
+ List < StructureInstance < DSOCacheEntry > > ? dsoCache ;
249
+ List < StructureInstance < DSOCacheEntry > > ? aotDsoCache ;
263
250
#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value - assigned conditionally by build process
264
251
List < StructureInstance < XamarinAndroidBundledAssembly > > ? xamarinAndroidBundledAssemblies ;
265
252
#pragma warning restore CS0649
@@ -274,10 +261,10 @@ sealed class DsoCacheState
274
261
StructureInfo ? assemblyStoreRuntimeDataStructureInfo ;
275
262
StructureInfo ? runtimePropertyStructureInfo ;
276
263
StructureInfo ? runtimePropertyIndexEntryStructureInfo ;
277
- #pragma warning disable CS0169 // Field is never used - might be used in future versions
264
+ #pragma warning disable CS0169 // Field is never used - might be used in future versions
278
265
StructureInfo ? hostConfigurationPropertyStructureInfo ;
279
266
#pragma warning restore CS0169
280
- #pragma warning disable CS0169 // Field is never used - might be used in future versions
267
+ #pragma warning disable CS0169 // Field is never used - might be used in future versions
281
268
StructureInfo ? hostConfigurationPropertiesStructureInfo ;
282
269
#pragma warning restore CS0169
283
270
StructureInfo ? appEnvironmentVariableStructureInfo ;
@@ -362,7 +349,7 @@ protected override void Construct (LlvmIrModule module)
362
349
} ;
363
350
module . Add ( sysProps , stringGroupName : "sysprop" , stringGroupComment : " System properties name:value pairs" ) ;
364
351
365
- DsoCacheState dsoState = InitDSOCache ( ) ;
352
+ ( dsoCache , aotDsoCache , LlvmIrStringBlob dsoNamesBlob ) = InitDSOCache ( ) ;
366
353
var app_cfg = new ApplicationConfigCLR {
367
354
uses_assembly_preload = UsesAssemblyPreload ,
368
355
jni_add_native_method_registration_attribute_present = JniAddNativeMethodRegistrationAttributePresent ,
@@ -376,8 +363,8 @@ protected override void Construct (LlvmIrModule module)
376
363
number_of_assemblies_in_apk = ( uint ) NumberOfAssembliesInApk ,
377
364
number_of_shared_libraries = ( uint ) NativeLibraries . Count ,
378
365
bundled_assembly_name_width = ( uint ) BundledAssemblyNameWidth ,
379
- number_of_dso_cache_entries = ( uint ) dsoState . DsoCache . Count ,
380
- number_of_aot_cache_entries = ( uint ) dsoState . AotDsoCache . Count ,
366
+ number_of_dso_cache_entries = ( uint ) dsoCache . Count ,
367
+ number_of_aot_cache_entries = ( uint ) aotDsoCache . Count ,
381
368
android_runtime_jnienv_class_token = ( uint ) AndroidRuntimeJNIEnvToken ,
382
369
jnienv_initialize_method_token = ( uint ) JNIEnvInitializeToken ,
383
370
jnienv_registerjninatives_method_token = ( uint ) JNIEnvRegisterJniNativesToken ,
@@ -388,28 +375,18 @@ protected override void Construct (LlvmIrModule module)
388
375
application_config = new StructureInstance < ApplicationConfigCLR > ( applicationConfigStructureInfo , app_cfg ) ;
389
376
module . AddGlobalVariable ( "application_config" , application_config ) ;
390
377
391
- var dso_cache = new LlvmIrGlobalVariable ( dsoState . DsoCache , "dso_cache" , LlvmIrVariableOptions . GlobalWritable ) {
378
+ var dso_cache = new LlvmIrGlobalVariable ( dsoCache , "dso_cache" , LlvmIrVariableOptions . GlobalWritable ) {
392
379
Comment = " DSO cache entries" ,
393
380
BeforeWriteCallback = HashAndSortDSOCache ,
394
381
} ;
395
382
module . Add ( dso_cache ) ;
396
383
397
- // This variable MUST be written after `dso_cache` since it relies on sorting performed by HashAndSortDSOCache
398
- var dso_jni_preloads_idx = new LlvmIrGlobalVariable ( new List < uint > ( ) , "dso_jni_preloads_idx" , LlvmIrVariableOptions . GlobalConstant ) {
399
- Comment = " Indices into dso_cache[] of DSO libraries to preload because of JNI use" ,
400
- ArrayItemCount = ( uint ) dsoState . JniPreloadDSOs . Count ,
401
- BeforeWriteCallback = PopulatePreloadIndices ,
402
- BeforeWriteCallbackCallerState = dsoState ,
403
- } ;
404
- module . AddGlobalVariable ( "dso_jni_preloads_idx_count" , dso_jni_preloads_idx . ArrayItemCount ) ;
405
- module . Add ( dso_jni_preloads_idx ) ;
406
-
407
- var aot_dso_cache = new LlvmIrGlobalVariable ( dsoState . AotDsoCache , "aot_dso_cache" , LlvmIrVariableOptions . GlobalWritable ) {
384
+ var aot_dso_cache = new LlvmIrGlobalVariable ( aotDsoCache , "aot_dso_cache" , LlvmIrVariableOptions . GlobalWritable ) {
408
385
Comment = " AOT DSO cache entries" ,
409
386
BeforeWriteCallback = HashAndSortDSOCache ,
410
387
} ;
411
388
module . Add ( aot_dso_cache ) ;
412
- module . AddGlobalVariable ( "dso_names_data" , dsoState . NamesBlob , LlvmIrVariableOptions . GlobalConstant ) ;
389
+ module . AddGlobalVariable ( "dso_names_data" , dsoNamesBlob , LlvmIrVariableOptions . GlobalConstant ) ;
413
390
414
391
var dso_apk_entries = new LlvmIrGlobalVariable ( typeof ( List < StructureInstance < DSOApkEntry > > ) , "dso_apk_entries" ) {
415
392
ArrayItemCount = ( ulong ) NativeLibraries . Count ,
@@ -566,36 +543,6 @@ void AddAssemblyStores (LlvmIrModule module)
566
543
module . Add ( assembly_store ) ;
567
544
}
568
545
569
- void PopulatePreloadIndices ( LlvmIrVariable variable , LlvmIrModuleTarget target , object ? state )
570
- {
571
- var indices = variable . Value as List < uint > ;
572
- if ( indices == null ) {
573
- throw new InvalidOperationException ( $ "Internal error: DSO preload indices list instance not present.") ;
574
- }
575
-
576
- var dsoState = state as DsoCacheState ;
577
- if ( dsoState == null ) {
578
- throw new InvalidOperationException ( $ "Internal error: DSO state not present.") ;
579
- }
580
-
581
- foreach ( DSOCacheEntry preload in dsoState . JniPreloadDSOs ) {
582
- int dsoIdx = dsoState . DsoCache . FindIndex ( entry => {
583
- if ( entry . Instance == null ) {
584
- return false ;
585
- }
586
-
587
- return entry . Instance . hash == preload . hash && entry . Instance . real_name_hash == preload . real_name_hash ;
588
- } ) ;
589
-
590
- if ( dsoIdx == - 1 ) {
591
- throw new InvalidOperationException ( $ "Internal error: DSO entry in JNI preload list not found in the DSO cache list.") ;
592
- }
593
-
594
- indices . Add ( ( uint ) dsoIdx ) ;
595
- }
596
- indices . Sort ( ) ;
597
- }
598
-
599
546
void HashAndSortDSOCache ( LlvmIrVariable variable , LlvmIrModuleTarget target , object ? state )
600
547
{
601
548
var cache = variable . Value as List < StructureInstance < DSOCacheEntry > > ;
@@ -624,9 +571,10 @@ void HashAndSortDSOCache (LlvmIrVariable variable, LlvmIrModuleTarget target, ob
624
571
} ) ;
625
572
}
626
573
627
- DsoCacheState InitDSOCache ( )
574
+ ( List < StructureInstance < DSOCacheEntry > > dsoCache , List < StructureInstance < DSOCacheEntry > > aotDsoCache , LlvmIrStringBlob namesBlob )
575
+ InitDSOCache ( )
628
576
{
629
- var dsos = new List < ( string name , string nameLabel , bool ignore , ITaskItem item ) > ( ) ;
577
+ var dsos = new List < ( string name , string nameLabel , bool ignore ) > ( ) ;
630
578
var nameCache = new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) ;
631
579
632
580
foreach ( ITaskItem item in NativeLibraries ) {
@@ -640,11 +588,10 @@ DsoCacheState InitDSOCache ()
640
588
continue ;
641
589
}
642
590
643
- dsos . Add ( ( name , $ "dsoName{ dsos . Count . ToString ( CultureInfo . InvariantCulture ) } ", ELFHelper . IsEmptyAOTLibrary ( Log , item . ItemSpec ) , item ) ) ;
591
+ dsos . Add ( ( name , $ "dsoName{ dsos . Count . ToString ( CultureInfo . InvariantCulture ) } ", ELFHelper . IsEmptyAOTLibrary ( Log , item . ItemSpec ) ) ) ;
644
592
}
645
593
646
594
var dsoCache = new List < StructureInstance < DSOCacheEntry > > ( ) ;
647
- var jniPreloads = new List < DSOCacheEntry > ( ) ;
648
595
var aotDsoCache = new List < StructureInstance < DSOCacheEntry > > ( ) ;
649
596
var nameMutations = new List < string > ( ) ;
650
597
var dsoNamesBlob = new LlvmIrStringBlob ( ) ;
@@ -653,9 +600,6 @@ DsoCacheState InitDSOCache ()
653
600
string name = dsos [ i ] . name ;
654
601
( int nameOffset , _ ) = dsoNamesBlob . Add ( name ) ;
655
602
656
- bool isJniLibrary = ELFHelper . IsJniLibrary ( Log , dsos [ i ] . item . ItemSpec ) ;
657
- bool ignore = dsos [ i ] . ignore ;
658
-
659
603
nameMutations . Clear ( ) ;
660
604
AddNameMutations ( name ) ;
661
605
// All mutations point to the actual library name, but have hash of the mutated one
@@ -665,15 +609,10 @@ DsoCacheState InitDSOCache ()
665
609
RealName = name ,
666
610
667
611
hash = 0 , // Hash is arch-specific, we compute it before writing
668
- ignore = ignore ,
669
- is_jni_library = isJniLibrary ,
612
+ ignore = dsos [ i ] . ignore ,
670
613
name_index = ( uint ) nameOffset ,
671
614
} ;
672
615
673
- if ( entry . is_jni_library && entry . HashedName == name && ! DsoCacheJniPreloadIgnore . Contains ( name ) ) {
674
- jniPreloads . Add ( entry ) ;
675
- }
676
-
677
616
var item = new StructureInstance < DSOCacheEntry > ( dsoCacheEntryStructureInfo , entry ) ;
678
617
if ( name . StartsWith ( "libaot-" , StringComparison . OrdinalIgnoreCase ) ) {
679
618
aotDsoCache . Add ( item ) ;
@@ -683,12 +622,7 @@ DsoCacheState InitDSOCache ()
683
622
}
684
623
}
685
624
686
- return new DsoCacheState {
687
- DsoCache = dsoCache ,
688
- JniPreloadDSOs = jniPreloads ,
689
- AotDsoCache = aotDsoCache ,
690
- NamesBlob = dsoNamesBlob ,
691
- } ;
625
+ return ( dsoCache , aotDsoCache , dsoNamesBlob ) ;
692
626
693
627
void AddNameMutations ( string name )
694
628
{
0 commit comments