[ELF] - Fix for: Bug 30521 - lld exits non-zero return value linking a library with no entry symbol

PR30521 was about linking shared library. After r282295 code when linking -shared produced
"entry symbol not found" warning, what in combination with --fatal-errors failed linkage.

Patch fixes logic (and adds testcases) to follow next rules:

1) If entry was specified and not found report warning.
2) If entry was not specified then:
 a) Emit warning if not -shared.
 b) Do not emit warning if -shared.

Differential revision: https://reviews.llvm.org/D24913

llvm-svn: 282427
This commit is contained in:
George Rimar 2016-09-26 19:04:42 +00:00
parent abb6eea19c
commit a213e6b6f5
2 changed files with 10 additions and 2 deletions

View File

@ -675,7 +675,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
// if it is resolvable.
Config->Entry = (Config->EMachine == EM_MIPS) ? "__start" : "_start";
}
if (!HasEntryAddr) {
if (!HasEntryAddr && !Config->Entry.empty()) {
if (Symtab.find(Config->Entry))
Config->EntrySym = Symtab.addUndefined(Config->Entry);
else

View File

@ -1,9 +1,16 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
# 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 2>&1 | FileCheck -check-prefix=WARN2 %s
# RUN: ld.lld -shared -e foobar %t1 -o %t2 2>&1 | FileCheck -check-prefix=WARN %s
# RUN: ld.lld -shared --fatal-warnings -e entry %t1 -o %t2
# RUN: ld.lld -shared --fatal-warnings %t1 -o %t2
# RUN: ld.lld %t1 -o %t2 -e entry
# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=SYM %s
# RUN: ld.lld %t1 -shared -o %t2 -e entry
# RUN: ld.lld %t1 --fatal-warnings -shared -o %t2 -e entry
# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=DSO %s
# RUN: ld.lld %t1 -o %t2 --entry=4096
# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=DEC %s
@ -13,6 +20,7 @@
# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=OCT %s
# WARN: entry symbol foobar not found, assuming 0
# WARN2: entry symbol _start not found, assuming 0
# NOENTRY: Entry: 0x0
# SYM: Entry: 0x11000