[PATCH] D40810: Make the behavior of the -v option more closer to GNU linkers.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 4 15:41:30 PST 2017
LGTM
Rui Ueyama via Phabricator <reviews at reviews.llvm.org> writes:
> ruiu created this revision.
> Herald added a subscriber: emaste.
>
> Previously, lld exited with an error status if the only option given to
> the command is -v. GNU linkers gracefully exit in that case. This patch
> makes lld behave like GNU.
>
> Note that even with this patch, lld's -v and --version options behave
> slightly differently than GNU linkers' counterparts. For example,
> if you run `ld.bfd -v -v`, the version string is printed out twice.
> But that is an edge case that I don't think we need to take care of.
>
> Fixes https://bugs.llvm.org/show_bug.cgi?id=31582
>
>
> https://reviews.llvm.org/D40810
>
> Files:
> lld/ELF/Driver.cpp
> lld/test/ELF/driver.test
>
>
> Index: lld/test/ELF/driver.test
> ===================================================================
> --- lld/test/ELF/driver.test
> +++ lld/test/ELF/driver.test
> @@ -18,10 +18,10 @@
> # HELP: : supported targets:{{.*}} elf
>
> # RUN: ld.lld --version 2>&1 | FileCheck -check-prefix=VERSION %s
> +# RUN: ld.lld -v 2>&1 | FileCheck -check-prefix=VERSION %s
> +# RUN: not ld.lld -v xyz 2>&1 | FileCheck -check-prefix=VERSION %s
> # VERSION: LLD {{.*}} (compatible with GNU linkers)
>
> -# RUN: not ld.lld -v 2>&1 | FileCheck -check-prefix=VERSION %s
> -
> ## Attempt to link DSO with -r
> # RUN: ld.lld -shared %t -o %t.so
> # RUN: not ld.lld -r %t.so %t -o %tfail 2>&1 | FileCheck -check-prefix=ERR %s
> Index: lld/ELF/Driver.cpp
> ===================================================================
> --- lld/ELF/Driver.cpp
> +++ lld/ELF/Driver.cpp
> @@ -337,9 +337,10 @@
> if (Args.hasArg(OPT_v) || Args.hasArg(OPT_version))
> message(getLLDVersion() + " (compatible with GNU linkers)");
>
> - // ld.bfd always exits after printing out the version string.
> - // ld.gold proceeds if a given option is -v. Because gold's behavior
> - // is more permissive than ld.bfd, we chose what gold does here.
> + // The behavior of -v or --version is a bit strange, but this is
> + // needed for compatibility with GNU linkers.
> + if (Args.hasArg(OPT_v) && !Args.hasArg(OPT_INPUT))
> + return;
> if (Args.hasArg(OPT_version))
> return;
>
>
>
> Index: lld/test/ELF/driver.test
> ===================================================================
> --- lld/test/ELF/driver.test
> +++ lld/test/ELF/driver.test
> @@ -18,10 +18,10 @@
> # HELP: : supported targets:{{.*}} elf
>
> # RUN: ld.lld --version 2>&1 | FileCheck -check-prefix=VERSION %s
> +# RUN: ld.lld -v 2>&1 | FileCheck -check-prefix=VERSION %s
> +# RUN: not ld.lld -v xyz 2>&1 | FileCheck -check-prefix=VERSION %s
> # VERSION: LLD {{.*}} (compatible with GNU linkers)
>
> -# RUN: not ld.lld -v 2>&1 | FileCheck -check-prefix=VERSION %s
> -
> ## Attempt to link DSO with -r
> # RUN: ld.lld -shared %t -o %t.so
> # RUN: not ld.lld -r %t.so %t -o %tfail 2>&1 | FileCheck -check-prefix=ERR %s
> Index: lld/ELF/Driver.cpp
> ===================================================================
> --- lld/ELF/Driver.cpp
> +++ lld/ELF/Driver.cpp
> @@ -337,9 +337,10 @@
> if (Args.hasArg(OPT_v) || Args.hasArg(OPT_version))
> message(getLLDVersion() + " (compatible with GNU linkers)");
>
> - // ld.bfd always exits after printing out the version string.
> - // ld.gold proceeds if a given option is -v. Because gold's behavior
> - // is more permissive than ld.bfd, we chose what gold does here.
> + // The behavior of -v or --version is a bit strange, but this is
> + // needed for compatibility with GNU linkers.
> + if (Args.hasArg(OPT_v) && !Args.hasArg(OPT_INPUT))
> + return;
> if (Args.hasArg(OPT_version))
> return;
>
More information about the llvm-commits
mailing list