[lld] r264843 - [ELF] - Do not keep undefined locals in .symtab

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 30 01:16:13 PDT 2016


Author: grimar
Date: Wed Mar 30 03:16:11 2016
New Revision: 264843

URL: http://llvm.org/viewvc/llvm-project?rev=264843&view=rev
Log:
[ELF] - Do not keep undefined locals in .symtab

gold and bfd do not include the undefined locals in symtab.
We have no reasons to support that either.

That fixes PR27016

Differential revision: http://reviews.llvm.org/D18554

Added:
    lld/trunk/test/ELF/local-undefined-symbol.s
Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=264843&r1=264842&r2=264843&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Mar 30 03:16:11 2016
@@ -511,6 +511,10 @@ static bool shouldKeepInSymtab(const elf
   if (Sym.getType() == STT_SECTION)
     return Config->Relocatable;
 
+  // No reason to keep local undefined symbol in symtab.
+  if (Sym.st_shndx == SHN_UNDEF)
+    return false;
+
   InputSectionBase<ELFT> *Sec = File.getSection(Sym);
   // If sym references a section in a discarded group, don't keep it.
   if (Sec == InputSection<ELFT>::Discarded)

Added: lld/trunk/test/ELF/local-undefined-symbol.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/local-undefined-symbol.s?rev=264843&view=auto
==============================================================================
--- lld/trunk/test/ELF/local-undefined-symbol.s (added)
+++ lld/trunk/test/ELF/local-undefined-symbol.s Wed Mar 30 03:16:11 2016
@@ -0,0 +1,13 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: ld.lld %t -o %t1
+# RUN: llvm-readobj -t %t1 | FileCheck %s
+
+# CHECK:     Symbols [
+# CHECK-NOT:  Name: foo
+
+.global _start
+_start:
+ jmp foo
+
+.local foo




More information about the llvm-commits mailing list