ELF: Add --help option.

llvm-svn: 262168
This commit is contained in:
Rui Ueyama 2016-02-28 03:18:09 +00:00
parent 1abcf370fd
commit 1eb9f44118
5 changed files with 18 additions and 2 deletions

View File

@ -41,7 +41,7 @@ bool elf::link(ArrayRef<const char *> Args, raw_ostream &Error) {
Config = &C;
Driver = &D;
Script = &LS;
Driver->main(Args.slice(1));
Driver->main(Args);
return !HasError;
}
@ -163,7 +163,11 @@ static bool hasZOption(opt::InputArgList &Args, StringRef Key) {
void LinkerDriver::main(ArrayRef<const char *> ArgsArr) {
initSymbols();
opt::InputArgList Args = parseArgs(&Alloc, ArgsArr);
opt::InputArgList Args = parseArgs(&Alloc, ArgsArr.slice(1));
if (Args.hasArg(OPT_help)) {
printHelp(ArgsArr[0]);
return;
}
if (Args.hasArg(OPT_version)) {
printVersion();
return;

View File

@ -53,6 +53,7 @@ enum {
#undef OPTION
};
void printHelp(const char *Argv0);
void printVersion();
std::string findFromSearchPaths(StringRef Path);

View File

@ -79,6 +79,11 @@ opt::InputArgList elf::parseArgs(llvm::BumpPtrAllocator *A,
return Args;
}
void elf::printHelp(const char *Argv0) {
ELFOptTable Table;
Table.PrintHelp(outs(), Argv0, "lld", false);
}
void elf::printVersion() {
outs() << "LLD " << getLLDVersion();
std::string S = getLLDRepositoryVersion();

View File

@ -57,6 +57,9 @@ def fini : Separate<["-"], "fini">, MetaVarName<"<symbol>">,
def hash_style : Separate<["--", "-"], "hash-style">,
HelpText<"Specify hash style (sysv, gnu or both)">;
def help : Flag<["--", "-"], "help">,
HelpText<"Print option help">;
def icf : Flag<["--"], "icf=all">,
HelpText<"Enable Identical Code Folding.">;

View File

@ -14,6 +14,9 @@
# RUN: not ld.lld %t -o /no/such/file 2>&1 | FileCheck -check-prefix=MISSING %s
# MISSING: failed to open /no/such/file
# RUN: ld.lld --help 2>&1 | FileCheck -check-prefix=HELP %s
# HELP: USAGE:
# RUN: ld.lld --version 2>&1 | FileCheck -check-prefix=VERSION %s
# VERSION: LLD