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
This commit is contained in:
Rafael Espindola 2016-09-20 17:14:16 +00:00
parent 6fe6eae7f7
commit db62cbb97f
2 changed files with 6 additions and 8 deletions

View 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

View File

@ -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