Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lld/ELF/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1744,8 +1744,10 @@ createBitcodeSymbol(Symbol *&sym, const std::vector<bool> &keptComdats,
uint8_t type = objSym.isTLS() ? STT_TLS : STT_NOTYPE;
uint8_t visibility = mapVisibility(objSym.getVisibility());

// Symbols can be duplicated in bitcode files because of '#include' and
// linkonce_odr. Use unique_saver to save symbol names for de-duplication.
if (!sym)
sym = symtab.insert(saver().save(objSym.getName()));
sym = symtab.insert(unique_saver().save(objSym.getName()));

int c = objSym.getComdatIndex();
if (objSym.isUndefined() || (c != -1 && !keptComdats[c])) {
Expand Down Expand Up @@ -1797,7 +1799,9 @@ void BitcodeFile::parseLazy() {
symbols = std::make_unique<Symbol *[]>(numSymbols);
for (auto [i, irSym] : llvm::enumerate(obj->symbols()))
if (!irSym.isUndefined()) {
auto *sym = symtab.insert(saver().save(irSym.getName()));
// Symbols can be duplicated in bitcode files because of '#include' and
// linkonce_odr. Use unique_saver to save symbol names for de-duplication.
auto *sym = symtab.insert(unique_saver().save(irSym.getName()));
sym->resolve(LazySymbol{*this});
symbols[i] = sym;
}
Expand Down
8 changes: 7 additions & 1 deletion lld/include/lld/Common/CommonLinkerContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class CommonLinkerContext {

llvm::BumpPtrAllocator bAlloc;
llvm::StringSaver saver{bAlloc};
llvm::UniqueStringSaver unique_saver{bAlloc};
llvm::DenseMap<void *, SpecificAllocBase *> instances;

ErrorHandler e;
Expand All @@ -54,8 +55,13 @@ template <typename T = CommonLinkerContext> T &context() {

bool hasContext();

inline llvm::StringSaver &saver() { return context().saver; }
inline llvm::BumpPtrAllocator &bAlloc() { return context().bAlloc; }
inline llvm::StringSaver &saver() { return context().saver; }
inline llvm::UniqueStringSaver &unique_saver() {
// FIXME: Look into other places where duplications are common in saved
// strings and unique saver make sense.
return context().unique_saver;
}
} // namespace lld

#endif