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

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 20 10:34:56 PDT 2016


This is interesting. I was thinking that in that case linkers should report
an error, but GNU linkers actually report just a warning. Maybe we should
report a warning, too.

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.
>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160920/a03e5df0/attachment.html>


More information about the llvm-commits mailing list