@@ -540,6 +540,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
540540 Some ( cnum)
541541 }
542542 Err ( err) => {
543+ debug ! ( "failed to resolve crate {} {:?}" , name, dep_kind) ;
543544 let missing_core =
544545 self . maybe_resolve_crate ( sym:: core, CrateDepKind :: Explicit , None ) . is_err ( ) ;
545546 err. report ( self . sess , span, missing_core) ;
@@ -588,6 +589,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
588589 match self . load ( & mut locator) ? {
589590 Some ( res) => ( res, None ) ,
590591 None => {
592+ info ! ( "falling back to loading proc_macro" ) ;
591593 dep_kind = CrateDepKind :: MacrosOnly ;
592594 match self . load_proc_macro ( & mut locator, path_kind, host_hash) ? {
593595 Some ( res) => res,
@@ -599,6 +601,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
599601
600602 match result {
601603 ( LoadResult :: Previous ( cnum) , None ) => {
604+ info ! ( "library for `{}` was loaded previously" , name) ;
602605 // When `private_dep` is none, it indicates the directly dependent crate. If it is
603606 // not specified by `--extern` on command line parameters, it may be
604607 // `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> {
613616 Ok ( cnum)
614617 }
615618 ( LoadResult :: Loaded ( library) , host_library) => {
619+ info ! ( "register newly loaded library for `{}`" , name) ;
616620 self . register_crate ( host_library, root, library, dep_kind, name, private_dep)
617621 }
618622 _ => panic ! ( ) ,
@@ -696,7 +700,25 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
696700 stable_crate_id : StableCrateId ,
697701 ) -> Result < & ' static [ ProcMacro ] , CrateError > {
698702 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+ }
700722 }
701723
702724 fn inject_panic_runtime ( & mut self , krate : & ast:: Crate ) {
@@ -1141,6 +1163,29 @@ fn format_dlopen_err(e: &(dyn std::error::Error + 'static)) -> String {
11411163 e. sources ( ) . map ( |e| format ! ( ": {e}" ) ) . collect ( )
11421164}
11431165
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+
11441189// On Windows the compiler would sometimes intermittently fail to open the
11451190// proc-macro DLL with `Error::LoadLibraryExW`. It is suspected that something in the
11461191// 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
11511196 let mut last_error = None ;
11521197
11531198 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) {
11551201 Ok ( lib) => {
11561202 if attempt > 0 {
11571203 debug ! (
@@ -1165,6 +1211,7 @@ fn load_dylib(path: &Path, max_attempts: usize) -> Result<libloading::Library, S
11651211 Err ( err) => {
11661212 // Only try to recover from this specific error.
11671213 if !matches ! ( err, libloading:: Error :: LoadLibraryExW { .. } ) {
1214+ debug ! ( "Failed to load proc-macro `{}`. Not retrying" , path. display( ) ) ;
11681215 let err = format_dlopen_err ( & err) ;
11691216 // We include the path of the dylib in the error ourselves, so
11701217 // if it's in the error, we strip it.
0 commit comments