[lld] r316065 - Handle shared symbols in the gnu hash construction.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 17 23:49:59 PDT 2017


Author: rafael
Date: Tue Oct 17 23:49:59 2017
New Revision: 316065

URL: http://llvm.org/viewvc/llvm-project?rev=316065&view=rev
Log:
Handle shared symbols in the gnu hash construction.

They are special in that they they need to be in the hash table iff we
are linking an executable that preempts them.

Added:
    lld/trunk/test/ELF/gnu-hash-table-copy.s
Modified:
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/test/ELF/gc-sections-shared.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=316065&r1=316064&r2=316065&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Tue Oct 17 23:49:59 2017
@@ -1608,7 +1608,11 @@ void GnuHashTableSection::addSymbols(std
   // its type correctly.
   std::vector<SymbolTableEntry>::iterator Mid =
       std::stable_partition(V.begin(), V.end(), [](const SymbolTableEntry &S) {
-        return S.Symbol->isUndefined() || S.Symbol->isLazy();
+        // Shared symbols that this executable preempts are special. The dynamic
+        // linker has to look them up, so they have to be in the hash table.
+        if (auto *SS = dyn_cast<SharedSymbol>(S.Symbol))
+          return SS->CopyRelSec == nullptr && !SS->NeedsPltAddr;
+        return !S.Symbol->isInCurrentDSO();
       });
   if (Mid == V.end())
     return;

Modified: lld/trunk/test/ELF/gc-sections-shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gc-sections-shared.s?rev=316065&r1=316064&r2=316065&view=diff
==============================================================================
--- lld/trunk/test/ELF/gc-sections-shared.s (original)
+++ lld/trunk/test/ELF/gc-sections-shared.s Tue Oct 17 23:49:59 2017
@@ -19,16 +19,16 @@
 # CHECK-NEXT:     Section: Undefined (0x0)
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Symbol {
-# CHECK-NEXT:     Name: bar
+# CHECK-NEXT:     Name: bar2
 # CHECK-NEXT:     Value:
 # CHECK-NEXT:     Size:
 # CHECK-NEXT:     Binding: Global
 # CHECK-NEXT:     Type:
 # CHECK-NEXT:     Other:
-# CHECK-NEXT:     Section: .text
+# CHECK-NEXT:     Section: Undefined
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Symbol {
-# CHECK-NEXT:     Name: foo
+# CHECK-NEXT:     Name: bar
 # CHECK-NEXT:     Value:
 # CHECK-NEXT:     Size:
 # CHECK-NEXT:     Binding: Global
@@ -37,13 +37,13 @@
 # CHECK-NEXT:     Section: .text
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Symbol {
-# CHECK-NEXT:     Name: bar2
+# CHECK-NEXT:     Name: foo
 # CHECK-NEXT:     Value:
 # CHECK-NEXT:     Size:
 # CHECK-NEXT:     Binding: Global
 # CHECK-NEXT:     Type:
 # CHECK-NEXT:     Other:
-# CHECK-NEXT:     Section: Undefined
+# CHECK-NEXT:     Section: .text
 # CHECK-NEXT:   }
 # CHECK-NEXT: ]
 

Added: lld/trunk/test/ELF/gnu-hash-table-copy.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gnu-hash-table-copy.s?rev=316065&view=auto
==============================================================================
--- lld/trunk/test/ELF/gnu-hash-table-copy.s (added)
+++ lld/trunk/test/ELF/gnu-hash-table-copy.s Tue Oct 17 23:49:59 2017
@@ -0,0 +1,30 @@
+# REQUIRES: x86
+
+# RUN: echo ".global foo; .type foo, @object; .size foo, 4; foo:; .long 0" > %t.s
+# RUN: echo ".global bar; .type bar, @object; .size bar, 4; bar:; .long 0" >> %t.s
+# RUN: echo ".global zed; .type zed, @function; zed:" >> %t.s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %t.s -o %t1.o
+# RUN: ld.lld %t1.o -o %t1.so -shared
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t2.o
+# RUN: ld.lld --hash-style=gnu %t2.o %t1.so -o %t2
+
+# RUN: llvm-readelf --symbols --gnu-hash-table %t2 | FileCheck %s
+
+# CHECK:      Symbol table '.dynsym' contains 4 entries:
+# CHECK-NEXT:    Num:    Value          Size Type    Bind   Vis      Ndx   Name
+# CHECK-NEXT:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND   @
+# CHECK-NEXT:      1: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  UND   foo@
+# CHECK-DAG:        : {{.*}}               4 OBJECT  GLOBAL DEFAULT {{.*}} bar@
+# CHECK-DAG:        : {{.*}}               0 FUNC    GLOBAL DEFAULT  UND   zed@
+
+# CHECK: First Hashed Symbol Index: 2
+
+.global _start
+_start:
+
+.quad bar
+.quad zed
+
+.data
+.quad foo

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=316065&r1=316064&r2=316065&view=diff
==============================================================================
--- lld/trunk/test/ELF/gnu-hash-table.s (original)
+++ lld/trunk/test/ELF/gnu-hash-table.s Tue Oct 17 23:49:59 2017
@@ -71,7 +71,7 @@
 # I386-NEXT:     ]
 # I386-NEXT:     Address:
 # I386-NEXT:     Offset:
-# I386-NEXT:     Size: 44
+# I386-NEXT:     Size: 32
 # I386-NEXT:     Link:
 # I386-NEXT:     Info: 0
 # I386-NEXT:     AddressAlignment: 4
@@ -89,6 +89,11 @@
 # I386:          Section: Undefined
 # I386:        }
 # I386:        Symbol {
+# I386:          Name: xyz@
+# I386:          Binding: Global
+# I386:          Section: Undefined
+# I386:        }
+# I386:        Symbol {
 # I386:          Name: zed@
 # I386:          Binding: Weak
 # I386:          Section: Undefined
@@ -103,20 +108,15 @@
 # I386:          Binding: Global
 # I386:          Section: .text
 # I386:        }
-# I386:        Symbol {
-# I386:          Name: xyz@
-# I386:          Binding: Global
-# I386:          Section: Undefined
-# I386:        }
 # I386:      ]
 # I386:      GnuHashTable {
-# I386-NEXT:   Num Buckets: 3
-# I386-NEXT:   First Hashed Symbol Index: 3
+# I386-NEXT:   Num Buckets: 1
+# I386-NEXT:   First Hashed Symbol Index: 4
 # I386-NEXT:   Num Mask Words: 1
 # I386-NEXT:   Shift Count: 5
-# I386-NEXT:   Bloom Filter: [0x14010A20]
-# I386-NEXT:   Buckets: [3, 0, 5]
-# I386-NEXT:   Values: [0xB8860BA, 0xB887389, 0xB88C171]
+# I386-NEXT:   Bloom Filter: [0x14000220]
+# I386-NEXT:   Buckets: [4]
+# I386-NEXT:   Values: [0xB8860BA, 0xB887389]
 # I386-NEXT: }
 
 # X86_64:      Format: ELF64-x86-64
@@ -130,7 +130,7 @@
 # X86_64-NEXT:     ]
 # X86_64-NEXT:     Address:
 # X86_64-NEXT:     Offset:
-# X86_64-NEXT:     Size: 48
+# X86_64-NEXT:     Size: 36
 # X86_64-NEXT:     Link:
 # X86_64-NEXT:     Info: 0
 # X86_64-NEXT:     AddressAlignment: 8
@@ -149,6 +149,11 @@
 # X86_64:          Section: Undefined
 # X86_64:        }
 # X86_64:        Symbol {
+# X86_64:          Name: xyz@
+# X86_64:          Binding: Global
+# X86_64:          Section: Undefined
+# X86_64:        }
+# X86_64:        Symbol {
 # X86_64:          Name: zed@
 # X86_64:          Binding: Weak
 # X86_64:          Section: Undefined
@@ -163,20 +168,15 @@
 # X86_64:          Binding: Global
 # X86_64:          Section: .text
 # X86_64:        }
-# X86_64:        Symbol {
-# X86_64:          Name: xyz@
-# X86_64:          Binding: Global
-# X86_64:          Section: Undefined
-# X86_64:        }
 # X86_64:      ]
 # X86_64:      GnuHashTable {
-# X86_64-NEXT:   Num Buckets: 3
-# X86_64-NEXT:   First Hashed Symbol Index: 3
+# X86_64-NEXT:   Num Buckets: 1
+# X86_64-NEXT:   First Hashed Symbol Index: 4
 # X86_64-NEXT:   Num Mask Words: 1
 # X86_64-NEXT:   Shift Count: 6
-# X86_64-NEXT:   Bloom Filter: [0x401000000004224]
-# X86_64-NEXT:   Buckets: [3, 0, 5]
-# X86_64-NEXT:   Values: [0xB8860BA, 0xB887389, 0xB88C171]
+# X86_64-NEXT:   Bloom Filter: [0x400000000004204]
+# X86_64-NEXT:   Buckets: [4]
+# X86_64-NEXT:   Values: [0xB8860BA, 0xB887389]
 # X86_64-NEXT: }
 
 # PPC64:      Format: ELF64-ppc64
@@ -190,7 +190,7 @@
 # PPC64-NEXT:     ]
 # PPC64-NEXT:     Address:
 # PPC64-NEXT:     Offset:
-# PPC64-NEXT:     Size: 48
+# PPC64-NEXT:     Size: 36
 # PPC64-NEXT:     Link:
 # PPC64-NEXT:     Info: 0
 # PPC64-NEXT:     AddressAlignment: 8
@@ -209,6 +209,11 @@
 # PPC64:          Section: Undefined
 # PPC64:        }
 # PPC64:        Symbol {
+# PPC64:          Name: xyz@
+# PPC64:          Binding: Global
+# PPC64:          Section: Undefined
+# PPC64:        }
+# PPC64:        Symbol {
 # PPC64:          Name: zed@
 # PPC64:          Binding: Weak
 # PPC64:          Section: Undefined
@@ -223,20 +228,15 @@
 # PPC64:          Binding: Global
 # PPC64:          Section: .text
 # PPC64:        }
-# PPC64:        Symbol {
-# PPC64:          Name: xyz@
-# PPC64:          Binding: Global
-# PPC64:          Section: Undefined
-# PPC64:        }
 # PPC64:      ]
 # PPC64:      GnuHashTable {
-# PPC64-NEXT:   Num Buckets: 3
-# PPC64-NEXT:   First Hashed Symbol Index: 3
+# PPC64-NEXT:   Num Buckets: 1
+# PPC64-NEXT:   First Hashed Symbol Index: 4
 # PPC64-NEXT:   Num Mask Words: 1
 # PPC64-NEXT:   Shift Count: 6
-# PPC64-NEXT:   Bloom Filter: [0x401000000004224]
-# PPC64-NEXT:   Buckets: [3, 0, 5]
-# PPC64-NEXT:   Values: [0xB8860BA, 0xB887389, 0xB88C171]
+# PPC64-NEXT:   Bloom Filter: [0x400000000004204]
+# PPC64-NEXT:   Buckets: [4]
+# PPC64-NEXT:   Values: [0xB8860BA, 0xB887389]
 # PPC64-NEXT: }
 
 .globl foo,bar,baz




More information about the llvm-commits mailing list