Don't produce an error for undefined entry symbol.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 20 Sep 2016 17:14:16 +0000 (17:14 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 20 Sep 2016 17:14:16 +0000 (17:14 +0000)
This is particularly important when the symbol comes from a linker
script. It is common to use the same linker script for shared
libraries and executables. Without this we would always fail to link
shared libraries with -z,defs and a linker script with an ENTRY
directive.

llvm-svn: 281989

lld/ELF/Driver.cpp
lld/test/ELF/linkerscript/linkerscript.s

index 3e1f723..9f13ca6 100644 (file)
@@ -667,16 +667,15 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
   // Note that AMDGPU binaries have no entries.
   if (!Config->Entry.empty()) {
     // It is either "-e <addr>" or "-e <symbol>".
-    if (Config->Entry.getAsInteger(0, Config->EntryAddr))
-      Config->EntrySym = Symtab.addUndefined(Config->Entry);
+    Config->Entry.getAsInteger(0, Config->EntryAddr);
   } else if (!Config->Shared && !Config->Relocatable &&
              Config->EMachine != EM_AMDGPU) {
     // -e was not specified. Use the default start symbol name
     // if it is resolvable.
     Config->Entry = (Config->EMachine == EM_MIPS) ? "__start" : "_start";
-    if (Symtab.find(Config->Entry))
-      Config->EntrySym = Symtab.addUndefined(Config->Entry);
   }
+  if (Symtab.find(Config->Entry))
+    Config->EntrySym = Symtab.addUndefined(Config->Entry);
 
   if (HasError)
     return; // There were duplicate symbols or incompatible files
index 29e5428..c103739 100644 (file)
 # RUN: ld.lld -o %t2 %t.script %t
 # RUN: llvm-readobj %t2 > /dev/null
 
+# The entry symbol should not cause an undefined error.
 # RUN: echo "ENTRY(_wrong_label)" > %t.script
-# RUN: not ld.lld -o %t2 %t.script %t > %t.log 2>&1
-# RUN: FileCheck -check-prefix=ERR-ENTRY %s < %t.log
-
-# ERR-ENTRY: undefined symbol: _wrong_label
+# RUN: ld.lld -o %t2 %t.script %t
+# RUN: ld.lld --entry=abc -o %t2 %t
 
 # -e has precedence over linker script's ENTRY.
 # RUN: echo "ENTRY(_label)" > %t.script