diff options
author | Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> | 2020-01-02 13:44:02 +0100 |
---|---|---|
committer | Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> | 2020-01-02 13:44:05 +0100 |
commit | 535b3c6b2f1c81ed91942ebd9ea06a1022dc59a1 (patch) | |
tree | 2e02d6fc90e91e35ce8ee211988a993405b1cda0 /llvm/tools | |
parent | 8188c998ffa4d20253444b257402907d2aa74dc2 (diff) | |
download | bcm5719-llvm-535b3c6b2f1c81ed91942ebd9ea06a1022dc59a1.tar.gz bcm5719-llvm-535b3c6b2f1c81ed91942ebd9ea06a1022dc59a1.zip |
[llvm-ranlib] Handle -D and -U command line flag
I have been trying to build CheriBSD (a fork for FreeBSD for the CHERI
CPU) with LLVM binutils instead of the default elftoolchain utilities.
I noticed that building static archives was failing because ranlib is
invoked with the -D flag. This failed with llvm-ranlib since it parses
the -D flag as the archive path and reports an error that more than one
archive has been passed.
This fixes https://llvm.org/PR41707
Reviewed By: rupprecht
Differential Revision: https://reviews.llvm.org/D71554
Diffstat (limited to 'llvm/tools')
-rw-r--r-- | llvm/tools/llvm-ar/llvm-ar.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp index d1830c0762c..c339dfe1f33 100644 --- a/llvm/tools/llvm-ar/llvm-ar.cpp +++ b/llvm/tools/llvm-ar/llvm-ar.cpp @@ -64,8 +64,10 @@ const char RanlibHelp[] = R"(OVERVIEW: LLVM Ranlib (llvm-ranlib) USAGE: llvm-ranlib <archive-file> OPTIONS: - -h --help - Display available options - --version - Display the version of this program + -h --help - Display available options + -v --version - Display the version of this program + -D - Use zero for timestamps and uids/gids (default) + -U - Use actual timestamps and uids/gids )"; const char ArHelp[] = R"(OVERVIEW: LLVM Archiver @@ -1156,13 +1158,33 @@ static int ar_main(int argc, char **argv) { static int ranlib_main(int argc, char **argv) { bool ArchiveSpecified = false; for (int i = 1; i < argc; ++i) { - if (handleGenericOption(argv[i])) { + StringRef arg(argv[i]); + if (handleGenericOption(arg)) { return 0; + } else if (arg.consume_front("-")) { + // Handle the -D/-U flag + while (!arg.empty()) { + if (arg.front() == 'D') { + Deterministic = true; + } else if (arg.front() == 'U') { + Deterministic = false; + } else if (arg.front() == 'h') { + printHelpMessage(); + return 0; + } else if (arg.front() == 'v') { + cl::PrintVersionMessage(); + return 0; + } else { + // TODO: GNU ranlib also supports a -t flag + fail("Invalid option: '-" + arg + "'"); + } + arg = arg.drop_front(1); + } } else { if (ArchiveSpecified) fail("exactly one archive should be specified"); ArchiveSpecified = true; - ArchiveName = argv[i]; + ArchiveName = arg.str(); } } if (!ArchiveSpecified) { |