[Core] Only complain about undefined symbols if they are marked as canBeNullNever.
authorMichael J. Spencer <bigcheesegs@gmail.com>
Thu, 31 Jan 2013 22:56:13 +0000 (22:56 +0000)
committerMichael J. Spencer <bigcheesegs@gmail.com>
Thu, 31 Jan 2013 22:56:13 +0000 (22:56 +0000)
llvm-svn: 174107

lld/include/lld/Core/SymbolTable.h
lld/lib/Core/Resolver.cpp
lld/lib/Core/SymbolTable.cpp

index b78cce45bcac25ee955b53ec3ebedec9b1e5e1b0..f1d25e5b82863b13f3781303720dde4eeb9e95cf 100644 (file)
@@ -59,7 +59,7 @@ public:
   const Atom *findByName(StringRef sym);
 
   /// @brief returns vector of remaining UndefinedAtoms
-  void undefines(std::vector<const Atom *>&);
+  void undefines(std::vector<const UndefinedAtom *>&);
   
   /// returns vector of tentative definitions
   void tentativeDefinitions(std::vector<StringRef> &);
index b80a22141734be7f947b0c15bb0be7bff61d1d33..d0dd41fb5b46a3b64c4263998041bd4096c64e8d 100644 (file)
@@ -191,7 +191,7 @@ void Resolver::resolveUndefines() {
   unsigned int undefineGenCount = 0xFFFFFFFF;
   while (undefineGenCount != _symbolTable.size()) {
     undefineGenCount = _symbolTable.size();
-    std::vector<const Atom *> undefines;
+    std::vector<const UndefinedAtom *> undefines;
     _symbolTable.undefines(undefines);
     for ( const Atom *undefAtom : undefines ) {
       StringRef undefName = undefAtom->name();
@@ -301,7 +301,7 @@ void Resolver::checkUndefines(bool final) {
     return;
 
   // build vector of remaining undefined symbols
-  std::vector<const Atom *> undefinedAtoms;
+  std::vector<const UndefinedAtom *> undefinedAtoms;
   _symbolTable.undefines(undefinedAtoms);
   if (_targetInfo.getLinkerOptions()._deadStrip) {
     // When dead code stripping, we don't care if dead atoms are undefined.
@@ -315,11 +315,15 @@ void Resolver::checkUndefines(bool final) {
       (!_targetInfo.getLinkerOptions()._noInhibitExec ||
        _targetInfo.getLinkerOptions()._outputKind == OutputKind::Relocatable)) {
     // FIXME: need diagonstics interface for writing error messages
-    llvm::errs() << "Undefined symbols:\n";
-    for ( const Atom *undefAtom : undefinedAtoms ) {
-      llvm::errs() << "  " << undefAtom->name() << "\n";
+    bool isError = false;
+    for (const UndefinedAtom *undefAtom : undefinedAtoms) {
+      if (undefAtom->canBeNull() == UndefinedAtom::canBeNullNever) {
+        llvm::errs() << "Undefined Symbol: " << undefAtom->name() << "\n";
+        isError = true;
+      }
     }
-    llvm::report_fatal_error("symbol(s) not found");
+    if (isError)
+      llvm::report_fatal_error("symbol(s) not found");
   }
 }
 
index 7a35ed901442e957b05812192a32f5d39d0703cd..29e587960221f0af30acb844af269e5c3646d4d2 100644 (file)
@@ -332,13 +332,13 @@ unsigned int SymbolTable::size() {
   return _nameTable.size();
 }
 
-void SymbolTable::undefines(std::vector<const Atom *> &undefs) {
+void SymbolTable::undefines(std::vector<const UndefinedAtom *> &undefs) {
   for (NameToAtom::iterator it = _nameTable.begin(),
        end = _nameTable.end(); it != end; ++it) {
     const Atom *atom = it->second;
     assert(atom != nullptr);
-    if (atom->definition() == Atom::definitionUndefined)
-      undefs.push_back(atom);
+    if (const auto undef = dyn_cast<const UndefinedAtom>(atom))
+      undefs.push_back(undef);
   }
 }