llvm-ar accidentally provides the wrong exit code when given an invalid command
| Bugzilla Link | 34396 |
| Resolution | FIXED |
| Resolved on | Sep 08, 2017 14:27 |
| Version | 5.0 |
| OS | Linux |
Extended Description
llvm-ar parses its arguments, and if it can't make sense of them it shows it's help message and exits. In particular llvm-ar calls show_help ( see it at https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-ar/llvm-ar.cpp#L169 )
'''
show_help(const std::string &msg) {
errs() << ToolName << ": " << msg << "\n\n";
cl::PrintHelpMessage();
exit(1);
}
'''
llvm-ar dutifully tries to show some help and exit with a code indicating error. Unfortunately, if one follows the cl::PrintHelpMessage function (found at http://llvm.org/doxygen/CommandLine_8cpp_source.html#l02100) they'll find that it ends up calling exit(0). The exit(1) never gets reached.
This became a problem for us because GHC takes the AR implementation its given and runs it with a variety of arguments to see what it supports. It relies on the exit code to determine success or failure.
I'm not sure what would be technically the most appropriate fix would be in the context of the LLVM project. Would simply changing show_help to print out something like "unknown command line argument: run llvm-ar with -help for usage information" and then call exit(0) be fine?
Thanks so much for the fix! Glad to see a few more trouble spots got picked up in the commit as well.
leaving the full phab link for any future visitors to this ticket.
https://reviews.llvm.org/rL312752
r312752.