[PATCH] D83549: [ELF] Do not leave undefined symbols (specified by -init and -fini) if they are defined in non-fetched archive members

Igor Kudrin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 13 01:26:55 PDT 2020


ikudrin updated this revision to Diff 277341.
ikudrin marked 2 inline comments as done.
ikudrin added a comment.

- Moved the test into `init-fini.s`.

Thanks @MaskRay for updating the title! I'll use it for the commit message.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83549/new/

https://reviews.llvm.org/D83549

Files:
  lld/ELF/Driver.cpp
  lld/test/ELF/init-fini.s


Index: lld/test/ELF/init-fini.s
===================================================================
--- lld/test/ELF/init-fini.s
+++ lld/test/ELF/init-fini.s
@@ -46,6 +46,14 @@
 // NOENTRY-NOT: Name: _unknown
 // NOENTRY: ]
 
+// Should not add entries for "_init" and "_fini" to the symbol table
+// if the symbols are defined in non-fetched achive members.
+// RUN: rm -f %t.a
+// RUN: llvm-ar rcs %t.a %t
+// RUN: ld.lld -shared -m elf_x86_64 -e _unknown %t.a -o %t.so
+// RUN: llvm-nm %t.so | \
+// RUN:   FileCheck %s --implicit-check-not=_init --implicit-check-not=_fini
+
 .global _start,_init,_fini,_foo,_bar,_undef
 _start:
 _init = 0x11010
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -1944,9 +1944,9 @@
     handleUndefinedGlob(pat);
 
   // Mark -init and -fini symbols so that the LTO doesn't eliminate them.
-  if (Symbol *sym = symtab->find(config->init))
+  if (Symbol *sym = dyn_cast_or_null<Defined>(symtab->find(config->init)))
     sym->isUsedInRegularObj = true;
-  if (Symbol *sym = symtab->find(config->fini))
+  if (Symbol *sym = dyn_cast_or_null<Defined>(symtab->find(config->fini)))
     sym->isUsedInRegularObj = true;
 
   // If any of our inputs are bitcode files, the LTO code generator may create


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83549.277341.patch
Type: text/x-patch
Size: 1326 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200713/545cc507/attachment.bin>


More information about the llvm-commits mailing list