@@ -2729,6 +2729,7 @@ bool DWARFLinker::registerModuleReference(const DWARFDie &CUDie,
27292729 LinkContext &Context,
27302730 ObjFileLoaderTy Loader,
27312731 CompileUnitHandlerTy OnCUDieLoaded,
2732+ CASLoaderTy CASLoader,
27322733 unsigned Indent) {
27332734 std::string PCMFile = getPCMFile (CUDie, Options.ObjectPrefixMap );
27342735 std::pair<bool , bool > IsClangModuleRef =
@@ -2748,47 +2749,62 @@ bool DWARFLinker::registerModuleReference(const DWARFDie &CUDie,
27482749 ClangModules.insert ({PCMFile, getDwoId (CUDie)});
27492750
27502751 if (Error E = loadClangModule (Loader, CUDie, PCMFile, Context, OnCUDieLoaded,
2751- Indent + 2 )) {
2752+ CASLoader, Indent + 2 )) {
27522753 consumeError (std::move (E));
27532754 return false ;
27542755 }
27552756 return true ;
27562757}
27572758
2758- Error DWARFLinker::loadClangModule (
2759- ObjFileLoaderTy Loader, const DWARFDie &CUDie, const std::string &PCMFile,
2760- LinkContext &Context, CompileUnitHandlerTy OnCUDieLoaded, unsigned Indent) {
2759+ Error DWARFLinker::loadClangModule (ObjFileLoaderTy Loader,
2760+ const DWARFDie &CUDie,
2761+ const std::string &PCMFile,
2762+ LinkContext &Context,
2763+ CompileUnitHandlerTy OnCUDieLoaded,
2764+ CASLoaderTy CASLoader, unsigned Indent) {
27612765
27622766 uint64_t DwoId = getDwoId (CUDie);
27632767 std::string ModuleName = dwarf::toString (CUDie.find (dwarf::DW_AT_name), " " );
27642768
2765- // / Using a SmallString<0> because loadClangModule() is recursive.
2766- SmallString<0 > Path (Options.PrependPath );
2767- if (sys::path::is_relative (PCMFile))
2768- resolveRelativeObjectPath (Path, CUDie);
2769- sys::path::append (Path, PCMFile);
2770- // Don't use the cached binary holder because we have no thread-safety
2771- // guarantee and the lifetime is limited.
2772-
2773- if (Loader == nullptr ) {
2774- reportError (" Could not load clang module: loader is not specified.\n " ,
2775- Context.File );
2776- return Error::success ();
2777- }
2769+ DWARFFile *PCM = nullptr ;
2770+ if (CASLoader) {
2771+ auto LoadPCM = CASLoader (PCMFile, Context.File .FileName );
2772+ if (!LoadPCM)
2773+ return LoadPCM.takeError ();
2774+ PCM = *LoadPCM;
2775+ }
2776+
2777+ if (!PCM) {
2778+ // / Using a SmallString<0> because loadClangModule() is recursive.
2779+ SmallString<0 > Path (Options.PrependPath );
2780+ if (sys::path::is_relative (PCMFile))
2781+ resolveRelativeObjectPath (Path, CUDie);
2782+ sys::path::append (Path, PCMFile);
2783+ // Don't use the cached binary holder because we have no thread-safety
2784+ // guarantee and the lifetime is limited.
2785+
2786+ if (Loader == nullptr ) {
2787+ reportError (" Could not load clang module: loader is not specified.\n " ,
2788+ Context.File );
2789+ return Error::success ();
2790+ }
27782791
2779- auto ErrOrObj = Loader (Context.File .FileName , Path);
2780- if (!ErrOrObj)
2781- return Error::success ();
2792+ auto ErrOrObj = Loader (Context.File .FileName , Path);
2793+ if (!ErrOrObj)
2794+ return Error::success ();
2795+
2796+ PCM = &*ErrOrObj;
2797+ }
27822798
27832799 std::unique_ptr<CompileUnit> Unit;
2784- for (const auto &CU : ErrOrObj ->Dwarf ->compile_units ()) {
2800+ for (const auto &CU : PCM ->Dwarf ->compile_units ()) {
27852801 OnCUDieLoaded (*CU);
27862802 // Recursively get all modules imported by this one.
27872803 auto ChildCUDie = CU->getUnitDIE ();
27882804 if (!ChildCUDie)
27892805 continue ;
27902806 if (!registerModuleReference (ChildCUDie, Context, Loader, OnCUDieLoaded,
2791- Indent)) {
2807+ CASLoader, Indent)) {
27922808 if (Unit) {
27932809 std::string Err =
27942810 (PCMFile +
@@ -2818,7 +2834,7 @@ Error DWARFLinker::loadClangModule(
28182834 }
28192835
28202836 if (Unit)
2821- Context.ModuleUnits .emplace_back (RefModuleUnit{*ErrOrObj , std::move (Unit)});
2837+ Context.ModuleUnits .emplace_back (RefModuleUnit{*PCM , std::move (Unit)});
28222838
28232839 return Error::success ();
28242840}
@@ -2925,7 +2941,8 @@ void DWARFLinker::copyInvariantDebugSection(DWARFContext &Dwarf) {
29252941}
29262942
29272943void DWARFLinker::addObjectFile (DWARFFile &File, ObjFileLoaderTy Loader,
2928- CompileUnitHandlerTy OnCUDieLoaded) {
2944+ CompileUnitHandlerTy OnCUDieLoaded,
2945+ CASLoaderTy CASLoader) {
29292946 ObjectContexts.emplace_back (LinkContext (File));
29302947
29312948 if (ObjectContexts.back ().File .Dwarf ) {
@@ -2940,7 +2957,7 @@ void DWARFLinker::addObjectFile(DWARFFile &File, ObjFileLoaderTy Loader,
29402957
29412958 if (!LLVM_UNLIKELY (Options.Update ))
29422959 registerModuleReference (CUDie, ObjectContexts.back (), Loader,
2943- OnCUDieLoaded);
2960+ OnCUDieLoaded, CASLoader );
29442961 }
29452962 }
29462963}
0 commit comments