[PATCH] D18554: [ELF, PR27016] - Do not keep undefined locals in .symtab

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 29 08:03:56 PDT 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.

While looking into PR27016 I found that both gold and bfd just do not 
include the undefined locals in symtab.

We can support that for sure, but do anybody see reasons to do that then ?
(I can probably implement that if so).

Now that is pretty simple patch to fix PR27016 and also looks even have benefits, 
helps to "get rid of undefined ppc64 "dot-symbols"
(https://sourceware.org/ml/binutils/2015-02/msg00237.html).



http://reviews.llvm.org/D18554

Files:
  ELF/Writer.cpp
  test/ELF/local-undefined-symbol.s

Index: test/ELF/local-undefined-symbol.s
===================================================================
--- test/ELF/local-undefined-symbol.s
+++ test/ELF/local-undefined-symbol.s
@@ -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 -s %t1 | FileCheck %s
+
+# CHECK:     Symbols [
+# CHECK-NOT:  Name: foo
+
+.global _start
+_start:
+ jmp foo
+
+.local foo
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -520,6 +520,10 @@
   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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18554.51912.patch
Type: text/x-patch
Size: 965 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160329/efff5650/attachment.bin>


More information about the llvm-commits mailing list