Index: ELF/Relocations.cpp =================================================================== --- ELF/Relocations.cpp +++ ELF/Relocations.cpp @@ -52,6 +52,7 @@ #include "Thunks.h" #include "lld/Common/Memory.h" #include "lld/Common/Strings.h" +#include "llvm/ADT/SmallSet.h" #include "llvm/Support/Endian.h" #include "llvm/Support/raw_ostream.h" #include @@ -444,21 +445,25 @@ // If two or more symbols are at the same offset, and at least one of // them are copied by a copy relocation, all of them need to be copied. // Otherwise, they would refer different places at runtime. +// Use a set so that if two or more symbols share the same address, we only copy +// one but with the largest size. template -static std::vector getSymbolsAt(SharedSymbol &SS) { +static SmallSet getSymbolsAt(SharedSymbol &SS) { typedef typename ELFT::Sym Elf_Sym; SharedFile &File = SS.getFile(); - std::vector Ret; + SmallSet Ret; for (const Elf_Sym &S : File.getGlobalELFSyms()) { if (S.st_shndx == SHN_UNDEF || S.st_shndx == SHN_ABS || S.st_value != SS.Value) continue; StringRef Name = check(S.getName(File.getStringTable())); Symbol *Sym = Symtab->find(Name); - if (auto *Alias = dyn_cast_or_null(Sym)) - Ret.push_back(Alias); + if (auto *Alias = dyn_cast_or_null(Sym)) { + SharedSymbol* SSym = *Ret.insert(Alias).first; + SSym->Size = std::max(SSym->Size, Alias->Size); + } } return Ret; }