[lld] r338110 - Revert "ELF: Make --print-icf-sections output deterministic."

Ilya Biryukov via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 27 02:01:03 PDT 2018


Author: ibiryukov
Date: Fri Jul 27 02:01:03 2018
New Revision: 338110

URL: http://llvm.org/viewvc/llvm-project?rev=338110&view=rev
Log:
Revert "ELF: Make --print-icf-sections output deterministic."

This reverts commit r338088. To unbreak our integrate.
The resulting lld output is different if compiled with '-funsigned-char'.

Modified:
    lld/trunk/ELF/ICF.cpp
    lld/trunk/test/ELF/icf-safe.s

Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=338110&r1=338109&r2=338110&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Fri Jul 27 02:01:03 2018
@@ -80,10 +80,9 @@
 #include "SyntheticSections.h"
 #include "Writer.h"
 #include "lld/Common/Threads.h"
-#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/Hashing.h"
 #include "llvm/BinaryFormat/ELF.h"
 #include "llvm/Object/ELF.h"
-#include "llvm/Support/xxhash.h"
 #include <algorithm>
 #include <atomic>
 
@@ -156,6 +155,12 @@ private:
 };
 }
 
+// Returns a hash value for S. Note that the information about
+// relocation targets is not included in the hash value.
+template <class ELFT> static uint32_t getHash(InputSection *S) {
+  return hash_combine(S->Flags, S->getSize(), S->NumRelocations, S->Data);
+}
+
 // Returns true if section S is subject of ICF.
 static bool isEligible(InputSection *S) {
   if (!S->Live || S->KeepUnique || !(S->Flags & SHF_ALLOC))
@@ -436,7 +441,7 @@ template <class ELFT> void ICF<ELFT>::ru
   // Initially, we use hash values to partition sections.
   parallelForEach(Sections, [&](InputSection *S) {
     // Set MSB to 1 to avoid collisions with non-hash IDs.
-    S->Class[0] = xxHash64(toStringRef(S->Data)) | (1U << 31);
+    S->Class[0] = getHash<ELFT>(S) | (1U << 31);
   });
 
   // From now on, sections in Sections vector are ordered so that sections

Modified: lld/trunk/test/ELF/icf-safe.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/icf-safe.s?rev=338110&r1=338109&r2=338110&view=diff
==============================================================================
--- lld/trunk/test/ELF/icf-safe.s (original)
+++ lld/trunk/test/ELF/icf-safe.s Fri Jul 27 02:01:03 2018
@@ -10,6 +10,10 @@
 # RUN: ld.lld %t1.o %t2.o -o %t2 --icf=all --print-icf-sections --export-dynamic | FileCheck --check-prefix=ALL-EXPORT %s
 # RUN: ld.lld %t1copy.o -o %t4 --icf=safe 2>&1 | FileCheck --check-prefix=OBJCOPY %s
 
+# CHECK-NOT: selected section {{.*}}:(.rodata.l1)
+# CHECK: selected section {{.*}}:(.rodata.l3)
+# CHECK:   removing identical section {{.*}}:(.rodata.l4)
+
 # CHECK-NOT: selected section {{.*}}:(.text.f1)
 # CHECK: selected section {{.*}}:(.text.f3)
 # CHECK:   removing identical section {{.*}}:(.text.f4)
@@ -18,10 +22,6 @@
 # CHECK: selected section {{.*}}:(.rodata.h3)
 # CHECK:   removing identical section {{.*}}:(.rodata.h4)
 
-# CHECK-NOT: selected section {{.*}}:(.rodata.l1)
-# CHECK: selected section {{.*}}:(.rodata.l3)
-# CHECK:   removing identical section {{.*}}:(.rodata.l4)
-
 # CHECK-NOT: selected section {{.*}}:(.rodata.g1)
 # CHECK: selected section {{.*}}:(.rodata.g3)
 # CHECK:   removing identical section {{.*}}:(.rodata.g4)
@@ -30,21 +30,21 @@
 
 # With --icf=all address-significance implies keep-unique only for rodata, not
 # text.
+# ALL-NOT: selected section {{.*}}:(.rodata.l1)
+# ALL: selected section {{.*}}:(.rodata.l3)
+# ALL:   removing identical section {{.*}}:(.rodata.l4)
+
 # ALL: selected section {{.*}}:(.text.f3)
 # ALL:   removing identical section {{.*}}:(.text.f4)
 
-# ALL-NOT: selected section {{.*}}:(.rodata.h1)
-# ALL: selected section {{.*}}:(.rodata.h3)
-# ALL:   removing identical section {{.*}}:(.rodata.h4)
-
 # ALL: selected section {{.*}}:(.text.f1)
 # ALL:   removing identical section {{.*}}:(.text.f2)
 # ALL:   removing identical section {{.*}}:(.text.non_addrsig1)
 # ALL:   removing identical section {{.*}}:(.text.non_addrsig2)
 
-# ALL-NOT: selected section {{.*}}:(.rodata.l1)
-# ALL: selected section {{.*}}:(.rodata.l3)
-# ALL:   removing identical section {{.*}}:(.rodata.l4)
+# ALL-NOT: selected section {{.*}}:(.rodata.h1)
+# ALL: selected section {{.*}}:(.rodata.h3)
+# ALL:   removing identical section {{.*}}:(.rodata.h4)
 
 # ALL-NOT: selected section {{.*}}:(.rodata.g1)
 # ALL: selected section {{.*}}:(.rodata.g3)
@@ -58,36 +58,36 @@
 # STB_LOCAL or STV_HIDDEN symbols. The dynsym entries should have prevented
 # anything else from being merged.
 # EXPORT-NOT: selected section
+# EXPORT: selected section {{.*}}:(.rodata.l3)
+# EXPORT:   removing identical section {{.*}}:(.rodata.l4)
+# EXPORT-NOT: selected section
 # EXPORT: selected section {{.*}}:(.rodata.h3)
 # EXPORT:   removing identical section {{.*}}:(.rodata.h4)
 # EXPORT-NOT: selected section
 # EXPORT: selected section {{.*}}:(.text)
 # EXPORT:   removing identical section {{.*}}:(.text)
 # EXPORT-NOT: selected section
-# EXPORT: selected section {{.*}}:(.rodata.l3)
-# EXPORT:   removing identical section {{.*}}:(.rodata.l4)
-# EXPORT-NOT: selected section
 
 # If --icf=all is specified when exporting we can also merge the exported text
 # sections, but not the exported rodata.
 # ALL-EXPORT-NOT: selected section
+# ALL-EXPORT: selected section {{.*}}:(.rodata.l3)
+# ALL-EXPORT:   removing identical section {{.*}}:(.rodata.l4)
+# ALL-EXPORT-NOT: selected section
 # ALL-EXPORT: selected section {{.*}}:(.text.f3)
 # ALL-EXPORT:   removing identical section {{.*}}:(.text.f4)
 # ALL-EXPORT-NOT: selected section
-# ALL-EXPORT: selected section {{.*}}:(.rodata.h3)
-# ALL-EXPORT:   removing identical section {{.*}}:(.rodata.h4)
-# ALL-EXPORT-NOT: selected section
 # ALL-EXPORT: selected section {{.*}}:(.text.f1)
 # ALL-EXPORT:   removing identical section {{.*}}:(.text.f2)
 # ALL-EXPORT:   removing identical section {{.*}}:(.text.non_addrsig1)
 # ALL-EXPORT:   removing identical section {{.*}}:(.text.non_addrsig2)
 # ALL-EXPORT-NOT: selected section
+# ALL-EXPORT: selected section {{.*}}:(.rodata.h3)
+# ALL-EXPORT:   removing identical section {{.*}}:(.rodata.h4)
+# ALL-EXPORT-NOT: selected section
 # ALL-EXPORT: selected section {{.*}}:(.text)
 # ALL-EXPORT:   removing identical section {{.*}}:(.text)
 # ALL-EXPORT-NOT: selected section
-# ALL-EXPORT: selected section {{.*}}:(.rodata.l3)
-# ALL-EXPORT:   removing identical section {{.*}}:(.rodata.l4)
-# ALL-EXPORT-NOT: selected section
 
 # OBJCOPY: --icf=safe is incompatible with object files created using objcopy or ld -r
 




More information about the llvm-commits mailing list