[PATCH] D59275: [ELF] Do not emit weak-undef symbols in .dynsym under -pie --no-dynamic-linker.
Siva Chandra via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 13 13:59:55 PDT 2019
sivachandra updated this revision to Diff 190504.
sivachandra added a comment.
Add a comment.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D59275/new/
https://reviews.llvm.org/D59275
Files:
lld/ELF/Symbols.cpp
lld/test/ELF/pie-weak.s
lld/test/ELF/relocation-relative-weak.s
lld/test/ELF/weak-undef-no-dynamic-linker.s
lld/test/ELF/weak-undef.s
Index: lld/test/ELF/weak-undef.s
===================================================================
--- lld/test/ELF/weak-undef.s
+++ lld/test/ELF/weak-undef.s
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-# RUN: ld.lld %t.o -o %t -pie
+# RUN: ld.lld %t.o -o %t -pie -dynamic-linker /path/to/ld.so
# RUN: llvm-readobj -dyn-symbols %t | FileCheck %s
# CHECK: DynamicSymbols [
Index: lld/test/ELF/weak-undef-no-dynamic-linker.s
===================================================================
--- /dev/null
+++ lld/test/ELF/weak-undef-no-dynamic-linker.s
@@ -0,0 +1,27 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+// RUN: ld.lld -pie --no-dynamic-linker %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 NOT 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/relocation-relative-weak.s
===================================================================
--- lld/test/ELF/relocation-relative-weak.s
+++ lld/test/ELF/relocation-relative-weak.s
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-# RUN: ld.lld %t.o -o %t -pie
+# RUN: ld.lld %t.o -o %t -pie -dynamic-linker /path/to/ld.so
# RUN: llvm-readobj -dyn-relocations %t | FileCheck %s
# CHECK: Dynamic Relocations {
Index: lld/test/ELF/pie-weak.s
===================================================================
--- lld/test/ELF/pie-weak.s
+++ lld/test/ELF/pie-weak.s
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -relax-relocations=false -triple=x86_64-unknown-linux %s -o %t.o
-# RUN: ld.lld --hash-style=sysv -pie %t.o -o %t
+# RUN: ld.lld --hash-style=sysv -dynamic-linker /path/to/ld.so -pie %t.o -o %t
# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOCS %s
# RUN: llvm-objdump -d %t | FileCheck --check-prefix=DISASM %s
Index: lld/ELF/Symbols.cpp
===================================================================
--- lld/ELF/Symbols.cpp
+++ lld/ELF/Symbols.cpp
@@ -267,6 +267,10 @@
return false;
if (computeBinding() == STB_LOCAL)
return false;
+ // If a dynamic linker is not specified, then weak-undef symbols in a PIE
+ // binary will not get resolved at runtime. Hence, drop them from .dynsym.
+ if (isUndefWeak() && Config->Pie && Config->DynamicLinker.empty())
+ return false;
if (!isDefined())
return true;
return ExportDynamic;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59275.190504.patch
Type: text/x-patch
Size: 3062 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190313/a596ba54/attachment.bin>
More information about the llvm-commits
mailing list