@@ -540,6 +540,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
540
540
Some ( cnum)
541
541
}
542
542
Err ( err) => {
543
+ debug ! ( "failed to resolve crate {} {:?}" , name, dep_kind) ;
543
544
let missing_core =
544
545
self . maybe_resolve_crate ( sym:: core, CrateDepKind :: Explicit , None ) . is_err ( ) ;
545
546
err. report ( self . sess , span, missing_core) ;
@@ -588,6 +589,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
588
589
match self . load ( & mut locator) ? {
589
590
Some ( res) => ( res, None ) ,
590
591
None => {
592
+ info ! ( "falling back to loading proc_macro" ) ;
591
593
dep_kind = CrateDepKind :: MacrosOnly ;
592
594
match self . load_proc_macro ( & mut locator, path_kind, host_hash) ? {
593
595
Some ( res) => res,
@@ -599,6 +601,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
599
601
600
602
match result {
601
603
( LoadResult :: Previous ( cnum) , None ) => {
604
+ info ! ( "library for `{}` was loaded previously" , name) ;
602
605
// When `private_dep` is none, it indicates the directly dependent crate. If it is
603
606
// not specified by `--extern` on command line parameters, it may be
604
607
// `private-dependency` when `register_crate` is called for the first time. Then it must be updated to
@@ -613,6 +616,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
613
616
Ok ( cnum)
614
617
}
615
618
( LoadResult :: Loaded ( library) , host_library) => {
619
+ info ! ( "register newly loaded library for `{}`" , name) ;
616
620
self . register_crate ( host_library, root, library, dep_kind, name, private_dep)
617
621
}
618
622
_ => panic ! ( ) ,
@@ -696,7 +700,25 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
696
700
stable_crate_id : StableCrateId ,
697
701
) -> Result < & ' static [ ProcMacro ] , CrateError > {
698
702
let sym_name = self . sess . generate_proc_macro_decls_symbol ( stable_crate_id) ;
699
- Ok ( unsafe { * load_symbol_from_dylib :: < * const & [ ProcMacro ] > ( path, & sym_name) ? } )
703
+ debug ! ( "trying to dlsym proc_macros {} for symbol `{}`" , path. display( ) , sym_name) ;
704
+
705
+ unsafe {
706
+ let result = load_symbol_from_dylib :: < * const & [ ProcMacro ] > ( path, & sym_name) ;
707
+ match result {
708
+ Ok ( result) => {
709
+ debug ! ( "loaded dlsym proc_macros {} for symbol `{}`" , path. display( ) , sym_name) ;
710
+ Ok ( * result)
711
+ }
712
+ Err ( err) => {
713
+ debug ! (
714
+ "failed to dlsym proc_macros {} for symbol `{}`" ,
715
+ path. display( ) ,
716
+ sym_name
717
+ ) ;
718
+ Err ( err. into ( ) )
719
+ }
720
+ }
721
+ }
700
722
}
701
723
702
724
fn inject_panic_runtime ( & mut self , krate : & ast:: Crate ) {
@@ -1141,6 +1163,29 @@ fn format_dlopen_err(e: &(dyn std::error::Error + 'static)) -> String {
1141
1163
e. sources ( ) . map ( |e| format ! ( ": {e}" ) ) . collect ( )
1142
1164
}
1143
1165
1166
+ fn attempt_load_dylib ( path : & Path ) -> Result < libloading:: Library , libloading:: Error > {
1167
+ #[ cfg( target_os = "aix" ) ]
1168
+ if let Some ( ext) = path. extension ( )
1169
+ && ext. eq ( "a" )
1170
+ {
1171
+ // On AIX, we ship all libraries as .a big_af archive
1172
+ // the expected format is lib<name>.a(libname.so) for the actual
1173
+ // dynamic library
1174
+ let library_name = path. file_stem ( ) . expect ( "expect a library name" ) ;
1175
+ let mut archive_member = OsString :: from ( "a(" ) ;
1176
+ archive_member. push ( library_name) ;
1177
+ archive_member. push ( ".so)" ) ;
1178
+ let new_path = path. with_extension ( archive_member) ;
1179
+
1180
+ // On AIX, we need RTLD_MEMBER to dlopen an archived shared
1181
+ let flags = libc:: RTLD_LAZY | libc:: RTLD_LOCAL | libc:: RTLD_MEMBER ;
1182
+ return unsafe { libloading:: os:: unix:: Library :: open ( Some ( & new_path) , flags) }
1183
+ . map ( |lib| lib. into ( ) ) ;
1184
+ }
1185
+
1186
+ unsafe { libloading:: Library :: new ( & path) }
1187
+ }
1188
+
1144
1189
// On Windows the compiler would sometimes intermittently fail to open the
1145
1190
// proc-macro DLL with `Error::LoadLibraryExW`. It is suspected that something in the
1146
1191
// system still holds a lock on the file, so we retry a few times before calling it
@@ -1151,7 +1196,8 @@ fn load_dylib(path: &Path, max_attempts: usize) -> Result<libloading::Library, S
1151
1196
let mut last_error = None ;
1152
1197
1153
1198
for attempt in 0 ..max_attempts {
1154
- match unsafe { libloading:: Library :: new ( & path) } {
1199
+ debug ! ( "Attempt to load proc-macro `{}`." , path. display( ) ) ;
1200
+ match attempt_load_dylib ( path) {
1155
1201
Ok ( lib) => {
1156
1202
if attempt > 0 {
1157
1203
debug ! (
@@ -1165,6 +1211,7 @@ fn load_dylib(path: &Path, max_attempts: usize) -> Result<libloading::Library, S
1165
1211
Err ( err) => {
1166
1212
// Only try to recover from this specific error.
1167
1213
if !matches ! ( err, libloading:: Error :: LoadLibraryExW { .. } ) {
1214
+ debug ! ( "Failed to load proc-macro `{}`. Not retrying" , path. display( ) ) ;
1168
1215
let err = format_dlopen_err ( & err) ;
1169
1216
// We include the path of the dylib in the error ourselves, so
1170
1217
// if it's in the error, we strip it.
0 commit comments