From 251e240adcc8fd81a17d7ce0ef12f0b4308f2aa9 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 23 Sep 2016 21:04:56 +0000 Subject: [PATCH] Warn if we can't find the entry symbol. Fixes pr30465. llvm-svn: 282295 --- lld/ELF/Driver.cpp | 11 ++++++++--- lld/test/ELF/entry.s | 4 +++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 9f13ca6..b27b33e 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -665,17 +665,22 @@ template void LinkerDriver::link(opt::InputArgList &Args) { // Add the start symbol. // It initializes either Config->Entry or Config->EntryAddr. // Note that AMDGPU binaries have no entries. + bool HasEntryAddr = false; if (!Config->Entry.empty()) { // It is either "-e " or "-e ". - Config->Entry.getAsInteger(0, Config->EntryAddr); + HasEntryAddr = !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 (!HasEntryAddr) { + if (Symtab.find(Config->Entry)) + Config->EntrySym = Symtab.addUndefined(Config->Entry); + else + warning("entry symbol " + Config->Entry + " not found, assuming 0"); + } if (HasError) return; // There were duplicate symbols or incompatible files diff --git a/lld/test/ELF/entry.s b/lld/test/ELF/entry.s index 9dc3552..aef71c6 100644 --- a/lld/test/ELF/entry.s +++ b/lld/test/ELF/entry.s @@ -1,5 +1,5 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1 -# RUN: ld.lld %t1 -o %t2 +# RUN: ld.lld -e foobar %t1 -o %t2 2>&1 | FileCheck -check-prefix=WARN %s # RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=NOENTRY %s # RUN: ld.lld %t1 -o %t2 -e entry # RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=SYM %s @@ -12,6 +12,8 @@ # RUN: ld.lld %t1 -o %t2 -e 0777 # RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=OCT %s +# WARN: entry symbol foobar not found, assuming 0 + # NOENTRY: Entry: 0x0 # SYM: Entry: 0x11000 # DSO: Entry: 0x1000 -- 2.7.4