[lld] 96e2376 - [ELF] Don't special case weak symbols for pie with no shared objects

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 8 09:40:53 PST 2020


Author: Fangrui Song
Date: 2020-01-08T09:38:49-08:00
New Revision: 96e2376d02f0840e82b96314108660ecabe63c7f

URL: https://github.com/llvm/llvm-project/commit/96e2376d02f0840e82b96314108660ecabe63c7f
DIFF: https://github.com/llvm/llvm-project/commit/96e2376d02f0840e82b96314108660ecabe63c7f.diff

LOG: [ELF] Don't special case weak symbols for pie with no shared objects

D59275 added the following clause to Symbol::includeInDynsym()

  if (isUndefWeak() && Config->Pie && SharedFiles.empty())
    return false;

D59549 explored the possibility to generalize it for -no-pie.

GNU ld's rules are architecture dependent and partly controlled by -z
{,no-}dynamic-undefined-weak. Our attempts to mimic its rules are
actually half-baked and don't provide perceivable benefits (it can save
a few more weak undefined symbols in .dynsym in a -static-pie
executable). Let's just delete the rule for simplicity. We will expect
cosmetic inconsistencies with ld.bfd in certain -static-pie scenarios.

This permits a simplification in D71795.

Reviewed By: peter.smith

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

Added: 
    

Modified: 
    lld/ELF/Symbols.cpp
    lld/test/ELF/ppc32-weak-undef-call.s

Removed: 
    lld/test/ELF/weak-undef-no-shared-libs.s


################################################################################
diff  --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index 365be6f7802f..a9e3645043fe 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -278,11 +278,6 @@ bool Symbol::includeInDynsym() const {
   if (computeBinding() == STB_LOCAL)
     return false;
 
-  // If a PIE binary was not linked against any shared libraries, then we can
-  // safely drop weak undef symbols from .dynsym.
-  if (isUndefWeak() && config->pie && sharedFiles.empty())
-    return false;
-
   return isUndefined() || isShared() || exportDynamic || inDynamicList;
 }
 

diff  --git a/lld/test/ELF/ppc32-weak-undef-call.s b/lld/test/ELF/ppc32-weak-undef-call.s
index 303e5a8ac10e..95c36b7eed53 100644
--- a/lld/test/ELF/ppc32-weak-undef-call.s
+++ b/lld/test/ELF/ppc32-weak-undef-call.s
@@ -1,19 +1,19 @@
 # REQUIRES: ppc
 # RUN: llvm-mc -filetype=obj -triple=powerpc %s -o %t.o
 # RUN: ld.lld %t.o -o %t
-# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=EXE %s
+# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=PDE %s
 # RUN: ld.lld -pie %t.o -o %t
-# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=EXE %s
+# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=PIC %s
 # RUN: ld.lld -shared %t.o -o %t
-# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=SHARED %s
+# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=PIC %s
 
 ## It does not really matter how we fixup it, but we cannot overflow and
 ## should not generate a call stub (this would waste space).
-# EXE: bl .+0
+# PDE: bl .+0
 
-## With -shared, create a call stub. ld.bfd produces bl .+0
-# SHARED: bl .+4
-# SHARED: 00000000.plt_pic32.foo:
+## With -pie or -shared, create a call stub. ld.bfd produces bl .+0
+# PIC: bl .+4
+# PIC: 00000000.plt_pic32.foo:
 
 .weak foo
 bl foo

diff  --git a/lld/test/ELF/weak-undef-no-shared-libs.s b/lld/test/ELF/weak-undef-no-shared-libs.s
deleted file mode 100644
index 1d708eef6f8f..000000000000
--- a/lld/test/ELF/weak-undef-no-shared-libs.s
+++ /dev/null
@@ -1,28 +0,0 @@
-// REQUIRES: x86
-// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
-// RUN: ld.lld -pie %t.o -o %t
-// RUN: llvm-readobj -V --dyn-syms %t | FileCheck %s
-
-        .globl _start
-_start:
-        .type foo, at function
-        .weak foo
-        .long foo at gotpcrel
-
-// Test that an entry for weak undefined symbols is NOT emitted in .dynsym as
-// the PIE was not linked with any shared libraries. There are other tests which
-// ensure that the weak undefined symbols do get emitted in .dynsym for PIEs
-// linked against dynamic libraries.
-
-
-// CHECK:      DynamicSymbols [
-// CHECK-NEXT:   Symbol {
-// CHECK-NEXT:     Name:
-// CHECK-NEXT:     Value: 0x0
-// CHECK-NEXT:     Size: 0
-// CHECK-NEXT:     Binding: Local (0x0)
-// CHECK-NEXT:     Type: None (0x0)
-// CHECK-NEXT:     Other: 0
-// CHECK-NEXT:     Section: Undefined (0x0)
-// CHECK-NEXT:   }
-// CHECK-NEXT: ]


        


More information about the llvm-commits mailing list