diff options
author | Fangrui Song <maskray@google.com> | 2018-06-11 19:42:57 +0000 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2018-06-11 19:42:57 +0000 |
commit | 2389a240d02bd8440995e2ad630958e1971ebec7 (patch) | |
tree | c21b97209c15ebe4a72dd65802ea8ebca5287d3a /lld/ELF/Relocations.cpp | |
parent | d1df7b7ee751206f6e9cee31ac003801376c938a (diff) | |
download | bcm5719-llvm-2389a240d02bd8440995e2ad630958e1971ebec7.tar.gz bcm5719-llvm-2389a240d02bd8440995e2ad630958e1971ebec7.zip |
[ELF] Fix copy relocation when two symbols share the same Symbol instance.
In glibc libc.so.6, the multiple versions of sys_errlist share the same Symbol instance. When sys_errlist is copy relocated, we would replace SharedSymbol with Defined in the first iteration of the following loop:
for (SharedSymbol *Sym : getSymbolsAt<ELFT>(SS))
Then in the second iteration, we think the symbol (which has been changed to Defined) is still SharedSymbol and screw up (the address ends up in the `Size` field).
llvm-svn: 334432
Diffstat (limited to 'lld/ELF/Relocations.cpp')
-rw-r--r-- | lld/ELF/Relocations.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 64b23ab87de..936371303b6 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/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 <algorithm> @@ -432,14 +433,14 @@ template <class ELFT> static bool isReadOnly(SharedSymbol &SS) { // // 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. +// Otherwise, they would refer to different places at runtime. template <class ELFT> -static std::vector<SharedSymbol *> getSymbolsAt(SharedSymbol &SS) { +static SmallSet<SharedSymbol *, 4> getSymbolsAt(SharedSymbol &SS) { typedef typename ELFT::Sym Elf_Sym; SharedFile<ELFT> &File = SS.getFile<ELFT>(); - std::vector<SharedSymbol *> Ret; + SmallSet<SharedSymbol *, 4> Ret; for (const Elf_Sym &S : File.getGlobalELFSyms()) { if (S.st_shndx == SHN_UNDEF || S.st_shndx == SHN_ABS || S.st_value != SS.Value) @@ -447,7 +448,7 @@ static std::vector<SharedSymbol *> getSymbolsAt(SharedSymbol &SS) { StringRef Name = check(S.getName(File.getStringTable())); Symbol *Sym = Symtab->find(Name); if (auto *Alias = dyn_cast_or_null<SharedSymbol>(Sym)) - Ret.push_back(Alias); + Ret.insert(Alias); } return Ret; } |