[PATCH] D26865: [ELF] - exit on --version call

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 19 10:15:26 PST 2016


grimar updated this revision to Diff 78635.
grimar added a comment.

- Updated.

Behavior of ld.bfd and ld.gold is inconsistent. I checked the next combinations:
ld -v + <normal files>. Result: link OK.
gold -v + <normal files>. Result: link OK.
ld -v <no files>. Result: exit with code 0.
gold -v <no files>. Result: exit with code 0.
ld -version <no files>. Result: exit with code 0.
gold -version <no files>. Result: exit with code 0.

Until here behavior was equal. But the last case has different result:
ld -version <normal files>. Result: no link happens, exit with 0.
gold -version <normal file>. Result: link OK.

That is what Rui mentioned on bug page, I did not realized it at first.

So looks we can live with just a minor change like this patch do to fix
PR31057, thoughts ?


https://reviews.llvm.org/D26865

Files:
  ELF/Driver.cpp
  ELF/Options.td
  test/ELF/driver.test


Index: test/ELF/driver.test
===================================================================
--- test/ELF/driver.test
+++ test/ELF/driver.test
@@ -16,9 +16,11 @@
 # RUN: ld.lld --help 2>&1 | FileCheck -check-prefix=HELP %s
 # HELP: USAGE:
 
-# RUN: not ld.lld --version 2>&1 | FileCheck -check-prefix=VERSION %s
+# RUN: ld.lld --version 2>&1 | FileCheck -check-prefix=VERSION %s
 # VERSION: LLD
 
+# 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: ELF/Options.td
===================================================================
--- ELF/Options.td
+++ ELF/Options.td
@@ -206,9 +206,11 @@
 def rsp_quoting: J<"rsp-quoting=">,
   HelpText<"Quoting style for response files. Values supported: windows|posix">;
 
+def v: Flag<["-"], "v">, HelpText<"Display the version number">;
+
 def verbose: F<"verbose">, HelpText<"Verbose mode">;
 
-def version: F<"version">, HelpText<"Display the version number">;
+def version: F<"version">, HelpText<"Display the version number and exit">;
 
 def version_script: S<"version-script">,
   HelpText<"Read a version script">;
@@ -266,7 +268,6 @@
 def alias_undefined_eq: J<"undefined=">, Alias<undefined>;
 def alias_undefined_u: JoinedOrSeparate<["-"], "u">, Alias<undefined>;
 def alias_version_V: Flag<["-"], "V">, Alias<version>;
-def alias_version_v: Flag<["-"], "v">, Alias<version>;
 def alias_wrap_wrap: J<"wrap=">, Alias<wrap>;
 
 // Our symbol resolution algorithm handles symbols in archive files differently
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -290,8 +290,15 @@
     printHelp(ArgsArr[0]);
     return;
   }
-  if (Args.hasArg(OPT_version))
+
+  // GNU linkers disagree here. Though both -version and -v are mentioned
+  // in help to print the version information, GNU ld just normally exits,
+  // while gold can continue linking. We are compatible with ld.bfd here.
+  if (Args.hasArg(OPT_version) || Args.hasArg(OPT_v))
     outs() << getLLDVersion() << "\n";
+  if (Args.hasArg(OPT_version))
+    return;
+
   Config->ExitEarly = CanExitEarly && !Args.hasArg(OPT_full_shutdown);
 
   if (const char *Path = getReproduceOption(Args)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26865.78635.patch
Type: text/x-patch
Size: 2354 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161119/6175d969/attachment.bin>


More information about the llvm-commits mailing list