@@ -2611,6 +2611,7 @@ bool DWARFLinker::registerModuleReference(const DWARFDie &CUDie,
26112611 LinkContext &Context,
26122612 ObjFileLoaderTy Loader,
26132613 CompileUnitHandlerTy OnCUDieLoaded,
2614+ CASLoaderTy CASLoader,
26142615 unsigned Indent) {
26152616 std::string PCMFile = getPCMFile (CUDie, Options.ObjectPrefixMap );
26162617 std::pair<bool , bool > IsClangModuleRef =
@@ -2630,47 +2631,62 @@ bool DWARFLinker::registerModuleReference(const DWARFDie &CUDie,
26302631 ClangModules.insert ({PCMFile, getDwoId (CUDie)});
26312632
26322633 if (Error E = loadClangModule (Loader, CUDie, PCMFile, Context, OnCUDieLoaded,
2633- Indent + 2 )) {
2634+ CASLoader, Indent + 2 )) {
26342635 consumeError (std::move (E));
26352636 return false ;
26362637 }
26372638 return true ;
26382639}
26392640
2640- Error DWARFLinker::loadClangModule (
2641- ObjFileLoaderTy Loader, const DWARFDie &CUDie, const std::string &PCMFile,
2642- LinkContext &Context, CompileUnitHandlerTy OnCUDieLoaded, unsigned Indent) {
2641+ Error DWARFLinker::loadClangModule (ObjFileLoaderTy Loader,
2642+ const DWARFDie &CUDie,
2643+ const std::string &PCMFile,
2644+ LinkContext &Context,
2645+ CompileUnitHandlerTy OnCUDieLoaded,
2646+ CASLoaderTy CASLoader, unsigned Indent) {
26432647
26442648 uint64_t DwoId = getDwoId (CUDie);
26452649 std::string ModuleName = dwarf::toString (CUDie.find (dwarf::DW_AT_name), " " );
26462650
2647- // / Using a SmallString<0> because loadClangModule() is recursive.
2648- SmallString<0 > Path (Options.PrependPath );
2649- if (sys::path::is_relative (PCMFile))
2650- resolveRelativeObjectPath (Path, CUDie);
2651- sys::path::append (Path, PCMFile);
2652- // Don't use the cached binary holder because we have no thread-safety
2653- // guarantee and the lifetime is limited.
2654-
2655- if (Loader == nullptr ) {
2656- reportError (" Could not load clang module: loader is not specified.\n " ,
2657- Context.File );
2658- return Error::success ();
2659- }
2651+ DWARFFile *PCM = nullptr ;
2652+ if (CASLoader) {
2653+ auto LoadPCM = CASLoader (PCMFile, Context.File .FileName );
2654+ if (!LoadPCM)
2655+ return LoadPCM.takeError ();
2656+ PCM = *LoadPCM;
2657+ }
2658+
2659+ if (!PCM) {
2660+ // / Using a SmallString<0> because loadClangModule() is recursive.
2661+ SmallString<0 > Path (Options.PrependPath );
2662+ if (sys::path::is_relative (PCMFile))
2663+ resolveRelativeObjectPath (Path, CUDie);
2664+ sys::path::append (Path, PCMFile);
2665+ // Don't use the cached binary holder because we have no thread-safety
2666+ // guarantee and the lifetime is limited.
2667+
2668+ if (Loader == nullptr ) {
2669+ reportError (" Could not load clang module: loader is not specified.\n " ,
2670+ Context.File );
2671+ return Error::success ();
2672+ }
26602673
2661- auto ErrOrObj = Loader (Context.File .FileName , Path);
2662- if (!ErrOrObj)
2663- return Error::success ();
2674+ auto ErrOrObj = Loader (Context.File .FileName , Path);
2675+ if (!ErrOrObj)
2676+ return Error::success ();
2677+
2678+ PCM = &*ErrOrObj;
2679+ }
26642680
26652681 std::unique_ptr<CompileUnit> Unit;
2666- for (const auto &CU : ErrOrObj ->Dwarf ->compile_units ()) {
2682+ for (const auto &CU : PCM ->Dwarf ->compile_units ()) {
26672683 OnCUDieLoaded (*CU);
26682684 // Recursively get all modules imported by this one.
26692685 auto ChildCUDie = CU->getUnitDIE ();
26702686 if (!ChildCUDie)
26712687 continue ;
26722688 if (!registerModuleReference (ChildCUDie, Context, Loader, OnCUDieLoaded,
2673- Indent)) {
2689+ CASLoader, Indent)) {
26742690 if (Unit) {
26752691 std::string Err =
26762692 (PCMFile +
@@ -2700,7 +2716,7 @@ Error DWARFLinker::loadClangModule(
27002716 }
27012717
27022718 if (Unit)
2703- Context.ModuleUnits .emplace_back (RefModuleUnit{*ErrOrObj , std::move (Unit)});
2719+ Context.ModuleUnits .emplace_back (RefModuleUnit{*PCM , std::move (Unit)});
27042720
27052721 return Error::success ();
27062722}
@@ -2807,7 +2823,8 @@ void DWARFLinker::copyInvariantDebugSection(DWARFContext &Dwarf) {
28072823}
28082824
28092825void DWARFLinker::addObjectFile (DWARFFile &File, ObjFileLoaderTy Loader,
2810- CompileUnitHandlerTy OnCUDieLoaded) {
2826+ CompileUnitHandlerTy OnCUDieLoaded,
2827+ CASLoaderTy CASLoader) {
28112828 ObjectContexts.emplace_back (LinkContext (File));
28122829
28132830 if (ObjectContexts.back ().File .Dwarf ) {
@@ -2822,7 +2839,7 @@ void DWARFLinker::addObjectFile(DWARFFile &File, ObjFileLoaderTy Loader,
28222839
28232840 if (!LLVM_UNLIKELY (Options.Update ))
28242841 registerModuleReference (CUDie, ObjectContexts.back (), Loader,
2825- OnCUDieLoaded);
2842+ OnCUDieLoaded, CASLoader );
28262843 }
28272844 }
28282845}
0 commit comments