static void addModule(LTO &Lto, claimed_file &F, const void *View) { MemoryBufferRef BufferRef(StringRef((const char *)View, F.filesize), F.name); Expected<std::unique_ptr<InputFile>> ObjOrErr = InputFile::create(BufferRef); if (!ObjOrErr) message(LDPL_FATAL, "Could not read bitcode from file : %s", toString(ObjOrErr.takeError()).c_str()); unsigned SymNum = 0; std::vector<SymbolResolution> Resols(F.syms.size()); for (ld_plugin_symbol &Sym : F.syms) { SymbolResolution &R = Resols[SymNum++]; ld_plugin_symbol_resolution Resolution = (ld_plugin_symbol_resolution)Sym.resolution; ResolutionInfo &Res = ResInfo[Sym.name]; switch (Resolution) { case LDPR_UNKNOWN: llvm_unreachable("Unexpected resolution"); case LDPR_RESOLVED_IR: case LDPR_RESOLVED_EXEC: case LDPR_RESOLVED_DYN: case LDPR_PREEMPTED_IR: case LDPR_PREEMPTED_REG: case LDPR_UNDEF: break; case LDPR_PREVAILING_DEF_IRONLY: R.Prevailing = true; break; case LDPR_PREVAILING_DEF: R.Prevailing = true; R.VisibleToRegularObj = true; break; case LDPR_PREVAILING_DEF_IRONLY_EXP: R.Prevailing = true; if (!Res.CanOmitFromDynSym) R.VisibleToRegularObj = true; break; } if (Resolution != LDPR_RESOLVED_DYN && Resolution != LDPR_UNDEF && (IsExecutable || !Res.DefaultVisibility)) R.FinalDefinitionInLinkageUnit = true; freeSymName(Sym); } check(Lto.add(std::move(*ObjOrErr), Resols), std::string("Failed to link module ") + F.name); }
static void addModule(LTO &Lto, claimed_file &F, const void *View, StringRef Filename) { MemoryBufferRef BufferRef(StringRef((const char *)View, F.filesize), Filename); Expected<std::unique_ptr<InputFile>> ObjOrErr = InputFile::create(BufferRef); if (!ObjOrErr) message(LDPL_FATAL, "Could not read bitcode from file : %s", toString(ObjOrErr.takeError()).c_str()); unsigned SymNum = 0; std::unique_ptr<InputFile> Input = std::move(ObjOrErr.get()); auto InputFileSyms = Input->symbols(); assert(InputFileSyms.size() == F.syms.size()); std::vector<SymbolResolution> Resols(F.syms.size()); for (ld_plugin_symbol &Sym : F.syms) { const InputFile::Symbol &InpSym = InputFileSyms[SymNum]; SymbolResolution &R = Resols[SymNum++]; ld_plugin_symbol_resolution Resolution = (ld_plugin_symbol_resolution)Sym.resolution; ResolutionInfo &Res = ResInfo[Sym.name]; switch (Resolution) { case LDPR_UNKNOWN: llvm_unreachable("Unexpected resolution"); case LDPR_RESOLVED_IR: case LDPR_RESOLVED_EXEC: case LDPR_RESOLVED_DYN: case LDPR_PREEMPTED_IR: case LDPR_PREEMPTED_REG: case LDPR_UNDEF: break; case LDPR_PREVAILING_DEF_IRONLY: R.Prevailing = true; break; case LDPR_PREVAILING_DEF: R.Prevailing = true; R.VisibleToRegularObj = true; break; case LDPR_PREVAILING_DEF_IRONLY_EXP: R.Prevailing = true; if (!Res.CanOmitFromDynSym) R.VisibleToRegularObj = true; break; } // If the symbol has a C identifier section name, we need to mark // it as visible to a regular object so that LTO will keep it around // to ensure the linker generates special __start_<secname> and // __stop_<secname> symbols which may be used elsewhere. if (isValidCIdentifier(InpSym.getSectionName())) R.VisibleToRegularObj = true; if (Resolution != LDPR_RESOLVED_DYN && Resolution != LDPR_UNDEF && (IsExecutable || !Res.DefaultVisibility)) R.FinalDefinitionInLinkageUnit = true; freeSymName(Sym); } check(Lto.add(std::move(Input), Resols), std::string("Failed to link module ") + F.name); }