[PATCH] D16643: ELF: Report more than one undefined symbols if exist.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 27 11:16:15 PST 2016


ruiu created this revision.
ruiu added a reviewer: rafael.
ruiu added a subscriber: llvm-commits.

This patch depends on http://reviews.llvm.org/D16641.

http://reviews.llvm.org/D16643

Files:
  ELF/Writer.cpp
  test/ELF/undef.s

Index: test/ELF/undef.s
===================================================================
--- test/ELF/undef.s
+++ test/ELF/undef.s
@@ -1,8 +1,10 @@
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
 # RUN: not ld.lld %t -o %t2 2>&1 | FileCheck %s
+# CHECK: undefined symbol: bar in {{.*}}
 # CHECK: undefined symbol: foo in {{.*}}
 # REQUIRES: x86
 
-  .globl _start;
+  .globl _start
 _start:
   call foo
+  call bar
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -43,7 +43,7 @@
 private:
   void copyLocalSymbols();
   void addReservedSymbols();
-  void createSections();
+  bool createSections();
   void addPredefinedSections();
 
   template <bool isRela>
@@ -156,7 +156,8 @@
   if (!Config->DiscardAll)
     copyLocalSymbols();
   addReservedSymbols();
-  createSections();
+  if (!createSections())
+    return;
   assignAddresses();
   fixAbsoluteSymbols();
   openFile(Config->OutputFile);
@@ -382,7 +383,7 @@
   if (Config->NoInhibitExec)
     warning(Msg);
   else
-    fatal(Msg);
+    error(Msg);
 }
 
 template <class ELFT>
@@ -421,7 +422,10 @@
   for (const std::unique_ptr<ObjectFile<ELFT>> &F : Symtab.getObjectFiles()) {
     for (const Elf_Sym &Sym : F->getLocalSymbols()) {
       ErrorOr<StringRef> SymNameOrErr = Sym.getName(F->getStringTable());
-      fatal(SymNameOrErr);
+      if (!SymNameOrErr) {
+        error(SymNameOrErr);
+        return;
+      }
       StringRef SymName = *SymNameOrErr;
       if (!shouldKeepInSymtab<ELFT>(*F, SymName, Sym))
         continue;
@@ -796,7 +800,7 @@
 }
 
 // Create output section objects and add them to OutputSections.
-template <class ELFT> void Writer<ELFT>::createSections() {
+template <class ELFT> bool Writer<ELFT>::createSections() {
   // Add .interp first because some loaders want to see that section
   // on the first page of the executable file when loaded into memory.
   if (needsInterpSection())
@@ -890,6 +894,9 @@
   addCommonSymbols(CommonSymbols);
   addCopyRelSymbols(CopyRelSymbols);
 
+  if (HasError)
+    return false;
+
   // So far we have added sections from input object files.
   // This function adds linker-created Out<ELFT>::* sections.
   addPredefinedSections();
@@ -915,6 +922,7 @@
   for (OutputSectionBase<ELFT> *Sec : OutputSections)
     if (Sec != Out<ELFT>::DynStrTab)
       Sec->finalize();
+  return true;
 }
 
 // This function add Out<ELFT>::* sections to OutputSections.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16643.46160.patch
Type: text/x-patch
Size: 2494 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160127/2d1a8948/attachment.bin>


More information about the llvm-commits mailing list