Index: UniversalDriver.cpp =================================================================== --- UniversalDriver.cpp +++ UniversalDriver.cpp @@ -123,8 +123,35 @@ return ret; } +static void removeArgumentFromCommandLine( + llvm::opt::Arg *argument, + int &argc, + const char **&argv) { + // remove the argument along with all its values + unsigned int numberOfItemsToRemove = argument->getNumValues() + 1; + + // arg indexes are relative to argv[1]. Get absolute index of the arg + // in the command line + unsigned int argIndex = argument->getIndex() + 1; + + std::rotate( + &argv[argIndex], + &argv[argIndex + numberOfItemsToRemove], + argv + argc); + + argc -= numberOfItemsToRemove; +} + static Flavor getFlavor(int &argc, const char **&argv, std::unique_ptr &parsedArgs) { + if (llvm::opt::Arg *argCore = parsedArgs->getLastArg(OPT_core)) { + removeArgumentFromCommandLine(argCore, argc, argv); + return Flavor::core; + } + if (llvm::opt::Arg *argFlavor = parsedArgs->getLastArg(OPT_flavor)) { + removeArgumentFromCommandLine(argFlavor, argc, argv); + return strToFlavor(argFlavor->getValue()); + } #if LLVM_ON_UNIX if (llvm::sys::path::filename(argv[0]).equals("ld")) { #if __APPLE__ @@ -135,16 +162,6 @@ return Flavor::gnu_ld; } #endif - if (parsedArgs->getLastArg(OPT_core)) { - argc--; - argv++; - return Flavor::core; - } - if (llvm::opt::Arg *argFlavor = parsedArgs->getLastArg(OPT_flavor)) { - argc -= 2; - argv += 2; - return strToFlavor(argFlavor->getValue()); - } StringRef name = llvm::sys::path::stem(argv[0]); return strToFlavor(parseProgramName(name)._flavor); } @@ -174,7 +191,7 @@ // Handle --help if (parsedArgs->getLastArg(OPT_help)) { - table.PrintHelp(llvm::outs(), argv[0], "LLVM Linker", false); + table.PrintHelp(llvm::outs(), programName.data(), "LLVM Linker", false); return true; }