Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -421,8 +421,22 @@ } static std::string getRpath(opt::InputArgList &Args) { - std::vector V = getArgs(Args, OPT_rpath); - return llvm::join(V.begin(), V.end(), ":"); + // GNU linkers list -R as alias for -rpath and -R + // as alias for --just-symbols. For backward compatibility we support + // first case, but we do not want to share the same flag with other + // options, hence trigger an error for the second case. + std::vector V; + for (auto *Arg : Args.filtered(OPT_rpath, OPT_R)) { + V.push_back(Arg->getValue()); + if (Arg->getOption().getID() == OPT_rpath) + continue; + + sys::fs::file_type Type = sys::fs::get_file_type(V.back()); + if (Type != sys::fs::file_type::status_error && + Type != sys::fs::file_type::directory_file) + error("-R (-rpath): " + V.back() + " is not a directory."); + } + return llvm::join(V, ":"); } // Determines what we should do if there are remaining unresolved Index: ELF/Options.td =================================================================== --- ELF/Options.td +++ ELF/Options.td @@ -242,6 +242,9 @@ defm reproduce: Eq<"reproduce">, HelpText<"Dump linker invocation and input files for debugging">; +def R: JoinedOrSeparate<["-"], "R">, MetaVarName<"">, + HelpText<"Add a DT_RUNPATH to the output">; + defm rpath: Eq<"rpath">, HelpText<"Add a DT_RUNPATH to the output">; def relocatable: F<"relocatable">, HelpText<"Create relocatable object file">; @@ -345,7 +348,6 @@ def alias_pie_pic_executable: F<"pic-executable">, Alias; def alias_print_map_M: Flag<["-"], "M">, Alias; def alias_relocatable_r: Flag<["-"], "r">, Alias; -def alias_rpath_R: JoinedOrSeparate<["-"], "R">, Alias; def alias_script_T: JoinedOrSeparate<["-"], "T">, Alias