From db62cbb97f144a1f884621bf5cd6e361f17ff8f2 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 20 Sep 2016 17:14:16 +0000 Subject: [PATCH] Don't produce an error for undefined entry symbol. 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 | 7 +++---- lld/test/ELF/linkerscript/linkerscript.s | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 3e1f723..9f13ca6 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -667,16 +667,15 @@ template void LinkerDriver::link(opt::InputArgList &Args) { // Note that AMDGPU binaries have no entries. if (!Config->Entry.empty()) { // It is either "-e " or "-e ". - 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 diff --git a/lld/test/ELF/linkerscript/linkerscript.s b/lld/test/ELF/linkerscript/linkerscript.s index 29e5428..c103739 100644 --- a/lld/test/ELF/linkerscript/linkerscript.s +++ b/lld/test/ELF/linkerscript/linkerscript.s @@ -60,11 +60,10 @@ # 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 -- 2.7.4