[PATCH] [lld] [ELF] Fix inclusion of weak symbols in the dynamic symbol table

Shankar Kalpathi Easwaran shankarke at gmail.com
Thu Oct 2 16:12:56 PDT 2014


================
Comment at: lib/ReaderWriter/ELF/DefaultLayout.h:567-586
@@ -564,9 +566,22 @@
+
     // Add runtime relocations to the .rela section.
     for (const auto &reloc : *definedAtom) {
-      if (_context.isDynamicRelocation(*definedAtom, *reloc))
+      bool isLocalReloc = true;
+      if (_context.isDynamicRelocation(*definedAtom, *reloc)) {
         getDynamicRelocationTable()->addRelocation(*definedAtom, *reloc);
-      else if (_context.isPLTRelocation(*definedAtom, *reloc))
+        isLocalReloc = false;
+      } else if (_context.isPLTRelocation(*definedAtom, *reloc)) {
         getPLTRelocationTable()->addRelocation(*definedAtom, *reloc);
-      if (const auto *sla = dyn_cast<SharedLibraryAtom>(reloc->target()))
-        _referencedDynAtoms.insert(sla);
+        isLocalReloc = false;
+      }
+
+      if (!reloc->target())
+        continue;
+
+      //Ignore undefined atoms that are not target of dynamic relocations
+      if (isa<UndefinedAtom>(reloc->target()) && isLocalReloc)
+        continue;
+
+      _referencedDynAtoms.insert(reloc->target());
     }
+
----------------
If we are creating a dynamic relocation for a symbol, that symbol should go in the dynamic symbol table. Looks like this code is removing undefined symbols that are targets of dynamic relocations.

http://reviews.llvm.org/D5571






More information about the llvm-commits mailing list