[lld] r267568 - Don't gc symbols that have to go in the dynamic symbol table.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 26 09:26:45 PDT 2016


Author: rafael
Date: Tue Apr 26 11:26:45 2016
New Revision: 267568

URL: http://llvm.org/viewvc/llvm-project?rev=267568&view=rev
Log:
Don't gc symbols that have to go in the dynamic symbol table.

We were only doing it for .so and --export-dynamic, but those are not
the only ways a symbol ends up in the dynamic symbol table.

Problem diagnostic and earlier patch version by Peter Collingbourne.

Added:
    lld/trunk/test/ELF/gc-sections-shared.s
Modified:
    lld/trunk/ELF/MarkLive.cpp

Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=267568&r1=267567&r2=267568&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Tue Apr 26 11:26:45 2016
@@ -128,10 +128,9 @@ template <class ELFT> void elf::markLive
 
   // Preserve externally-visible symbols if the symbols defined by this
   // file can interrupt other ELF file's symbols at runtime.
-  if (Config->Shared || Config->ExportDynamic)
-    for (const Symbol *S : Symtab->getSymbols())
-      if (S->includeInDynsym())
-        MarkSymbol(S->Body);
+  for (const Symbol *S : Symtab->getSymbols())
+    if (S->includeInDynsym())
+      MarkSymbol(S->Body);
 
   // Preserve special sections and those which are specified in linker
   // script KEEP command.

Added: lld/trunk/test/ELF/gc-sections-shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gc-sections-shared.s?rev=267568&view=auto
==============================================================================
--- lld/trunk/test/ELF/gc-sections-shared.s (added)
+++ lld/trunk/test/ELF/gc-sections-shared.s Tue Apr 26 11:26:45 2016
@@ -0,0 +1,34 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t2.o
+# RUN: ld.lld -shared %t2.o -o %t2.so
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld --gc-sections --export-dynamic-symbol foo -o %t %t.o --as-needed %t2.so
+# RUN: llvm-readobj --dynamic-table --dyn-symbols %t | FileCheck %s
+
+# This test the property that we have a needed line for every undefined.
+# It would also be OK to drop bar2 and the need for the .so
+
+
+# CHECK: Name: bar
+# CHECK: Name: bar2
+# CHECK: Name: foo
+# CHECK: NEEDED SharedLibrary ({{.*}}.so)
+
+
+.section .text.foo, "ax"
+.globl foo
+foo:
+call bar
+
+.section .text.bar, "ax"
+.globl bar
+bar:
+ret
+
+.section .text._start, "ax"
+.globl _start
+_start:
+ret
+
+.section .text.unused, "ax"
+call bar2




More information about the llvm-commits mailing list