[lld] r327481 - [ELF] - Never create .gnu_hash with NBuckets == 0.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 14 01:52:39 PDT 2018


Author: grimar
Date: Wed Mar 14 01:52:39 2018
New Revision: 327481

URL: http://llvm.org/viewvc/llvm-project?rev=327481&view=rev
Log:
[ELF] - Never create .gnu_hash with NBuckets == 0.

Currently, we can end up with NBuckets==0 and android loader
does not like it (PR36537).

Seems we can go with a minimal amount of changes here for simplicity
and be consistent with gold and so just always use >= 1 value for NBuckets.

Differential revision: https://reviews.llvm.org/D44422

Modified:
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/test/ELF/arm-execute-only.s
    lld/trunk/test/ELF/dynamic-no-rosegment.s
    lld/trunk/test/ELF/gnu-hash-table.s

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=327481&r1=327480&r2=327481&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Wed Mar 14 01:52:39 2018
@@ -1799,15 +1799,19 @@ void GnuHashTableSection::addSymbols(std
           return SS->CopyRelSec == nullptr && !SS->NeedsPltAddr;
         return !S.Sym->isDefined();
       });
-  if (Mid == V.end())
-    return;
 
-  // We chose load factor 4 for the on-disk hash table. For each hash
-  // collision, the dynamic linker will compare a uint32_t hash value.
-  // Since the integer comparison is quite fast, we believe we can make
-  // the load factor even larger. 4 is just a conservative choice.
+  // Even if the hash table does not contain symbols, we still want to keep the
+  // section to indicate to a loader that the file exports no symbols. We can't
+  // have zero buckets because the android loader doesn't support that. We chose
+  // load factor 4 for the on-disk hash table. For each hash collision, the
+  // dynamic linker will compare a uint32_t hash value. Since the integer
+  // comparison is quite fast, we believe we can make the load factor even
+  // larger. 4 is just a conservative choice.
   NBuckets = std::max<size_t>((V.end() - Mid) / 4, 1);
 
+  if (Mid == V.end())
+    return;
+
   for (SymbolTableEntry &Ent : llvm::make_range(Mid, V.end())) {
     Symbol *B = Ent.Sym;
     uint32_t Hash = hashGnu(B->getName());

Modified: lld/trunk/test/ELF/arm-execute-only.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/arm-execute-only.s?rev=327481&r1=327480&r2=327481&view=diff
==============================================================================
--- lld/trunk/test/ELF/arm-execute-only.s (original)
+++ lld/trunk/test/ELF/arm-execute-only.s Wed Mar 14 01:52:39 2018
@@ -14,7 +14,7 @@
 // RUN: llvm-readelf -l %t.so | FileCheck --check-prefix=DIFF %s
 
 // CHECK-NOT:  LOAD
-// CHECK:      LOAD           0x000000 0x00000000 0x00000000 0x00169  0x00169  R   0x1000
+// CHECK:      LOAD           0x000000 0x00000000 0x00000000 0x0016d  0x0016d  R   0x1000
 // CHECK:      LOAD           0x001000 0x00001000 0x00001000 0x{{.*}} 0x{{.*}} R E 0x1000
 // CHECK:      LOAD           0x002000 0x00002000 0x00002000 0x{{.*}} 0x{{.*}}   E 0x1000
 // CHECK:      LOAD           0x003000 0x00003000 0x00003000 0x00038  0x00038  RW  0x1000
@@ -26,7 +26,7 @@
 // CHECK: 04     .dynamic
 
 // DIFF-NOT:  LOAD
-// DIFF:      LOAD           0x000000 0x00000000 0x00000000 0x00149 0x00149 R   0x1000
+// DIFF:      LOAD           0x000000 0x00000000 0x00000000 0x0014d 0x0014d R   0x1000
 // DIFF:      LOAD           0x001000 0x00001000 0x00001000 0x0000c 0x0000c R E 0x1000
 // DIFF:      LOAD           0x002000 0x00002000 0x00002000 0x00038 0x00038 RW  0x1000
 // DIFF-NOT:  LOAD

Modified: lld/trunk/test/ELF/dynamic-no-rosegment.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/dynamic-no-rosegment.s?rev=327481&r1=327480&r2=327481&view=diff
==============================================================================
--- lld/trunk/test/ELF/dynamic-no-rosegment.s (original)
+++ lld/trunk/test/ELF/dynamic-no-rosegment.s Wed Mar 14 01:52:39 2018
@@ -7,9 +7,9 @@
 # CHECK-NEXT:   Tag                Type                 Name/Value
 # CHECK-NEXT:   0x0000000000000006 SYMTAB               0x120
 # CHECK-NEXT:   0x000000000000000B SYMENT               24 (bytes)
-# CHECK-NEXT:   0x0000000000000005 STRTAB               0x1D0
+# CHECK-NEXT:   0x0000000000000005 STRTAB               0x1D8
 # CHECK-NEXT:   0x000000000000000A STRSZ                1 (bytes)
 # CHECK-NEXT:   0x000000006FFFFEF5 GNU_HASH             0x138
-# CHECK-NEXT:   0x0000000000000004 HASH                 0x150
+# CHECK-NEXT:   0x0000000000000004 HASH                 0x154
 # CHECK-NEXT:   0x0000000000000000 NULL                 0x0
 # CHECK-NEXT: ]

Modified: lld/trunk/test/ELF/gnu-hash-table.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gnu-hash-table.s?rev=327481&r1=327480&r2=327481&view=diff
==============================================================================
--- lld/trunk/test/ELF/gnu-hash-table.s (original)
+++ lld/trunk/test/ELF/gnu-hash-table.s Wed Mar 14 01:52:39 2018
@@ -51,12 +51,12 @@
 # EMPTY-NEXT:   }
 # EMPTY-NEXT: ]
 # EMPTY:      GnuHashTable {
-# EMPTY-NEXT:   Num Buckets: 0
+# EMPTY-NEXT:   Num Buckets: 1
 # EMPTY-NEXT:   First Hashed Symbol Index: 2
 # EMPTY-NEXT:   Num Mask Words: 1
 # EMPTY-NEXT:   Shift Count: 5
 # EMPTY-NEXT:   Bloom Filter: [0x0]
-# EMPTY-NEXT:   Buckets: []
+# EMPTY-NEXT:   Buckets: [0]
 # EMPTY-NEXT:   Values: []
 # EMPTY-NEXT: }
 




More information about the llvm-commits mailing list