[lld] r281989 - Don't produce an error for undefined entry symbol.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 20 10:26:40 PDT 2016


On Tue, Sep 20, 2016 at 10:14 AM, Rafael Espindola via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: rafael
> Date: Tue Sep 20 12:14:16 2016
> New Revision: 281989
>
> URL: http://llvm.org/viewvc/llvm-project?rev=281989&view=rev
> Log:
> 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.
>

I'm OK with this not being an error, presumably because we have no
other choices and this mimic what ld.bfd or gold do.
But, can you please add a warning diagnostic? I find rtld/ld.so a
little bit cryptic at times, and it's not even guaranteed they will
emit an error but they might just crash the executable (this was true
under certain circumstances, at least on FreeBSD).

> Modified:
>     lld/trunk/ELF/Driver.cpp
>     lld/trunk/test/ELF/linkerscript/linkerscript.s
>
> Modified: lld/trunk/ELF/Driver.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=281989&r1=281988&r2=281989&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Driver.cpp (original)
> +++ lld/trunk/ELF/Driver.cpp Tue Sep 20 12:14:16 2016
> @@ -667,16 +667,15 @@ template <class ELFT> void LinkerDriver:
>    // 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
>
> Modified: lld/trunk/test/ELF/linkerscript/linkerscript.s
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/linkerscript.s?rev=281989&r1=281988&r2=281989&view=diff
> ==============================================================================
> --- lld/trunk/test/ELF/linkerscript/linkerscript.s (original)
> +++ lld/trunk/test/ELF/linkerscript/linkerscript.s Tue Sep 20 12:14:16 2016
> @@ -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
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits

-- 
Davide

"There are no solved problems; there are only problems that are more
or less solved" -- Henri Poincare


More information about the llvm-commits mailing list