[PATCH] D59275: [ELF] Do not emit weak-undef symbols in .dynsym if config is -static -pie.

Siva Chandra via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 12 15:22:46 PDT 2019


sivachandra created this revision.
Herald added subscribers: llvm-commits, MaskRay, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D59275

Files:
  lld/ELF/Symbols.cpp
  lld/test/ELF/Inputs/static-pie-weak-undef.s
  lld/test/ELF/static-pie-weak-undef.s


Index: lld/test/ELF/static-pie-weak-undef.s
===================================================================
--- /dev/null
+++ lld/test/ELF/static-pie-weak-undef.s
@@ -0,0 +1,28 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/static-pie-weak-undef.s -o %t2.o
+// RUN: ld.lld -static -pie %t2.o %t.o -o %t
+// RUN: llvm-readobj -V -dyn-symbols %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 emitted in .dynsym. There
+// are other tests which ensure that the weak undefined symbols do get emitted in .dynsym
+// for non-static PIEs.
+
+
+// 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: ]
Index: lld/test/ELF/Inputs/static-pie-weak-undef.s
===================================================================
--- /dev/null
+++ lld/test/ELF/Inputs/static-pie-weak-undef.s
@@ -0,0 +1,2 @@
+        .global main
+main:
Index: lld/ELF/Symbols.cpp
===================================================================
--- lld/ELF/Symbols.cpp
+++ lld/ELF/Symbols.cpp
@@ -267,6 +267,8 @@
     return false;
   if (computeBinding() == STB_LOCAL)
     return false;
+  if (isUndefWeak() && Config->Pie && Config->Static)
+    return false;
   if (!isDefined())
     return true;
   return ExportDynamic;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59275.190347.patch
Type: text/x-patch
Size: 1727 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190312/2b97ecb2/attachment.bin>


More information about the llvm-commits mailing list