diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp index 3e3506e05d74b9..4aca707348b2d1 100644 --- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp +++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp @@ -142,6 +142,9 @@ static SmallVector TempFiles; /// Codegen flags for LTO backend. static codegen::RegisterCodeGenFlags CodeGenFlags; +/// Static buffer to hold StringRef values. +static BumpPtrAllocator Alloc; + /// Magic section string that marks the existence of offloading data. The /// section string will be formatted as `.llvm.offloading..`. #define OFFLOAD_SECTION_MAGIC_STR ".llvm.offloading." @@ -861,8 +864,9 @@ Error linkBitcodeFiles(SmallVectorImpl &InputFiles, SmallVector, 4> SavedBuffers; SmallVector, 4> BitcodeFiles; SmallVector NewInputFiles; - StringMap UsedInRegularObj; - StringMap UsedInSharedLib; + DenseSet UsedInRegularObj; + DenseSet UsedInSharedLib; + StringSaver Saver(Alloc); // Search for bitcode files in the input and create an LTO input file. If it // is not a bitcode file, scan its symbol table for symbols we need to @@ -888,9 +892,9 @@ Error linkBitcodeFiles(SmallVectorImpl &InputFiles, // Record if we've seen these symbols in any object or shared libraries. if ((*ObjFile)->isRelocatableObject()) - UsedInRegularObj[*Name] = true; + UsedInRegularObj.insert(Saver.save(*Name)); else - UsedInSharedLib[*Name] = true; + UsedInSharedLib.insert(Saver.save(*Name)); } } else { Expected> InputFileOrErr = @@ -950,14 +954,15 @@ Error linkBitcodeFiles(SmallVectorImpl &InputFiles, // We will use this as the prevailing symbol definition in LTO unless // it is undefined or another definition has already been used. Res.Prevailing = - !Sym.isUndefined() && PrevailingSymbols.insert(Sym.getName()).second; + !Sym.isUndefined() && + PrevailingSymbols.insert(Saver.save(Sym.getName())).second; // We need LTO to preseve the following global symbols: // 1) Symbols used in regular objects. // 2) Sections that will be given a __start/__stop symbol. - // 3) Prevailing symbols that are needed visibile to external libraries. + // 3) Prevailing symbols that are needed visible to external libraries. Res.VisibleToRegularObj = - UsedInRegularObj[Sym.getName()] || + UsedInRegularObj.contains(Sym.getName()) || isValidCIdentifier(Sym.getSectionName()) || (Res.Prevailing && (Sym.getVisibility() != GlobalValue::HiddenVisibility && @@ -967,7 +972,7 @@ Error linkBitcodeFiles(SmallVectorImpl &InputFiles, // referenced by other files. Res.ExportDynamic = Sym.getVisibility() != GlobalValue::HiddenVisibility && - (UsedInSharedLib[Sym.getName()] || + (UsedInSharedLib.contains(Sym.getName()) || !Sym.canBeOmittedFromSymbolTable()); // The final definition will reside in this linkage unit if the symbol is