[PATCH] [lld][ELF] add undefined atoms from dynamic library

kledzik at apple.com kledzik at apple.com
Tue Apr 9 13:32:44 PDT 2013



================
Comment at: lib/ReaderWriter/ELF/DynamicFile.h:57-78
@@ -58,9 +56,24 @@
       StringRef name;
-      if (error_code ec =
-              obj.getSymbolName(obj.getDynamicSymbolTableSectionHeader(), &*i,
-                                name))
-        return ec;
-      file->_nameToSym[name]._symbol = &*i;
-
-      // TODO: Read undefined dynamic symbols into _undefinedAtoms.
+      const Elf_Sym *symbol = &*i;
+      if ((EC = obj.getSymbolName(obj.getDynamicSymbolTableSectionHeader(), &*i,
+                                  name)))
+        return;
+      if (symbol->st_shndx == llvm::ELF::SHN_ABS) {
+        // TODO : create absolute atoms
+        // need a change in the SymbolTable functionality to override absolute
+        // atoms properly
+        // Create an absolute atom.
+        // auto *newAtom = new (_alloc)
+        //      ELFAbsoluteAtom<ELFT>(*this, name, symbol, symbol->st_value);
+        // _absoluteAtoms._atoms.push_back(newAtom);
+      } else if ((symbol->st_shndx == llvm::ELF::SHN_UNDEF)) {
+        // Create an undefined atom.
+        if (!name.empty()) {
+          auto *newAtom =
+              new (_alloc) ELFUndefinedAtom<ELFT>(*this, name, symbol);
+          _undefinedAtoms._atoms.push_back(newAtom);
+        }
+      } else {
+        _nameToSym[name]._symbol = symbol;
+      }
     }
----------------
Shankar Kalpathi Easwaran wrote:
> Michael Spencer wrote:
> > This and the tests are the only part of this patch that are needed.
> Will fix it.
This should only be done based on some ELFTargetInfo setting (e.g. useSharedLibraryUndefines()).   The binutils ld man page says that undefines in linked DSO are only used when creating a main executable - not when creating another DSO.  There are also command line options (--allow-shlib-undefined and --no-allow-shlib-undefined) to switch that behavior.  

The test case(s) need to validate both behaviors.


http://llvm-reviews.chandlerc.com/D642



More information about the llvm-commits mailing list