[lld] r351898 - COFF, ELF: Adjust ICF hash computation to account for self relocations.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 22 15:51:35 PST 2019


Author: pcc
Date: Tue Jan 22 15:51:35 2019
New Revision: 351898

URL: http://llvm.org/viewvc/llvm-project?rev=351898&view=rev
Log:
COFF, ELF: Adjust ICF hash computation to account for self relocations.

It turns out that sections in PGO instrumented object files on Windows
contain a large number of relocations pointing to themselves. With
r347429 this can cause many sections to receive the same hash (usually
zero) as a result of a section's hash being xor'ed with itself.

This patch causes the COFF and ELF linkers to avoid this problem
by adding the hash of the relocated section instead of xor'ing it.
On my machine this causes the regressing test case
provided by Mozilla to terminate in 2m41s.

Differential Revision: https://reviews.llvm.org/D56955

Modified:
    lld/trunk/COFF/ICF.cpp
    lld/trunk/ELF/ICF.cpp

Modified: lld/trunk/COFF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/ICF.cpp?rev=351898&r1=351897&r2=351898&view=diff
==============================================================================
--- lld/trunk/COFF/ICF.cpp (original)
+++ lld/trunk/COFF/ICF.cpp Tue Jan 22 15:51:35 2019
@@ -271,7 +271,7 @@ void ICF::run(ArrayRef<Chunk *> Vec) {
     uint32_t Hash = SC->Class[1];
     for (Symbol *B : SC->symbols())
       if (auto *Sym = dyn_cast_or_null<DefinedRegular>(B))
-        Hash ^= Sym->getChunk()->Class[1];
+        Hash += Sym->getChunk()->Class[1];
     // Set MSB to 1 to avoid collisions with non-hash classs.
     SC->Class[0] = Hash | (1U << 31);
   });

Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=351898&r1=351897&r2=351898&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Tue Jan 22 15:51:35 2019
@@ -431,7 +431,7 @@ static void combineRelocHashes(InputSect
     Symbol &S = IS->template getFile<ELFT>()->getRelocTargetSym(Rel);
     if (auto *D = dyn_cast<Defined>(&S))
       if (auto *RelSec = dyn_cast_or_null<InputSection>(D->Section))
-        Hash ^= RelSec->Class[1];
+        Hash += RelSec->Class[1];
   }
   // Set MSB to 1 to avoid collisions with non-hash IDs.
   IS->Class[0] = Hash | (1U << 31);




More information about the llvm-commits mailing list