Print error message in LinkOnce handler.
authorRui Ueyama <ruiu@google.com>
Thu, 5 Jun 2014 07:37:25 +0000 (07:37 +0000)
committerRui Ueyama <ruiu@google.com>
Thu, 5 Jun 2014 07:37:25 +0000 (07:37 +0000)
Rather than outside of the handler function to make the code simple.

llvm-svn: 210241

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

index 3d8fe9c..2cb2966 100644 (file)
@@ -57,7 +57,7 @@ private:
   typedef std::function<void(StringRef, bool)> UndefCallback;
 
   /// \brief Add section group/.gnu.linkonce if it does not exist previously.
-  bool maybeAddSectionGroupOrGnuLinkOnce(const DefinedAtom &atom);
+  void maybeAddSectionGroupOrGnuLinkOnce(const DefinedAtom &atom);
 
   /// \brief The main function that iterates over the files to resolve
   bool resolveUndefines();
index ba4b61b..03e6596 100644 (file)
@@ -148,26 +148,30 @@ bool Resolver::doUndefinedAtom(const UndefinedAtom &atom) {
 }
 
 /// \brief Add the section group and the group-child reference members.
-bool Resolver::maybeAddSectionGroupOrGnuLinkOnce(const DefinedAtom &atom) {
+void Resolver::maybeAddSectionGroupOrGnuLinkOnce(const DefinedAtom &atom) {
   // First time adding a group?
   bool isFirstTime = _symbolTable.addGroup(atom);
 
   if (!isFirstTime) {
     // If duplicate symbols are allowed, select the first group.
     if (_context.getAllowDuplicates())
-      return true;
-    const DefinedAtom *prevGroup =
-        dyn_cast<DefinedAtom>(_symbolTable.findGroup(atom.name()));
+      return;
+    auto *prevGroup = dyn_cast<DefinedAtom>(_symbolTable.findGroup(atom.name()));
     assert(prevGroup &&
            "Internal Error: The group atom could only be a defined atom");
     // The atoms should be of the same content type, reject invalid group
     // resolution behaviors.
-    return atom.contentType() == prevGroup->contentType();
+    if (atom.contentType() == prevGroup->contentType())
+      return;
+    llvm::errs() << "SymbolTable: error while merging " << atom.name()
+                 << "\n";
+    llvm::report_fatal_error("duplicate symbol error");
+    return;
   }
 
   for (const Reference *r : atom) {
-    if ((r->kindNamespace() == lld::Reference::KindNamespace::all) &&
-        (r->kindValue() == lld::Reference::kindGroupChild)) {
+    if (r->kindNamespace() == lld::Reference::KindNamespace::all &&
+        r->kindValue() == lld::Reference::kindGroupChild) {
       const DefinedAtom *target = dyn_cast<DefinedAtom>(r->target());
       assert(target && "Internal Error: kindGroupChild references need to "
                        "be associated with Defined Atoms only");
@@ -175,7 +179,6 @@ bool Resolver::maybeAddSectionGroupOrGnuLinkOnce(const DefinedAtom &atom) {
       _symbolTable.add(*target);
     }
   }
-  return true;
 }
 
 // Called on each atom when a file is added. Returns true if a given
@@ -202,12 +205,7 @@ void Resolver::doDefinedAtom(const DefinedAtom &atom) {
   _atoms.push_back(&atom);
 
   if (atom.isGroupParent()) {
-    // Raise error if there exists a similar gnu linkonce section.
-    if (!maybeAddSectionGroupOrGnuLinkOnce(atom)) {
-      llvm::errs() << "SymbolTable: error while merging " << atom.name()
-                   << "\n";
-      llvm::report_fatal_error("duplicate symbol error");
-    }
+    maybeAddSectionGroupOrGnuLinkOnce(atom);
   } else {
     _symbolTable.add(atom);
   }